News for hackers. Stuff that matters.
Re:IBM to buy HashiCorp in $6.4B deal by janosdebugs on Wednesday April 24, 2024 @06:17PM (#40150513)
After having written probably over 100k lines of Go code, my impression is that Go is simple, but not easy. The language has very few features to learn, but that results in a lot of boilerplate code and there are more than a few footguns burried in the language itself. (My favorite [1])

I find it very hard to write expressive, easy to read code and more often than not I see people using massive switch-case statements and other, hard to maintain patterns instead of abstracting away things because it's so painful to create abstractions. (The Terraform/OpenTofu codebase is absolutely guilty of this btw, there is a reason why it's over 300k lines of code. There is a lot of procedural code in there with plenty of hidden global scope, so getting anything implemented that touches multiple parts typically requires a lot of contortions.)

It's not a bad language by any stretch, but there are things it is good at and things it is not really suited for.

[1]: https://gist.github.com/janosdebugs/f0a3b91a0a070ffb067de4dc...

Re:IBM to buy HashiCorp in $6.4B deal by epgui on Wednesday April 24, 2024 @07:17PM (#40151106)
I’ve always found that the Go language is simple in all the ways that don’t matter.

(In contrast to languages like Haskell and Clojure, which are simple in most of the ways that matter.)

Re:IBM to buy HashiCorp in $6.4B deal by nine_k on Wednesday April 24, 2024 @10:16PM (#40152575)
Compilation speed matters, among other things, and monomorphization is often costly.
Re:IBM to buy HashiCorp in $6.4B deal by djbusby on Wednesday April 24, 2024 @06:44PM (#40150776)
Is it because secondSlice is a reference (pointer?) to firstSlice?
Re:IBM to buy HashiCorp in $6.4B deal by MoOmer on Wednesday April 24, 2024 @07:59PM (#40151476)
Slices are structures that hold a pointer to the array, a length, and a capacity!

So, when you slice a slice, if you perform an array operation like “append” while there is existing capacity, it will use that array space for the new value.

When the sliced value is assigned to another variable, it’s not a pointer that’s copied, it’s a new slice value (with the old length). So, this new value thinks it has capacity to overwrite that last array value - and it does.

So, that also overwrites the other slice’s last value.

If you append again, though, you get a (new) expanded array. It’s easier to see with more variables as demonstrated here: https://go.dev/play/p/AZR5E5ALnLR

(Sorry for formatting issues in that link, on phone)

Check out this post for more details: https://go.dev/blog/slices-intro

Re:IBM to buy HashiCorp in $6.4B deal by geoka9 on Wednesday April 24, 2024 @07:48PM (#40151400)
It's because slices have underlying arrays which define their capacity (cap(s)).

Both slices start out having the same underlying (bigger) array -so appending to one slice can affect the other one.

In the "bonus" part, though, the appends outgrew the original array, so new underlying arrays were allocated (i.e. the slices stopped sharing the same backing array).

Thanks for the heads-up, janosdebugs :)

Re:IBM to buy HashiCorp in $6.4B deal by janosdebugs on Wednesday April 24, 2024 @06:50PM (#40150834)
Yes-ish? Slices are this weird construct where they sometimes behave like references and sometimes not. When I read the explanation, it always makes sense, but when using them it doesn't. For me the rule is: don't reuse slices and don't modify them unless you are the "owner" of the slice. Appending to a slice that was returned to you from a function is usually a pretty good way to have a fun afternoon debugging.