I am currently working on a project that incorporates several different "programming" languages, each of which have their own conventions for how things should be named. Should the same naming convention be used throughout, or should names be different in each language to have a native look (ie not clash with the rest of the framework)?
For example, ths project uses MongoDB(BSON), C#, JSON, and Javascript. Right now I name things in each layer with that layer's convention and then have code between each layer to translate, say from BSON to the C# model. On the other hand, MongoDb would do this automatically if the naming convention was the same.
While there are well-established naming conventions, there's no single one that fits all scenarios. Each programming language recommends its own convention. Each project or organization may define it's own convention. Why should we have a naming convention and what are its advantages?
When a project is written in multiple languages, it's not possible to have a single naming convention. For each language, adopt the naming convention prevalent in that language. Another example is when you're using a third-party library.
When a name is highly localized, lacks business context or used within a few lines of code, it may be acceptable to use a short name ( fi rather than CustAcctFileInfo ). When a project is written in multiple languages, it's not possible to have a single naming convention. For each language, adopt the naming convention prevalent in that language.
It's common for a language to adopt different case styles for different contexts. For example, a PHP convention named PSR-1 adopts the following: PascalCase for class names, UPPER_SNAKE_CASE for class variables and camelCase for method names. Where can I find published naming conventions for different languages?
Twenty-something years ago, when I was just starting my professional career, I'd probably agree with Paul and say "Go for a universal naming conventions!". :)
Today my answer is different. Coming up with a decent naming conventions is a challenging task even when you are dealing with one programming language. Having universal conventions for multiple languages/frameworks is a noble goal and excellent brain teaser, but in general I don't think it's feasible. The syntactic and lexical rules of different languages/frameworks are way too diverse to make "one size fit all". Besides, the set of the employed languages/frameworks can change at any time, and appropriate adjustment of your "universal conventions" could turn out to be prohibitively expensive or prohibitively untimely.
So I would recommend to focus primarily on solid and decent conventions for each language/framework (or for each group of languages/frameworks that are sufficiently similar - like C and C++, for instance). One nice outcome of this approach is that the projects involving only one language would have to adhere to a set of conventions that does not look "foreign".
Having said all that, I believe that some conventions can be common for all the involved languages/frameworks without becoming too "foreign". Moreover, such thing as vocabulary should be common for entire project. This is mostly about semantic and lexical rules, of course; but even some syntactic rules can be universal, too. For example:
Lexical rules for entity names (e.g. "always use singular nouns").
Lexical rules for acronyms (e.g. "use only wide-known acronyms").
Syntactic rules for composite names (e.g. "always use general-then-specific sequence").
The examples above are oversimplified, of course. But I hope the idea is clear: whatever conventions can be common should be common, but it's always going to be just some subset of all the conventions that you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With