I'm not sure what the title has to do with the article at all. It's just pointing out a language gotcha/subtlety. The title might as well have been "Go is Not Javascript", "Go is not QBasic", etc.
Here's a more idiomatic translation of the Python code to Go, and there's no surprise to how the code behaves:<p><a href="https://play.golang.org/p/rpqvVDR9v8" rel="nofollow">https://play.golang.org/p/rpqvVDR9v8</a>
<p><pre><code> fredPtr = nil // This line is superfluous.
</code></pre>
In Go, declarations always initialise variables to their zero value, which for all pointers is nil.<p>(Perhaps worthy of a follow up article: "Go is Not C/C++"? ;)
Alternative options of solving this issue include `break`ing when the right option is found (so the loop variable doesn't get overwritten again) or moving everything into a function:<p><pre><code> func findByName(students []*Student, name string) *Student {
for _, s := range students {
if s.name == name {
return s
}
}
return nil
}
</code></pre>
Both options have the added advantage of stopping iteration as soon as the result is found.
I think you can put this more generally as "syntax is not semantics." Go takes some syntactic cues from python (but who doesn't these days?) but its semantics can be pretty different. I think it's pretty common for new programmers especially to get caught up in the syntax of languages without giving enough attention to their semantics, which causes the sort of problems the author highlights here.
I love Python. But honestly speaking, the point raised in this article is fairly trivial. I would not, not learn Go just because there are small differences in the way reference / pointers work. I do not see this as an inherent shortcoming of Go.<p>Both languages have their strengths. When you pick a language for an application, it is your responsibility to use it properly. Otherwise you will make mistakes and it won't be the fault of the language.
I don't know Python or Go, but both examples seem _wrong_.<p>Python: How is `Fred` available to be printed in the Python example, is not it out of scope?<p>Go: Why use `var fredPtr *Student`? What's the point? Can not use `var fredPtr Student` and the set `fredPtr = student` in the loop?
for a no-goer: will this copy by value?
```
var fred Student
for _, student := range students {
if student.name == "fred" {
fred = student
}
}
```