I saw this question on SO: here; the question is kind of old and not many viewed, so I want to ask it again.
I currently work on a project using C++, C# and Actionscript-3, the conventions of C++ and C# are similar, but AS3 is not.
For example, the function name conventions differ a lot, it’s common to use GetFoo()
in C++ but getFoo()
in AS3.
According to the SO question’s answer, it suggests that using different convention for different languages is more appropriate, which is also my opinion; I’d like to just accept it, but it’s kind of too brief; to persuade my team members, I’d like to look for more detailed pros and cons.
4
Coding standards should be specific to the particulars of each language and platform. An idiom that is considered essential in C++ might be superfluous for another language such as C#. For example, you might insist of always placing a constant in an ‘if’ expression on the left (5 = x) to reduce the chances of accidentally having a single equals accepted as good code by the C++ compiler. In C# this is not relevant because the expression must return a boolean and so you can never accidentally have a single equals.
Adding extra conventions just to make the languages consistent means each language will end up with meaningless rules that are not relevant and therefore will annoy the developers.
It is also important to use standards that are likely to be familiar to other programmers in the same community but not working at your company. New recruits should not be completely surprised by the coding standard because it is so different from everyone else in industry.
3
Please, use the standard conventions for each language (or somewhat very close to the standard).
- More consistency in each piece of software itself (because it will have the conventions that really apply)
- More ease for additional (external) fellow developers. They must not learn “inconsistent” styles.
- Easier comparison/review/transfer of code out of / into examples in the “world outside”
- No regrets later, see below
Here’s what I experienced:
I am currently working in a shop where they first did Java-only projects. Then, they started to do C#/.NET and applied the already-well-known Java styles/Naming conventions to those C#/.NET projects.
When I (and others) joined the team, after doing C# for years, I was really annoyed with how the code looked like and had a hard time to continue with the perceivedly awkward Java-style in the C#/.NET projects.
Later they figured, that having a “wrong” style is bad, and started to adopt the C#/.NET conventions in new C#/.NET projects. Now we have really mixed up styles – sometimes different within a platform, sometimes different in the projects. Hopefully, over time, we will write less Java-styled C# code, but in my perspective, it would have been better to never start out doing that at all.
Bottom line:
What you could do
- Consistent brace rules (Opening one on new line / same line)
- Consistent commenting rules (e.g. XML only)
- Rules about code quality (length of methods, unit testing frequency etc..
- Use a tool to help applying the above
What you really should keep per language / platform
- Namespaces
- Casing of identifiers
- Naming styles for identifiers
5