allMembers broke for __

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Jun 16 23:33:13 UTC 2018


On Saturday, June 16, 2018 22:59:24 DigitalDesigns via Digitalmars-d wrote:
> On Saturday, 16 June 2018 at 06:47:59 UTC, Jonathan M Davis wrote:
> > On Saturday, June 16, 2018 06:08:17 DigitalDesigns via
> >
> > Digitalmars-d wrote:
> >> When an identifier starts with __, allMembers does not return
> >> it. This is very bad behavior! It can silently create huge
> >> problems if the programmer is not aware of the bug.
> >>
> >> Instead, if you want to keep the current behavior at least
> >> create an error or warning rather than silently create a bug
> >> to waste the users time tracking it down.
> >
> > I would point out that identifiers that start with two
> > underscores are supposed to be reserved for the compiler.
> > Declaring them yourself is begging for trouble in general.
> >
> > - Jonathan M Davis
>
> So, you are saying that it's ok to beat me over the head and
> cause me trouble simply because I used __? Seriously? I thought D
> was all about making the programmers life easier and not more
> difficult! Thanks for letting me know! I guess it's time to go
> back to C#.

There's no need to be melodramatic. All I'm saying is that identifiers
starting with __ are reserved by the language - just like they are in many
C-derived languages (I would expect them to be reserved in C# as well,
though I don't know for sure if they are). Whether __traits stuff should
ignore such attributes, I don't know (I wouldn't have expected them to be
ignored, and that does seem weird), but either way, if you have any variable
names that start with two underscores (be they member variables or local
variables or whatever), you're potentially declaring variables that are in
conflict with stuff that druntime or the compiler itself declare, and you
risk bugs by doing so. Even if __traits shouldn't just ignore those
identifiers, you shouldn't be declaring any variables that start with two
underscores. If you didn't know that before, then I'm sorry, but the spec
mentions it, and now you know.

https://dlang.org/spec/lex.html#identifiers

- Jonathan M Davis



More information about the Digitalmars-d mailing list