4

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.

Marson Mao
  • 149
  • 4
  • 2
    `camelCase()` for method names is an abomination. Just sayin'. Java programmers use it for method names as well, and it's just as terrible there. But if your ActionScript programmers are more comfortable with the camelCase, then that's what they should use, assuming you can make it your shop standard. – Robert Harvey Feb 13 '15 at 04:13
  • 1
    Since you will inevitably have to use libraries of the respective languages, it's much less jarring if you follow the convention of each language than to try and impose the same convention on every language. Not to mention, languages differ in the kinds of identifiers permitted. – Rufflewind Feb 13 '15 at 04:38
  • Regarding the duplicate vote, even though the title of the question is not an exact match, the currently accepted and highest-voted answer provides the strongest rationale for cross-language naming convention issues, which is to go with each language's conventions, and to remain pragmatic and flexible and to tolerate a small amount of inconsistencies. – rwong Feb 13 '15 at 05:06
  • Yeah I agree with using it's own style for each language; but my team members agreed to use consistent style, since they are not willing to remember "when should I use capital word for function?", they just want to make 1 rule, then apply to everything. I'm not sure if these opinions are "strong" or "practical" enough to persuade them. – Marson Mao Feb 13 '15 at 05:54

2 Answers2

5

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.

Phil Wright
  • 409
  • 1
  • 3
  • 6
  • 3
    Sounds convincing, but we are not encountering idiom issue; it's actually rather simple, the members just don't want to remember to use C++ style when writing C++ and to use AS3 style when writing AS3, they just want "simple and the only one style". The case is that, we are implementing the same logic using both C++ and AS3, so for example, the function names are basically all the same, so that members do not want to write `GetFoo()` in C++ while they have to remember and switch to `getFoo()` in AS3. – Marson Mao Feb 13 '15 at 05:57
  • To be clear: I'd really like just accept and apply your opinion in our project, I total agree with that, but I am not sure if the members would like that explain...Are there any more examples? Thanks – Marson Mao Feb 13 '15 at 05:59
  • You know, any compiler worth using will warn you about assignments in that situation. Though you might have to use sensible warning-levels. Yoda-conditions are a needless obfuscation. – Deduplicator Jul 05 '18 at 21:06
1

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
Marcel
  • 3,092
  • 3
  • 18
  • 19
  • Could you please explain how this happened: "Later they figured, that having a "wrong" style is bad"? I think that's they key here! – Marson Mao Feb 13 '15 at 07:21
  • @MarsonMao Because it was really annoying for us new kids on the block to do "wrong" style (Java-Style in .NET projects), when we came in as experienced C#/.NET coders. It really felt bad. – Marcel Feb 13 '15 at 07:24
  • I see...so they accepted your "bad feelings", however in my case, the "good feelings" are to use consistent convention. The "feeling" issue is hard to talk about correct/incorrect, but I'll try to express what you said to the members. Thanks! – Marson Mao Feb 13 '15 at 07:41
  • @MarsonMao Well, everyone has had a good feeling, as long as there were no outsiders. But your business will grow, and you will hire some more people, right? – Marcel Feb 13 '15 at 08:00
  • True it is, but somehow the new guys are commonly either don't care, or accept that consistent convention is good; I don't know why; maybe most people here are too lazy? – Marson Mao Feb 13 '15 at 08:15