Safer Enums in Go

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • enumer

    A Go tool to auto generate methods for your enums (by dmarkham)

  • 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

    A fast and lightweight native programming language

  • 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...

  • 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.

    InfluxDB logo
  • tech

    Toolkit for the Go programming language. (by qlova)

  • 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).

  • v-mode

    🌻 An Emacs major mode for the V programming language.

  • 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.

  • go

    The Go programming language

  • > 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

  • githut

    Github Language Statistics

  • >> 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

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts