views:

73

answers:

2

I find myself in conflict, regarding which code style i should follow when using a different c language.

Currently i am doing work (different projects) in c++, c# and objective-c

I noticed there is a lot of discrepancy in the conventions basic frameworks follow. Generally, i dont think it's a bad idea to adhere to these convetions, as it makes code feel more "integrated" into the environment. However it is hard for me to remember all the differences and apply principles correctly.

In C# for example, all methods of a class start Uppercase, while objective-c seems to prefer lowerCase style methods.

What tactic would you choose:

  • One style to rule them all (as far as applicable)
  • Stick with what is common in the given environment

I do especially like the google styleguides, which seem to recommend the latter. However i disagree with them on using spaces instead of tabs and their intendation in general (e.g. methods on same level as class etc.)

+4  A: 

I think you should stick to the "accepted" styles for each language. My rationale for that is that I think it would be much easier to recall what environment you're in when you have to think in the style used for that language. It will also be much easier for someone who is familiar with that environment to look at your code and feel more comfortable with the style and formatting (i.e. less chance for them to misunderstand what they're looking at).

Michael Todd
Agreed. I think about half the C# conventions are dumb, but I still use them, even in code nobody but me will ever see.
Matt Briggs
+1  A: 

My rule with porting code is: Don't touch it unless you have to.

My rule with modifying old code is: Use the style of the file.

Outside of those two situations, things like coding standards and perhaps your own opinion on good style can come into play.

T.E.D.
i am not porting any code, it is related to different projects.
Johannes Rudolph