debug a reserved keyword (even for enums?)
libxmoc
libxmoc at gmail.com
Sun Apr 12 07:27:21 UTC 2026
On Saturday, 11 April 2026 at 23:27:14 UTC, Kapendev wrote:
> On Saturday, 11 April 2026 at 09:33:34 UTC, libxmoc wrote:
>> The fundamental issue isn't whether non-contextual keywords
>> are easier to parse, it's that D already has a mechanism to
>> disambiguate: the dot operator. loggingLevel.debug,
>> Align.align, and SemVer.version are all unambiguous to both
>> the parser and the reader. The token following a dot is
>> already in a different lexical context.
>>
>> There's precedent for this in other languages. Rust allows
>> self.as and match.as because keywords after . are unambiguous.
>> Even C#—hardly a radical language—has contextual keywords in
>> specific positions.
>>
>> The "trailing underscore" convention is a concession that
>> keeps accumulating.
>>
>> debug_, version_, align_, function_, immutable_... at what
>> point do we acknowledge that the cure (universal keyword
>> reservation) is worse than the disease (contextual parsing
>> complexity)?
>>
>> Editions exist precisely to make breaking improvements like
>> this possible without fragmenting the ecosystem.
>>
>> Let's do it.
>
> Breaking things just to be able to use `align` or `debug` as a
> variable or enum name is not worth it. The solution: find
> better names.
>
> - align: alignment
> - debug: debugMode
>
> No language change needed and is backwards compatible. Can't
> comment about contextual keywords.
You are asking me for a concession, again. This is the whole
point.
Sure, I can rename `align` to `alignment` and `debug` to
`debugMode`. But that's not the real win here. The real win is we
don't get stuck with more `__keywords` down the road, and we give
back control and _choice_ back to the user.
Look at `__gshared`. It's ugly. Now look at `__traits`,
`__vector`, `__parameters`. D already has this pattern of double
underscore escapes because new features can't use clean names
without breaking stuff. And it's only going to get worse. What
happens when we want `async`? Every one of those is a common
identifier in real code.
Deserializing XML with an `align` field for your UI? Oh too
badn,you have to hack your serializer to make an exception. Or
rename the field in your D struct to `alignment_` and map it
manually. Or tell your API team to change their schema because D
can't handle a common word..
Same with JSON from some external service that uses `version`. Or
a database column named `debug`. You are now fighting every data
format, config file, and third party API that happens to use a D
keyword.
I hit this with a CSS parser, `align` is everywhere in CSS. I hit
it with a package manager, `version` is in every manifest. Every
time it's "oh, just work around it"
But these workarounds satck up. They leak into serialization
logic, binding generators, ORMs etc..
People work around this mess constantly, it's friction. And every
time someone proposes a new feature, the first question is "what
keyword can we use that won't break the world?" That's backwards.
Other languages solved this.
More information about the Digitalmars-d
mailing list