6 ms·
> Go doesn’t technially have Enums and it is a missing feature in my book but there is a Go idiomatic way to achieve roughly the same thing. Oh, so it's a lot
by BugsJustFindMe 3y ago
> Go doesn’t technially have Enums and it is a missing feature in my book but there is a Go idiomatic way to achieve roughly the same thing.
Oh, so it's a lot like Python then.
> This is fine however it is nothing but an integer under the covers this means what we actually have is:
Oh, so it's a lot like C++ then.
> But what you notice here is we have no string representation of these Enums so we have to build that out next
Have to!
Yes this still all sucks. (But at least there's ugly historical precedent!)
- ollien 3y agoPython does have enums in its standard library https://docs.python.org/3/library/enum.html https://docs.python.org/3/library/enum.html
- deleted 3y ago[deleted]
- BugsJustFindMe 3y agoHeh. Python's enums are not real types, they're just funny classes, so you still have to do dumb things like assign an internal value (commonly a dumb int) and were (and probably still are) wildly deficient in many other commonly-desired ways for a very long time. A bunch of things covered in this blog post (like StrEnum and EnumCheck) weren't added until pretty recently.
- zelos 3y agoC++ added enum classes a while back, though.
- pkulak 3y agoGo is in this weird middle ground where it's modeled after C, so it's got things like no enums, return codes for errors, mutable everything, nulls, and pointers (that don't support arithmetic, so it's really just this "*" sigil that you have to remember to use sometimes), but it's also fully garbage collected and has built-in, stackful green threads. I have no idea what it's actually trying to be.
- kaashif 3y agoIt's all of the ergonomics of C combined with the bare metal performance of a garbage collector.
- foolfoolz 3y agoand the verbosity of very old java
- seanw444 3y agoMore efficient than a scripting language, less performant than a systems language. I really like it for anything network-related.
- samatman 3y agoC does have enums. Not trying to detract from your point, which I agree with, but enums are definitely a thing, which C has.
- randomdata 3y ago> C does have enums. Then again, so does Go. Go doesn't have an enum keyword like C, but that isn't what defines enums.
- xigoi 3y agoBut neither C nor Go have type-safe enums.
- randomdata 3y agoThey are type safe. They are not value safe, but neither language supports value constraints, so that isn't unexpected.
- cmrx64 3y agoWhat is value safety? Why should value constraints be pertinent here? near I can tell this is a neologism (introduced here? https://itnext.io/we-need-to-talk-about-the-bad-sides-of-go-568a1e5adbc6 https://itnext.io/we-need-to-talk-about-the-bad-sides-of-go-...) that just happens to be near the top of search results in this area. The introduction rule for enum values in C is _not_ type safe. You know how you can tell? Well typed programs go wrong. a language absolutely does not need value constraints of any kind to get this right.