Not understanding structs vs pointers is a pretty basic misconception in go. Does this trip anyone else up? I found it unenlightening / unsurprising, and the linked "100 mistakes" piece also very basic and in some cases just plain wrong.
As she points out though, a lot of dynamic languages don’t behave this way. A string after all points to a heap allocation; so it’s not unreasonable to think of a string as a pointer.
Go structs are copied on assignment (and other things about Go I'd missed)
21–30 of 176 posts
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#22One of the many things I find inspiring about Julia is how quick she is to admit to mistakes she has made or things that she hasn't understood. If she didn't understand it, I can 100% guarantee that there are large numbers of people out there who also didn't understand it - many of whom were probably too embarrassed to ever admit it. I think this is a useful trait for senior software engineers generally. If you're a…
Programming is about finding the answer. If you already knew everything, you could just sit down and type any program from your knowledge.
We all know that you can't know everything otherwise, why even write documentation or use git?
Unfortunately, it's difficult to move past this idea, and it's so pervasive that stating "I don't know" can negatively affect your standing for some.
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#23Re: Go structs are copied on assignment (and other things about Go I'd missed)
#24One of the many things I find inspiring about Julia is how quick she is to admit to mistakes she has made or things that she hasn't understood. If she didn't understand it, I can 100% guarantee that there are large numbers of people out there who also didn't understand it - many of whom were probably too embarrassed to ever admit it. I think this is a useful trait for senior software engineers generally. If you're a…
Personally, I think that the idea that programmers should know everything is kinda bizarre. Programming is about finding the answer. If you already knew everything, you could just sit down and type any program from your knowledge. We all know that you can't know everything otherwise, why even write documentation or use git? Unfortunately, it's difficult to move past this idea, and it's so pervasive that stating "I do…
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#25To generalize the title into a rule is good to remember that in Go everything is passed by value(copy).
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#26To generalize the title into a rule is good to remember that in Go everything is passed by value(copy).
The important lesson is that assignments are by value(copy).
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#27Not understanding structs vs pointers is a pretty basic misconception in go. Does this trip anyone else up? I found it unenlightening / unsurprising, and the linked "100 mistakes" piece also very basic and in some cases just plain wrong.
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#28(Fiddle demonstration for non-.Net peeps: https://dotnetfiddle.net/apDZP5 ).
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#29Re: Go structs are copied on assignment (and other things about Go I'd missed)
#30To generalize the title into a rule is good to remember that in Go everything is passed by value(copy).
That is the case for almost every modern language. C++ is one of the few languages that has "references" and at least last I looked that's a language accommodation over what are pointers being passed by value in the assembly, at least until compiler optimizations take over (and that's not limited to references either). If you're in 2024 and you're in some programming class making a big deal about pass-by-value versus…