3 ms·
It's not just "too late to change now", it's also proper behavior. Go code is meant to be concise: - once a Go developer learned that the above is a copy (whi
by dualogy 13y ago
It's not just "too late to change now", it's also proper behavior.
Go code is meant to be concise:
- once a Go developer learned that the above is a copy (which she will learn very early on), she won't ever forget, it's just too fundamental
- to modify the slice, just modify the slice and skip the copy with underscore:
for i, _ := range mySlice { mySlice[i] = "foo" }
There we go. Syntax simplicity (without exotic compiler flags or prep directives) and conciseness fully preserved.
- neeee 13y agoBy the way, you don't need a _ assignment there. You can just do i := range mySlice.
- pkulak 13y agoWhich I still do constantly, then get a compile error when what I thought was something else is actually an int.
- dualogy 13y agoThat's a good reason to always include both parts of the LHR: because if that "something else" actually is an int -- then you'll have a nasty bug at your hands (and not a compiler-catchable one at that).