Idiomatic Enums in Go

A programming idiom is the usual way to code a task in a specific language. Although Golang does not have built in support for enumerations there is an idomatic way to emulate the feature. The idiomatic way to have enumerations in Go is to use a combination of the Iota and Integer types. type TaxonomicRank int const ( Animalia TaxonomicRank = iota Plantae Fungi Protista Archaea Bacteria ) func (m TaxonomicRank) String() string { return toString[m] } var toString = map[TaxonomicRank]string{ Animalia: "Animalia", Plantae: "Plantae", Fungi: "Fungi", Protista: "Protista", Archaea: "Archaea", Bacteria: "Bacteria", } var toEnum = map[string]TaxonomicRank{ "Animalia": Animalia, "Plantae": Plantae, "Fungi": Fungi, "Protista": Protista "Archaea": Archaea "Bacteria": Bacteria, } For extra credit, as they say, we can add support for serialization support for our enum with the following...

June 19, 2021

Exploring Data Exchange in Go

A common task for a software engineer is to transform data from one format into another that is suitable for their needs. Some data formats are good for storage, others are easy to edit, and some are ideally suited for transport. Transforming data from a source format and into a target format is known as Data Exchange. There are many well known, commonly used, data formats YAML, XML, CSV, and JSON are popular text based human readable formats, binary formats like Protobufs and Flatbuffers are are gaining in popularity due to their improved serialization performance and small size when compared to text based formats....

January 9, 2021