Comment

Comment by sacado2

Provided C-tiers enums are just constants associated with an integer value, go's `const` are already providing you with the same thing, and are even more strongly typed.

    enum foo {Bar, Baz, Foobar};
    void f() {
        enum foo f = 5; // Will happily compile
        int f2 = Baz;   // Will happily compile
    }
vs

    type foo int
    const (
        bar foo = iota
        baz
        foobar
    )
    
    func f() {
        var f foo  = 5    // Will happily compile, i.e as bad as C-tier enums
        var f2 int = baz  // error: cannot use baz (type foo) as type int in assignment
    }
parent sacado2 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton