c# - About differing coding styles/guidelines -


Someone came in my head last night, I was wondering why there are still different coding styles among projects. Since the style is something private, I think it would be better to treat it better, why do not we? Is there any technical limitations on this?

Let me give you some examples:

  // code sample 1 random object. . (Where item => item.color == color.rud). Country (); // Code sample 2 random objects. Colour. Where (item => item color == color red). Count (); // Code sample 3 random objects. Colors.Count (item => item color == color rood); // Code sample 4 if (criteria) {// do stuff} and {} // sample sample 5 if (criteria) {// do stuff} and {}  

code sample 1 And 2 technically do the same (if I'm not mistaken) On the other hand, code samples 2 and 3 are different, they do something differently under the hood, but give similar results. For this, the code can not be rewritten in Example 1, yet it is possible to format it. Code samples 4 and 5, I think you have seen them before, I do not think they need further lectures.

So, what do I wonder ... can not we work with coding locally priorities, and / before the scan, the code according to the settings of the server is reformat Will go

** Strongly thinking: can not we work?

You can consider using the tools for VS (free unfortunately free), which Optimization codes provide formatting indication. You may have a different setting for each repository.

My idea is to stick to the "official" repository style, if any, though it can be annoying. This improves the readability of code for all developers. If there is no such standard, choose a style that will not be an obstacle for your colleagues.

For example, the sample is better than 5, because it is less crowded and it is easy to see what the line is doing, in my opinion at least I also think that sample 1 2 Better, though I have used another version:

  randomObject.Colors Where (item = & gt; item.color == color. ();  

In addition, sample 2 and 3 give the same result, but 3 is more efficient, and more concise Apart from being, I feel that this is very much better.

How do you do this before writing your code and locating it with your own style locally? There are tools for me but I believe they can not rely on indiscriminately, therefore You have to check that everything works properly as it has been done after the upgrade. It takes time, possibly before the code will be taken with the "standard" style, you can reformat by hand , But this is probably worse.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -