News for hackers. Stuff that matters.
Re:Go Enums Suck by nzach on Friday March 01, 2024 @03:00PM (#39566123)
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.

Re:Go Enums Suck by mojuba on Friday March 01, 2024 @04:57PM (#39567267)
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.
Re:Go Enums Suck by coffeebeqn on Friday March 01, 2024 @09:25PM (#39569235)
I would’ve written a shorter letter if I had more time. I’ve also noticed people don’t want to think through Boolean logic enough to write things legibly. Or the other extreme is way too many Boolean operators on a line where it gets very hard to parse. Even worse when there are multiple cases like that in one function
Re:Go Enums Suck by derekperkins on Saturday March 02, 2024 @11:40PM (#39578461)
That's clearly not true, and one of the primary design choices Go makes. It trades concise code for more readable code.