News for hackers. Stuff that matters.
Re:Making a Go program 70% faster with a one character change by cbsmith on Monday November 14, 2022 @12:23PM (#33597493)
> I've only ever found myself missing value semantics when I use languages with implicit reference semantics.

Oh, I miss it every time. ;-)

I will say though that some newer languages seem to have a confused idea about how to offer mixed semantics. A bunch of them tie semantics to types. The ideal interface can vary by usage context. It's hard enough getting the semantics right as the callee (as opposed to caller), let alone when you're defining a type that will be used by who knows how many interfaces.

> I guess I always figured the solution was "value semantics with better education / tooling".

I've always thought much the same, but I have slowly come to appreciate that it's more than just education & tooling. Even with good education & tooling, there's a cognitive load that comes with getting interfaces right that for the general case is just not worth it.

Re:Making a Go program 70% faster with a one character change by adgjlsfhk1 on Monday November 14, 2022 @01:46PM (#33598872)
I think this is half right. For anything 64 bits or smaller, value semantics are pretty much always going to be better. That said, being able to choose between value and reference semantics for larger objects per object is a pretty useful feature.
Re:Making a Go program 70% faster with a one character change by cbsmith on Monday November 14, 2022 @05:31PM (#33602265)
> For anything 64 bits or smaller, value semantics are pretty much always going to be better.

That's assuming a 64-bit CPU (which admittedly seems like a reasonable assumption. The nice thing about the abstraction though is that there's nothing preventing the runtime from applying value semantics for those trivial small-object cases where they're obviously more efficient.

Re:Making a Go program 70% faster with a one character change by account42 on Tuesday November 15, 2022 @04:31AM (#33607099)
Even for a 32-bit CPU a 64-bit type is only two words to copy - and in many cases those "copies" are just register loads. In contrast, reference types means to even access it you have to read the reference and then indirectly load the memory it points to. You have to really make something contrived where a two-word type ends up being more efficient as a reference than as a value.
Re:Making a Go program 70% faster with a one character change by throwaway894345 on Monday November 14, 2022 @03:11PM (#33600241)
> I will say though that some newer languages seem to have a confused idea about how to offer mixed semantics. A bunch of them tie semantics to types.

Curious about what you mean here. This sounds like C#'s class/struct distinction to me.

Re:Making a Go program 70% faster with a one character change by cbsmith on Monday November 14, 2022 @05:18PM (#33602083)
That's exactly the example I was thinking of.
Re:Making a Go program 70% faster with a one character change by throwaway894345 on Monday November 14, 2022 @06:16PM (#33602784)
Yeah, I never cared for that. Specifically, I'd prefer that everything was just "struct", but structs could implement interfaces, which is essentially the Go/Rust model.