Live data from Hacker News

Go Enums Suck

zarl.dev

241–244 of 244 posts

Re: Go Enums Suck

#241
post #169
post #130

Earlier quoted context omitted.

This is in line with 'guard clauses' and this is why it is accepted as idiomatic code. For this example we only have a single condition but as soon as you add more conditions it start to get out of hand. I prefer the original code because it makes the codebase as a whole easier to read. But I don't think there are any 'hard facts' to support using either of these styles over the other in these simple cases.

There is one simple hard fact: shorter code is faster to read and understand, period. If someone doesn't understand what the result of `o != Unknown` is then they should probably go back and read more about programming. Sorry to sound a bit condescending.

That's clearly not true, and one of the primary design choices Go makes. It trades concise code for more readable code.

Re: Go Enums Suck

#242
post #226

Earlier quoted context omitted.

> Why do you unwind the stack? Something terrible happened? Definitely not, Definitely do. In Go we just have to emulate it, badly, by manually writing code to forward the error up the stack so you can finally top-level print “error bad thing happen” or maybe some unholy stringification of wrapped errors possibly collected along the way.

Please explain how errors are fundamentally different so they require drastically different way of returning.

[deleted]

Re: Go Enums Suck

#243

Earlier quoted context omitted.

Rust I think covers most if not all of Ada features you mentioned

Rust's "enum" mechanism is really an algebraic data type, and corresponds to Ada's enumeration types when applied as discriminants in variant record types . But Ada's enumeration types have a wider context of use, separate and independent from variant record types, including compile- and run-time features related directly to a) symbolic order and symbol names, b) binary representation mapped to these symbols, and c)…

Rust enum model is a hybrid.

It allows to set discriminants explicitly and it allows unit-only enums (enums with only discriminants and no structures associated with them). You can control the underlying type of the discriminant too.

With a little bit of derive macro sugar you can even iterate through all the values of enum.

Re: Go Enums Suck

#244
post #240
post #183

Earlier quoted context omitted.

Java 21, and I assume like every scripting language (Ruby, Python, etc). Though I guess with scripting you can't use more than one OS thread (not totally sure). Rust started off with it, and C# tried it too, but there are huge downsides to the model, so it's not like it's perfection incarnate and every other language just can't pull it off.

Does 21 actually automatically schedule fibers? to open cores?

Yup. It's all 100% automatic. Just use a different name for the thread pool and you're done, I believe.
Post reply on HN