[Issue 9065] Please consider adding these std.traits

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 27 04:51:35 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9065



--- Comment #29 from Manu <turkeyman at gmail.com> 2012-11-27 04:51:33 PST ---
(In reply to comment #26)
> (In reply to comment #24)
> > What the compiler calls stuff internally has no bearing on
> > what users of the language will call things.
> 
> It's not an internal thing, that declaration is not an enum declaration,
> period. enum is used as a keyword for more than one thing, which is bad, but
> it's too late to change it now. 
> 
> We shouldn't name things in Phobos based on what people might think is right or
> looks right, but based on what the things really are.

I couldn't disagree more.

Firstly, what it is clearly documented as, is being some subset of enum. That's
what it 'really is'.

More importantly, if I look at the top of std.traits for something I presume to
be called isEnum, and I see isEnumValue, I'll realise that's actually what I'm
looking for immediately, use it, and save myself time.

If I see something called isEnum, and it doesn't seem to work because it only
reports true for enum TYPES (not values), then I'll declare it broken and
report a bug.

If I scan through everything in std.traits, and find nothing that looks like
what I want, I'll get frustrated the thing I need is missing.

If I see isManifestConstant, there is _NO WAY_ I would have even read what that
is, it's clearly not what I'm looking for, I'm trying to identify if my thing
is an enum...


> It's a shame we don't have a 'manifest' keyword of some sort, it would help
> avoid confusion. I guess 'enum' was used to cut back on having too many
> keywords in the language.

I honestly don't even know what manifest means. The terminology used in the
syntax and the documentation is correct; it's a kind of enum.


> Anyway it's documented behavior, see "manifest constants" here (it's at the
> bottom): http://dlang.org/enum.html

And every place it appears, it is clearly defined as being some subset of enum.

Again, if I go looking for isEnum, and find a suite of more specific enum
related traits (isEnumType, isEnumValue), I can easily conclude which is the
one I'm looking for. If the name is completely unrelated and uses terminology
most programmers have never heard before, they'll never spot it.


As a side point, what do you call X in: enum E { X = 10 } ?

Consider:
 enum E { X = 10 }
 enum Y = 10;

E.X and Y are both identical as far as I can tell. I would presume:

isEnumType!E == true, and isEnumValue!(E.X) == isEnumValue!Y == true.
You can tweak the names, but I think traits to that effect are a) useful, b)
what (I presume) most typical users will expect.

E.X and Y are identical. I think this specialised term 'manifest constant' that
only applies to Y can only result in confusion.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list