C # coding convention for line width

Possible duplicate:
C # coding style - line length / line break

Is there a widespread coding convention for C #, and is there a suggested maximum line width?

The rule of 80 characters per line is very common, but I think it is too small for C # with generics. So, is there any other convention for C #?

Solution: My team and I decided to go with 100 characters per line, and this seems like a good line width.

+4
source share
4 answers

If I went with “what fits” without thinking, besides this, I would type 60 lines into a function of 260 characters per line and still I could say that “it all fits on my screen”. It does, and I don't use the ridiculously small font size. (9 pt Courier New, a 24-inch widescreen monitor with a resolution of 1920x1200, mainly for all on-screen real estate dedicated to code, a solution browser, a code definition window, an output window, a list of errors, etc. They are located on my second monitor.)

Everyone will have their own opinion, and personally I think that these days the width of 80 characters in the other direction is a bit in the other direction, but depending on what is being discussed, I try to keep myself at 100-120 characters per line, including indentation. If it grows much longer, perhaps it has parts that can easily be broken down and put on separate lines in ways that improve readability.

Because it really is. Readability. I don't care if you use 60 characters per line or 200, but when I need to work with your code, it would be better to read easily and easily understand at a glance what it does.

Also, try breaking the code in such a way as to provide meaningful differences, which, again, are easy to read. This is another rule of thumb that I am trying to adhere to; if I compare two sets of files, I want to see changes that really matter, not kilometers, in which the only difference is the change of one character (which may well be a very correct change, but it is difficult to find in such a hippo).

+4
source

I am trying to ensure that the function is on my screen without scrolling (vertically or horizontally). Of course, everyone has monitors of different sizes, working with different resolutions, and the location of their toolbars / solutions / output windows, etc. It is different, therefore it is difficult to guarantee that everything is in command systems. However, this is a useful guide.

+1
source

I have two monitors, one 26 'and the other 22'. I use the smaller one to place service windows in the form of a file structure, class type, code definition, object browser, explorer for work, output, a list of errors, pending changes (Ankh input), etc. I leave the main window only for the project code and browser, so I said that ReSharper set the line width to 160 characters (just in case I need some line to be so long). Usually I will not exceed 120 characters, this is the length with which I like most. I would be very stupid if I had to work on this monitor with less.

80 characters per line made sense the same day that it was the standard width for text mode monitors.

+1
source

I would go with what fits. Usually I try not to spread too far from the screen I'm working on. Sometimes the artificial narrowing of statements, placing them on several lines, is no more clear than a long single line.

This is a very subjective question!

0
source

Source: https://habr.com/ru/post/1344896/


All Articles