When migrating from one C language to another, change the style?

I am in conflict as to which style of code should I follow when using another C language.

I am currently doing work (different projects) in C ++, C # and Objective-C

I noticed that there are many inconsistencies in the basic principles of the conventions. Generally, I don't think it's a bad idea to stick to these conventions, as it makes the code more "integrated" into the environment. However, I find it difficult to remember all the differences and apply the principles correctly.

In C #, for example, all class methods run Uppercase, while Objective-C seems to prefer camelCase style methods.

Which tactic would you choose:

  • One style to rule them all (as far as applicable)
  • Stick to what is common in your environment.

I especially like google styleguides , which seem to recommend the latter. However, I disagree with them in using spaces instead of tabs and their indentation in general (like methods at the same level as a class, etc.).

+2


source to share


2 answers


I think you should stick to the "accepted" styles for each language. My rationale for this is that I think it would be much easier to remember what environment you are in when you need to think in the style used for that language. Also, someone who is familiar with this environment will find it much easier to look at your code and feel more comfortable with styling and formatting (i.e. less chance of them getting the wrong idea of ​​what they are looking at).



+4


source


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

My rule of thumb with changing old code: Use the file style.



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

+1


source







All Articles