[bind10-dev] Enums as array indices and manual vs. auto-numbering
JINMEI Tatuya / 神明達哉
jinmei at isc.org
Thu Aug 25 18:49:09 UTC 2011
At Thu, 25 Aug 2011 21:06:21 +0900,
Yoshitaka Aharen <aharen at jprs.co.jp> wrote:
> +1 to the opinion. If there's no rationale behind numbering enums
> manually, I prefer to assign numbers automatically. I also believe that
> it is safer.
>
> Google Style Guide shows an example which omits assigning numbers:
> http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Enumerator_Names#Enumerator_Names
Thanks for the reference, but this doesn't seem to be related to
whether to prefer specifying the enum values explicitly.
On the main point, I have a mixture feeling as I mentioned in #1068
(which I believe is the trigger of this thread):
http://bind10.isc.org/ticket/1068#comment:8
<quote>
Personally I have a mixture feeling about this. On one
hand I think your point is valid. On the other hand, I don't like to
depend too much on implicit assumptions even if they are guaranteed by
the language spec - just like it's error prone to enumerate everything
by hand (I agree on that), I think it's also the case code relying on
implicit assumptions is error prone. Someone who doesn't understand
the rationale may, perhaps for a bogus reason, want to change the
initial value of the enum to non 0:
enum DeleteRecordParams {
DEL_NAME = 1, ///< The owner name of the record (a domain name)
///< It begins with 1 as it seems to make more sense
DEL_TYPE, ///< The RRType of the record (A/NS/TXT etc.)
DEL_RDATA ///< Full text representation of the record's RDATA
};
And then the code will suddenly start failing in a strange way.
In this specific it would be easy to detect and fix it via unittests,
but there may be more subtle cases. We could also add a note that the
use of the default definitions has a reason and should not be changed
in comments, but commenting something is also an error-prone human
involved practice.
</quote>
So, I personally don't think that the use of implicit assignments is
as safe as it might look. But this is not a strong opinion. I don't
necessarily disagree with switching the style if others prefer that
way.
So my vote would be -0.1 (mostly neutral, but with a slight preference
on *not* relying on implicit assumptions).
---
JINMEI, Tatuya
Internet Systems Consortium, Inc.
More information about the bind10-dev
mailing list