Hi,
I often find people and websites suggesting to use a max length of 80-100 for a line of code. Traditionally, the max length has been 80 characters, which was invented by COBOL around 1960 as far as I know. However, nowadays people have widescreen monitors and high resolution monitors, so, it makes me think about what is the "best" choice for a maximum length limit.
This is kind of blurry, because if you use a larger font or a larger font size - obviously you will run out of horizontal space sooner. So, I'm not sure what should be the limit of line height...
What are you thoughts on this?
Here's what I have been thinking:
- Coders have at least 1024 px in horizontal direction
- Coders use fixed-width fonts
- Coders use at most 14pt font size?
I've been trying to determine a good max line length and I usually come up with something like 80-100 characters/line.
However, this is not quite simple... netbooks are 20% of the laptop market - and they have smaller screens. What about people who have bad vision? They might use larger font sizes. To make matters worse, almost every single editor has sidebars, which take up some horizontal space.. so, it's pretty much impossible to find a good maximum limit, or is it?
I know that most editors have that "wrap overlong lines" feature, but if I have plenty of comments in my code, it may look bad if the editor wraps the lines based on the length..
The length of a line of PHP code?
Moderator: General Moderators
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: The length of a line of PHP code?
Nagative I still use 10pt...courier new...- Coders use at most 14pt font size?
I would say so...I personally focus more on SLOC (per method, module, file, class, etc).To make matters worse, almost every single editor has sidebars, which take up some horizontal space.. so, it's pretty much impossible to find a good maximum limit, or is it?
To further complicate this issue...what about editors (or coders) enable wordwrap?
I personally *hate* long lines. Long lines typically mean confusing code (unless were talking language strings or something trivial). When I see long lines it's usually of the form:
Code: Select all
$a = ($b > $c ? ($d < $e ? $f : $g) : $h > $i ? $j : $k);Ahhh...thats why you want to know...I dunno what to say...difficult question to answerI know that most editors have that "wrap overlong lines" feature, but if I have plenty of comments in my code, it may look bad if the editor wraps the lines based on the length..
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: The length of a line of PHP code?
I see. Courier New 10pt on my 24" looks like waste of an insect...PCSpectra wrote:Nagative I still use 10pt...courier new...
Hmm, yeah. Sometimes you just can't split, think about regular expressions, for instance, but the question is this: where do you draw the line between long lines and short lines?PCSpectra wrote:I personally *hate* long lines. Long lines typically mean confusing code (unless were talking language strings or something trivial). When I see long lines it's usually of the form:I hate the ternary operator for that reason...I much prefer IF statements in these cases but some developers just love putting complex lines of code on a single line...Code: Select all
$a = ($b > $c ? ($d < $e ? $f : $g) : $h > $i ? $j : $k);![]()
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: The length of a line of PHP code?
Regular expressions can usually be greatly simplified by taking advantage of string interpolation:Hmm, yeah. Sometimes you just can't split, think about regular expressions, for instance, but the question is this: where do you draw the line between long lines and short lines?
http://www.iamcal.com/publish/articles/ ... ing_email/
Now the regex resembles something akin to EBNF as opposed to the crazy cryptic RE's
Anyways, to answer your question, I draw the line pretty short. The only time line length becomes an issue for me is when leaving inline comments or language strings, in which case I usually move the comment to a new line and/or replace the language text with a DEFINE placeholder or something similar.
I hate scrolling horizontally...drives me nutts...so I avoid long lines as much as I can.
Cheers,
Alex
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: The length of a line of PHP code?
Well yeah you could just do:PCSpectra wrote:Regular expressions can usually be greatly simplified by taking advantage of string interpolation:
Code: Select all
preg_replace('...'.
'...'.
'...','','');So, maybe I'll stick with the sum of Euler's totient function over the first sixteen integersPCSpectra wrote:Anyways, to answer your question, I draw the line pretty short.
I hate scrolling horizontally...drives me nutts...so I avoid long lines as much as I can.