March 13 Re: D Style document | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dejan Lekic | On Wednesday, March 12, 2025 2:26:47 PM MDT Dejan Lekic via Digitalmars-d wrote:
> On Saturday, 8 March 2025 at 18:46:16 UTC, Jonathan M Davis wrote:
> > The naming rules are rules that every public library should be following if the developers working on it want to fit into the D ecosystem, and some programmers will complain if a library does not follow the official naming guidelines (whereas some other progammers won't care much). Ideally, everyone would be following the naming guidelines in the style guide, but some people prefer not to for a variety of reasons. And of course, when you're dealing with bindings to other languages, you can't always follow the D naming conventions.
>
> Even if I do not deal with bindings, but just work on a library (public, opens-ource) I still do not prefer the camelCase enum member names because the most obvious choices CLASH with D keywords. The most obvious one, that many people would want to use I am sure, but they can't is `default`. Another conflicting one is `double` that you want to use for values that are double of the previous enum value, etc...
For keywords as symbol names, the style guide mandates that you add a trailing underscore, so default becomes default_, and double becomes double_.
In my experience, it doesn't come up very often, but we do have an official way to deal with such naming conflicts. Obviously, not everyone agrees with some of the naming rules, and no one is forcing anyone to follow them (outside of official D source code), so some projects do not follow the official naming guidelines. Ideally though, libraries on code.dlang.org would be following those naming guidelines. So, I'd encourage you to follow the D style guide with your own code that you make public, but it's up to you.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation