Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
We tried out struct-based enums like this for a while and they're definitely better than the vanilla version, but they still have the problem of "how do you iterate over all the values?" and "how do you create an enum value from a string?". We chanced upon https://github.com/dmarkham/enumer a few months ago and have been very happy so far.
Virgil has enums where each enum value can have additional fields, so you can write tables and name individual rows. Under the hood the enum value is just an integer and "accessing a field" is just an access of a constant in an array.
It's turned out to be incredibly useful.
https://github.com/titzer/virgil/blob/master/doc/tutorial/En...
That code appears to be using reflection, and any checking is done at runtime?
https://github.com/qlova/tech/blob/c6379c9c32e5b7b2973bc02ba...
That's a big difference from other languages where this is all handled at compile time (ex. exhaustive switches).
One of the offshoot languages of Golang, is Vlang (https://vlang.io/), and the other is Odin. Vlang has both sum types and real enums.
> It is an absolutely terrible design decision to not have package level immutables that aren’t PODs.
FWIW here is a proposal to expand const in Go: https://github.com/golang/go/issues/21130
>> incredibly impressive how popular Rust has become
But it hasn’t become popular yet, it’s not competing with something like Go or C++, it’s competing with Erlang or Clojure for popularity
https://madnight.github.io/githut/#/pull_requests/2021/4