On Sun, Feb 2, 2020 at 7:52 PM Steve Roth <st...@rothskeller.net> wrote:

> Your assertion that "using an enum as a slice index would NEVER be safe"
> seems rather extreme to me.  It may be true in an academic sense, but in
> pragmatic engineering, enums defined using iota are not sparse and using
> them as slice indices would generally be quite safe.  Yes, this is safety
> by convention, but conventions are often effective.
>

Sorry, but I disagree with you. In fact, I have encountered several bugs in
the past four decades precisely because the "convention" was that the range
of an enum started at zero (or one) and the values were contiguous. When
the definition of the enum was changed so that it violated either of those
conventions the code was broken. Note that I didn't deliberately, just for
the heck of it, change the definition of the enum values. I did so because
the incorrect assumption masked bugs in the code. The bugs were most often
in unit tests but I found at least two bugs in the code being tested when I
violated those "conventions".

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD-TA3sE4qjRm-0_AaT3s0hXR%3DFkDxcdxWNqgacdtLcQkQ%40mail.gmail.com.

Reply via email to