go - Why do we need the := symbol in golang? -


i understand difference between = , := in golang, question why need :=? couldn't compiler figure out on own variable not yet defined? readability?

because can shadow outer-scope variables in inner scope, such closure or loop; compiler cannot infer purely based on whether variable existed before or not. having explicitly define variables helps reduce defects commonplace in languages php , javascript allow foo = bar without consideration of whether foo has been defined. kind of loose compilation paves on common mistakes like typos such they're no longer caught @ compile time, show "weird behavior" @ runtime, much, harder track down , fix.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -