News for hackers. Stuff that matters.
Re:Go Is a Well-Designed Language by kerkeslager on Saturday February 01, 2025 @12:38AM (#42895980)
Within the 90 seconds of thought while writing a Hacker News post, he's discovered that decades of language design and type theory were actually a terrible idea now that he thinks about it.

One of the tools I work on in my spare time is a Poker calculator that uses enums extensively for things like suits and hand strengths (flush, full house, etc.). This program doesn't connect to the internet in any way. But I hadn't considered that someone might come along and force me to serialize these poker hands and send them over the wire and change the number of suits and ranks in a deck of cards so that it creates incompatibilities. I guess I should go back and rewrite my code to remove those enums, since that's going to be a problem.

Re:Go Is a Well-Designed Language by roncesvalles on Saturday February 08, 2025 @03:57PM (#42986144)
Go actually has enums in the basic way that you're thinking of them, but they're just constants of a custom type based on int.

So you'd define `type Suit int` and have constants of type Suit that are `const DIAMONDS Suit = 0` ... `const SPADES Suit = 3`.

Go just doesn't have first-class enums with cardinality less than an int, like Java would. Which means you could have a Suit type variable with a value of 4 or 9000, because Suit serializes/deserializes as an int, not some custom string representation as in other languages.