views:

164

answers:

4

Most style guidelines for most programming languages recommend a maximum line length, typically 80 characters. This seems impractically short for HTML and JavaScript (when it is embedded in HTML). Is there a consensus on a practical line length limit for HTML/JavaScript? Or is it generally left up to the developer's common sense?

+1  A: 

It's left up to common sense.

Bryan Oakley
+1 unfortunately common sense is not to common nowadays :)
Anurag
A: 

The maximum limit on line length is whatever you feel comfortable reading and editing. personally, any code of mine that won't fit on the screen without wrapping will be rewritten.

VoodooChild
+1  A: 

The 80 character line limit spawns from the days of screens without a lot of real estate. Now it's just like that for readability, and so it's possible to have two (or more) different code files opened side-by-side, without having to scroll to see each of them.

Those reasons still apply to HTML and JavaScript, although, it's obviously not necessary to comply with them. So it's up to you.

I agree that with HTML it can be difficult to keep within that limit, although with JavaScript it shouldn't be a problem.

Carson Myers
Thanks! The reason I mention javascript is because it is sometimes embedded several indentation levels-deep in HTML. But I am really mostly talking about HTML.
Matthew
Well I suppose one could say you shouldn't have deeply nested javascript in an HTML page. Personally I prefer to only have one language per source file as much as possible
Carson Myers
+2  A: 

Since you mention JavaScript, this is what Douglas Crockford has to say on the topic:

Avoid lines longer than 80 characters. When a statement will not fit on a single line, it may be necessary to break it. Place the break after an operator, ideally after a comma. A break after an operator decreases the likelihood that a copy-paste error will be masked by semicolon insertion. The next line should be indented 8 spaces.

From: Code Conventions for the JavaScript Programming Language

Daniel Vassallo
8 space indent I find make the code harder to read and severely limits how much code you can out in a line
Newtopian
@Newtopian: Note that he recommends an 8 space indent only for the line that follows a statement break, ie. when a statement does not fit in a single line. Otherwise he recommends "The unit of indentation is four spaces". Personally I tend to prefer a 2 space indentation in JavaScript.
Daniel Vassallo