Possible Duplicate:
C# coding style - line length / wrapping lines
Is there a widely accepted coding convention for C#, and is there a suggested maximum line width?
The 80 characters per line rule is very common, but I think it is a bit too short for C# with generics. So is there any other convention for C#?
Solution: My team an I decided to go with 100 characters per line and it seems to be a good line width.
If I went with "what fits", without much thought other than that, I would be cramming 60 lines into a function at 260 characters per line, and could still argue that "it all fits on my screen". It does, and I'm not using a ridiculously small sized font either. (9 pt Courier New, 24-inch widescreen monitor at 1920x1200, with basically the whole screen real estate devoted to code; the solution explorer, code definition window, output window, error list and so on are on my second monitor.)
Everyone is going to have their own opinion, and personally I think 80 character line widths are a bit off in the other direction these days, but depending on exactly what it is about, I try to keep myself under 100-120 characters per line, including indentation. If it gets much longer than that, there's probably parts in it that can easily be broken out and put on separate lines in ways that improve readability.
Because that is what it really is about. Readability. I don't really care if you use 60 characters per line or 200, but when I have to work with your code, it had better be easy to read and easy to tell at a glance what it does.
Also, try to chunk your code in ways that will provide meaningful diffs that are, again, easy to read. That's another rule of thumb I try to stick to; if I compare two sets of files, I want to see the changes that actually matter, not kilometer-long lines where the only difference is a single character change (which may very well be a very valid change, but is difficult to find in such a behemoth).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With