views:

197

answers:

6

Similar Questions

While coding, how many columns do you format for?
What is a sensible maximum number of characters per line of code?
Do people still live by the 80 column rule?
The 80 column limit, still useful?


By code margins I am referring to the lines that guide how long a particular line of code is. Different IDEs have different language for this device, I believe Visual Studio calls them 'gutters'.

That being said, is there a particular standard to the length code margins? My IDE (Netbeans) has 80 by default but I was wondering if there was any rhyme or reason to that default.

+3  A: 

This is normally set to 80 because this is the standard width of a terminal in characters, allowing code to be easily viewed from the command line.

It's still popular in languages like python where whitespace is important and it's common to work with the interpreter via a CLI, but is becoming less standard in other languages.

mavnn
+9  A: 

We've been using 80 columns for over 80 years, thanks to IBM's punch cards. It's the default text mode on a PC, and it's the default size of a terminal window. Keeping your lines under the 80 column limit means they can be displayed without wrapping in those environments.

I believe the Visual Studio default is 120 columns (although that can be changed), which in my opinion makes more sense given the LongVerboseDotNetCompliant naming conventions. When working in an IDE, it's pretty common to maximize it, so an 80-column limit tends to waste space unless you have a lot of sidebars open.

I happen to prefer 72 (when writing HTML, Python, etc.), which allows my code to fit in a standard terminal with room to turn on line numbers.

jleedev
you just barely beat me to it...this is the REAL answer
Chris Shouts
Nice to know where this standard originated.
James McMahon
It's not just from punched cards. Typewriters could type 80 10-pitch fixed-width characters across an 8-inch wide piece of paper.
Loadmaster
A: 

I typically code at a size that some unlucky individual could be able to view it on 1024x768

0x808080
+1  A: 

Depends on:
1) whether you're going to print the code onto paper (e.g, for handouts at code reviews);
2) what environment anyone else who examines or maintains the code will use.

80 columns is the universal standard (as stated prevously), so code that fits within that width can be printed on any printer in existence. Likewise, 80-column code can be viewed and edited by any editor in existence without having to deal with line wrapping.

On the other hand, if you know your team is always going to be using widescreen IDE editors and landscape-mode printing, 120 columns is a reasonable code width maximum.

You should also use a reasonable indentation width, such as 3 to 5 spaces. 2 spaces is usually too small to see aligned statements in long methods (but okay for small methods in languages like SQL), while 8 spaces uses up quite a lot of horizontal real estate unnecessarily.

Loadmaster
A: 

80 columns has an additional advantage, other than compatibility with less capable environments: long statements that are broken up into shorter lines in a semi-intelligent manner are generally easy to read than a single 120-column line, even if the environment can display that without wrapping it.

ceo
A: 

I have seen people using long (120 or more) columns, but I stick to 80 columns for reasons explained above and others such as:

  • Ease of code review - either via printing or using tool (Code Collaborator)
  • Split screen on 17" or above monitors. Two code windows side by side (e.g. header and cpp) allows easier coding.
  • Avoids going to too many nested code, it helps keep logic simple!
  • Helps writes more concise and simpler code, due to short and simpler names, easier logic etc.

So, it all depends on whether you are working alone and how all the code will be consumed - read or maintained by others etc.

Ketan