Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line width formatting standard [closed]

People also ask

Why do we use <= 80 characters for lines in this course?

Zooming Way in for Videos Zooming in to the point where 80 characters fits your whole screen at 1080p is very nice. This will ensure that the font size is large enough so smaller devices can read it, and more importantly, people will be able to read it without having to full screen your video.

How wide should your code be?

If there's any accepted industry standard for maximum line width, it's 80 characters. I've used that maximum for years, and it's a good maximum. Like all other programmers, other people's code annoys me. The most common annoyance is that people write too wide code.

How long should code lines be?

Ideally, one line of code is a unit element that means or performs something specific – a part of a sentence if you will. It is generally agreed that the ideal length for a line of code is from 80 to 100 characters.

Where does the 80 character limit come from?

The origin of 80-column text formatting is earlier than 80-column terminals -- the IBM punch card dates back to 1928, and its legacy to paper tapes in 1725! This is reminiscent of the (apocryphal) story that the US railway gauge was determined by the width of chariot wheels in Roman Britain.


Don't compromise readability for dogmatic rules on the exact number of characters in a row. Horizontal scrolling is undesirable but an 81-character line is easier to read than an indentation-confusingly line-wrapped version.

80 characters is likely to be inadaquate for programming styles with large indentations and/or verbose variable names. Keep the amount of logical complexity down to a per-line maximum, not the number of characters.


I stick to the 80 lines rule (And try to convince everyone to do the same). Some reasons:

  1. You can open 2 (or more) editors at once.
  2. Same thing with compare tools. - most (all?) of them display the two(some three (some more ?)) files side by side.
  3. Sometimes you need to work from remote, on a different workstation, or a laptop, and suddenly, your nicely formatted 120 char's to line code looks horrible.

I prefer longer lines for one simple reason: I can fit more code into my window. There is a huge difference between having to scroll vertically to read a function and being able to fit it in a single screen. If everything is line-wrapped so that the function scrolls off the bottom while the right half of my screen is empty, I consider that to be a huge waste. Note that opening two editor windows doesn't help here either.


You should not have to scroll horizontally to read the code. But larger screens does not mean longer lines! There is also a limit to how much there should go on in a single line.

So I say: Keep it at 70-80 chars just as always. Larger screens just means that the IDE as more room.


It also depends on other conventions that you're using. At one job, we were programming in Java and the convention was to use long and descriptive identifiers, which meant that only a couple of them could fit on a line without running into the 80-character limit. I thought that was pretty stupid considering every developer in the company was given a widescreen monitor that could easily fit 200 characters. With hardware consistency like that it makes no sense to enforce a stupidly small line wrap limit.