Earlier quoted context omitted.
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…
Right! The best thing about our chosen career is that it's completely impossible to know everything - there's always a new corner of software engineering to dig into, be it how the Linux kernel works, or programming with Haskell, understanding Transformer LLM architectures, or how the Svelte compiler works or whatever.
Go structs are copied on assignment (and other things about Go I'd missed)
81–90 of 176 posts
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#82Earlier quoted context omitted.
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…
Is copying huge blocks of data free in 2024? My benchmarks suggest otherwise, and the world still needs assembly programmers.
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#83One 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…
most of the time when people don't ask questions in industry, it isn't because they already know the answers, it's because they don't care what the answers are blogging is culturally different because there's way more exhibitionism involved
We've probably all been in one of those meetings where something is being proposed, and everyone is nodding vaguely along but you're not sure the proposal is correct. Do you ask a clarifying question (and risk seeming foolish for not knowing something obvious) or just let it pass because everyone else seems happy with it?
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#84Re: Go structs are copied on assignment (and other things about Go I'd missed)
#85 thing := Thing{...}
other_thing := thing
pinter_to_same_thing := &thing
ALL types in go are being copied by value. There is no such thing as a "reference" in this language. Even a slice or map is just a small struct with some syntactic sugar provided by the language, and when you assign a slice to another variable, you are, in fact, creating a copy of that struct.Re: Go structs are copied on assignment (and other things about Go I'd missed)
#86The list feels like it's meant to blame the programmer, but that ain't right.
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#87The semantics of when stuff is copied, moved, or passed by reference are all over the place in language design. C started with the idea that functions returned one int-sized value in a register. This led to classic bugs where the function returns a pointer to a local value. Compilers now usually catch this. C eventually got structure return by copy. Then C++ added return value by move, and automatic optimization for…
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#88Earlier quoted context omitted.
Non-C# developer question: what use-case/situation would a `struct` make sense to use instead of a `class`? Just out of curiosity. [Edit] Well, there's a nice, special article for this very question: https://learn.microsoft.com/en-us/dotnet/standard/design-gui...
If they are small, then there can be a significant performance advantage to using a struct. Imagine you have a Dictionary . (That is, a dictionary (hash lookup) from type TKey to type TValue ). Imagine your choice of key is a composite of 4 bytes, and you want to preserve the meaning of each, so let's say you define a class (shorthand to avoid all the get/set cruft): class MyKey { byte A; byte B; byte C; byte D; } Wh…
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#89To 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…
Re: Go structs are copied on assignment (and other things about Go I'd missed)
#90Earlier quoted context omitted.
If they are small, then there can be a significant performance advantage to using a struct. Imagine you have a Dictionary . (That is, a dictionary (hash lookup) from type TKey to type TValue ). Imagine your choice of key is a composite of 4 bytes, and you want to preserve the meaning of each, so let's say you define a class (shorthand to avoid all the get/set cruft): class MyKey { byte A; byte B; byte C; byte D; } Wh…
It should be a record struct , as record defaults to class.