Why is @enum 0-based?


Arrays in Julia are 1-based, so why are Enums 0-based?

julia> Base.Enums.@enum ABC begin

julia> ABC(0)
A::ABC = 0


This was just recently discussed on Slack, in the gripes channel:


They’re partly designed for C interop which is probably why they’re like that - Stefan K.

I think they should start at 1 in a language like Julia (ie. using them as indexes), you could open an issue if you agree, or a PR, if you can change it yourself.

They will tell you that you can do:

@enum RoundFoods Cookie=1 Cake Pizza Pie

but that should be the default IMHO, and people using it for C interop, should be the one doing:

@enum RoundFoods Cookie=0 Cake Pizza Pie

Instead, as this is a generic language feature, not an interop specific feature.

It’s still breakage season, so why not? Better to have consistency across the language, good luck convincing them though.


I thought so.

I think it’s not too bad, because when you want to use them you usually don’t care about the actual values, and when you actually care about the values you probably want to specify them yourself.