You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Mark Thomas <ma...@apache.org> on 2013/08/08 19:50:50 UTC

Code style rules: Line length

Currently, Tomcat has an 'guide' of a maximum of 80 characters for line
length. It has been a while since we reviewed this and as we are looking
at style rules...

As a starting point what do folks think of the following options:

Line length:
 80 - the current
100 -
120 -

Strictness
Informal - the current
Enforce  - Use checkstyle to enforce whatever limit is chosen


Pros for longer lines:
- code easier to read

Cons
- diffs may wrap in mail clients
- harder to work with code in a pure text interface (particularly if
that interface is limited in width to 80 chars)


Comment
- With increasing screen resolution I expect IDEs to manage widths upto
120 or possibly even more
- Few (any?) folks will ever need to work in a pure text UI where the
line length is limited
- My only concern is readability of diffs

I have no strong preference on line length but if we do opt for a longer
length I'd like to see checkstyle enforce the limit.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Code style rules: Line length

Posted by Jeremy Boynes <jb...@apache.org>.
On Aug 8, 2013, at 10:50 AM, Mark Thomas <ma...@apache.org> wrote:

> Currently, Tomcat has an 'guide' of a maximum of 80 characters for line
> length. It has been a while since we reviewed this and as we are looking
> at style rules...
> 
> As a starting point what do folks think of the following options:
> 
> Line length:
> 80 - the current
> 100 -
> 120 -

My personal preference is to soft wrap around 120 and hard limit to something around 132 or 150.
The guideline I use for wrapping is "nothing beyond 120 that is critical to human understanding" which seems to work for the type of constructs that lead to long lines (method signatures, variable initializations) but which wraps things like invocations.

> Strictness
> Informal - the current
> Enforce  - Use checkstyle to enforce whatever limit is chosen

I think humans, who are the ones who care what the code looks like, make better judges than the simplistic rules built into formatters or verifiers.

> Pros for longer lines:
> - code easier to read

I agree with this given wider monitors in landscape mode. I have found myself preferring longer lines over time due to additional decoration in the code (e.g. generic type signatures).
Too short and the wrapping interrupts the flow, too long and horizontal eye movement means you lose context.

> 
> Cons
> - diffs may wrap in mail clients
> - harder to work with code in a pure text interface (particularly if
> that interface is limited in width to 80 chars)
> 
> 
> Comment
> - With increasing screen resolution I expect IDEs to manage widths upto
> 120 or possibly even more

I think this is true for the monitors developers often use when activity working on the code - a 1920 or 2560 horizontal resolution can be common (not counting "retina" type displays) and that can handle side-by-side diffs at 120 or more characters. However, I also use lower resolution screens such as a 1280 wide laptop but that can still display a single column at 120 wide (allowing for chrome).

> - Few (any?) folks will ever need to work in a pure text UI where the
> line length is limited
> - My only concern is readability of diffs

Specifically in email, which does depend on people's mail clients. Mailed diffs though are not side-by-side so the main issue is whether wrapping makes it less readable.

...
If we do change, I think it should only apply to new code and not impact existing code - no reformat for reformat's sake.

Cheers
Jeremy


Re: Code style rules: Line length

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/8/14 Mark Thomas <ma...@apache.org>:
> Summarising the response to this thread so far:
>
> There is a preference for not strictly enforcing whatever limit is
> selected. Rules need exceptions and committers can exercise judgement.
> It does create a grey area but the majority is OK with that.
>
> There is a mix of views on line length but there appears to be support
> for increasing the max line length for code and marginally less support
> for increasing the max line length for comments.
>
> Therefore, I'd like to propose the following:
>
> 1. Introduce a checkstyle enforced hard limit of 200 characters per line
> and fix any lines that exceed it. There are currently 24 lines that
> exceed this limit.
>

+1

> 2. Increase acceptable line length for new / modified code and comments
> to 100. No mass reformatting would take place.
>

+1 for *.java

I would prefer that documentation (.txt, .xml) stay to have
recommended line length of 80.

I do not care about line length in other files such as *.properties.

> 3. Consider further reducing the hard limit to 100 + suitable margin
> over time, possibly in stages. For example, reducing it to 120
> identifies 737 lines (quite a few files have multiple long lines so the
> number of files affected it a lot less than 737).
>

+1

> Thoughts?
>
> I'm inclined to fix the lines identified by 1 regardless. 200+
> characters per line is far too wide.
>

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Code style rules: Line length

Posted by Violeta Georgieva <mi...@gmail.com>.
2013/8/14 Mark Thomas wrote:
>
> Summarising the response to this thread so far:
>
> There is a preference for not strictly enforcing whatever limit is
> selected. Rules need exceptions and committers can exercise judgement.
> It does create a grey area but the majority is OK with that.
>
> There is a mix of views on line length but there appears to be support
> for increasing the max line length for code and marginally less support
> for increasing the max line length for comments.
>
> Therefore, I'd like to propose the following:
>
> 1. Introduce a checkstyle enforced hard limit of 200 characters per line
> and fix any lines that exceed it. There are currently 24 lines that
> exceed this limit.
>
> 2. Increase acceptable line length for new / modified code and comments
> to 100. No mass reformatting would take place.
>
> 3. Consider further reducing the hard limit to 100 + suitable margin
> over time, possibly in stages. For example, reducing it to 120
> identifies 737 lines (quite a few files have multiple long lines so the
> number of files affected it a lot less than 737).
>
> Thoughts?


+1

Regards
Violeta

Re: Code style rules: Line length

Posted by Rainer Jung <ra...@kippdata.de>.
On 14.08.2013 12:41, Mark Thomas wrote:
> Summarising the response to this thread so far:
> 
> There is a preference for not strictly enforcing whatever limit is
> selected. Rules need exceptions and committers can exercise judgement.
> It does create a grey area but the majority is OK with that.
> 
> There is a mix of views on line length but there appears to be support
> for increasing the max line length for code and marginally less support
> for increasing the max line length for comments.
> 
> Therefore, I'd like to propose the following:
> 
> 1. Introduce a checkstyle enforced hard limit of 200 characters per line
> and fix any lines that exceed it. There are currently 24 lines that
> exceed this limit.
> 
> 2. Increase acceptable line length for new / modified code and comments
> to 100. No mass reformatting would take place.
> 
> 3. Consider further reducing the hard limit to 100 + suitable margin
> over time, possibly in stages. For example, reducing it to 120
> identifies 737 lines (quite a few files have multiple long lines so the
> number of files affected it a lot less than 737).
> 
> Thoughts?
> 
> I'm inclined to fix the lines identified by 1 regardless. 200+
> characters per line is far too wide.

Here's my late +1.

Thanks.

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Code style rules: Line length

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Mark,

On 8/14/13 6:41 AM, Mark Thomas wrote:
> Summarising the response to this thread so far:
> 
> There is a preference for not strictly enforcing whatever limit is
> selected. Rules need exceptions and committers can exercise judgement.
> It does create a grey area but the majority is OK with that.
> 
> There is a mix of views on line length but there appears to be support
> for increasing the max line length for code and marginally less support
> for increasing the max line length for comments.
> 
> Therefore, I'd like to propose the following:
> 
> 1. Introduce a checkstyle enforced hard limit of 200 characters per line
> and fix any lines that exceed it. There are currently 24 lines that
> exceed this limit.
> 
> 2. Increase acceptable line length for new / modified code and comments
> to 100. No mass reformatting would take place.
> 
> 3. Consider further reducing the hard limit to 100 + suitable margin
> over time, possibly in stages. For example, reducing it to 120
> identifies 737 lines (quite a few files have multiple long lines so the
> number of files affected it a lot less than 737).
> 
> Thoughts?
> 
> I'm inclined to fix the lines identified by 1 regardless. 200+
> characters per line is far too wide.

+1

-chris


Re: Code style rules: Line length

Posted by Olivier Lamy <ol...@apache.org>.
On 14 August 2013 20:41, Mark Thomas <ma...@apache.org> wrote:
> Summarising the response to this thread so far:
>
> There is a preference for not strictly enforcing whatever limit is
> selected. Rules need exceptions and committers can exercise judgement.
> It does create a grey area but the majority is OK with that.
>
> There is a mix of views on line length but there appears to be support
> for increasing the max line length for code and marginally less support
> for increasing the max line length for comments.
>
> Therefore, I'd like to propose the following:
>
> 1. Introduce a checkstyle enforced hard limit of 200 characters per line
> and fix any lines that exceed it. There are currently 24 lines that
> exceed this limit.
>
> 2. Increase acceptable line length for new / modified code and comments
> to 100. No mass reformatting would take place.
>
> 3. Consider further reducing the hard limit to 100 + suitable margin
> over time, possibly in stages. For example, reducing it to 120
> identifies 737 lines (quite a few files have multiple long lines so the
> number of files affected it a lot less than 737).
>
> Thoughts?
sounds good.
>
> I'm inclined to fix the lines identified by 1 regardless. 200+
> characters per line is far too wide.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>



-- 
Olivier Lamy
Ecetera: http://ecetera.com.au
http://twitter.com/olamy | http://linkedin.com/in/olamy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Code style rules: Line length

Posted by Jeremy Boynes <jb...@apache.org>.
On Aug 14, 2013, at 3:41 AM, Mark Thomas <ma...@apache.org> wrote:

> Summarising the response to this thread so far:
> 
> There is a preference for not strictly enforcing whatever limit is
> selected. Rules need exceptions and committers can exercise judgement.
> It does create a grey area but the majority is OK with that.
> 
> There is a mix of views on line length but there appears to be support
> for increasing the max line length for code and marginally less support
> for increasing the max line length for comments.
> 
> Therefore, I'd like to propose the following:
> 
> 1. Introduce a checkstyle enforced hard limit of 200 characters per line
> and fix any lines that exceed it. There are currently 24 lines that
> exceed this limit.
> 
> 2. Increase acceptable line length for new / modified code and comments
> to 100. No mass reformatting would take place.
> 
> 3. Consider further reducing the hard limit to 100 + suitable margin
> over time, possibly in stages. For example, reducing it to 120
> identifies 737 lines (quite a few files have multiple long lines so the
> number of files affected it a lot less than 737).
> 
> Thoughts?

+1

Cheers
Jeremy


Re: Code style rules: Line length

Posted by Mark Thomas <ma...@apache.org>.
Summarising the response to this thread so far:

There is a preference for not strictly enforcing whatever limit is
selected. Rules need exceptions and committers can exercise judgement.
It does create a grey area but the majority is OK with that.

There is a mix of views on line length but there appears to be support
for increasing the max line length for code and marginally less support
for increasing the max line length for comments.

Therefore, I'd like to propose the following:

1. Introduce a checkstyle enforced hard limit of 200 characters per line
and fix any lines that exceed it. There are currently 24 lines that
exceed this limit.

2. Increase acceptable line length for new / modified code and comments
to 100. No mass reformatting would take place.

3. Consider further reducing the hard limit to 100 + suitable margin
over time, possibly in stages. For example, reducing it to 120
identifies 737 lines (quite a few files have multiple long lines so the
number of files affected it a lot less than 737).

Thoughts?

I'm inclined to fix the lines identified by 1 regardless. 200+
characters per line is far too wide.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Code style rules: Line length

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/8/8 Mark Thomas <ma...@apache.org>:
> Currently, Tomcat has an 'guide' of a maximum of 80 characters for line
> length. It has been a while since we reviewed this and as we are looking
> at style rules...
>

Changing @SuppressWarnings had its technical reasons. I do not see
much reasons to reconsider code formatting.

> As a starting point what do folks think of the following options:
>
> Line length:
>  80 - the current
> 100 -
> 120 -
>
> Strictness
> Informal - the current
> Enforce  - Use checkstyle to enforce whatever limit is chosen
>

My preference is to keep the current "80", not enforcing.

I can go with 100, it is not much of a change.
I think 120 (+50%) will be too much.

Regardless of our preference for Java files, I think textual files
like RUNNING.txt should adhere to 80 characters limit.

We have a bunch of code copied from Apache Commons. Do they have
longer line lengths?

(From a quick look they use the same 4 spaces indent, but I do not see
info on line lengths,
http://commons.apache.org/patches.html


> Pros for longer lines:
> - code easier to read

It depends on your environment.

> Cons
> - diffs may wrap in mail clients

It is my main concern.

Other concern is that sometimes files are compared side-by-side. One
example: "Colored Diff" mode in viewvc.

> - harder to work with code in a pure text interface (particularly if
> that interface is limited in width to 80 chars)
>
> Comment
> - With increasing screen resolution I expect IDEs to manage widths upto
> 120 or possibly even more

Resolution does not matter. Screen size does.  Smartphones and
netbooks that people use in their free time do not have big screens.

> - Few (any?) folks will ever need to work in a pure text UI where the
> line length is limited

I routinely go without an IDE in a console (editing of documentation,
or quick reviews), but I cannot say that my line length is limited. I
can scroll or reconfigure it.

Regarding "non enforcing":
1. It is too dumb of a rule. Sometimes long lines are better. E.g. in
*.properties files we have very long lines.
2. I do not want another global reformatting of the code.

For my own code I use indent of 2 spaces and line width limit of 100
for Java, 75 for documentation.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Code style rules: Line length

Posted by Tim Funk <fu...@apache.org>.
My opinion only (since I've been pretty inactive lately ... only enough
time to lurk)

I'm a big fan of long method/class names and 80 character width drives me
nuts - unless your IDE is a phone - 80 is not very wide.

100 many times is just enough extra space to limit a lot of wrapping.
(preferred soft limit)

120 is pretty wide and with enough side bars open in your IDE - this could
get annoying.




On Thu, Aug 8, 2013 at 1:50 PM, Mark Thomas <ma...@apache.org> wrote:

> Currently, Tomcat has an 'guide' of a maximum of 80 characters for line
> length. It has been a while since we reviewed this and as we are looking
> at style rules...
>
> As a starting point what do folks think of the following options:
>
> Line length:
>  80 - the current
> 100 -
> 120 -
>
> Strictness
> Informal - the current
> Enforce  - Use checkstyle to enforce whatever limit is chosen
>
>
> Pros for longer lines:
> - code easier to read
>
> Cons
> - diffs may wrap in mail clients
> - harder to work with code in a pure text interface (particularly if
> that interface is limited in width to 80 chars)
>
>
> Comment
> - With increasing screen resolution I expect IDEs to manage widths upto
> 120 or possibly even more
> - Few (any?) folks will ever need to work in a pure text UI where the
> line length is limited
> - My only concern is readability of diffs
>
> I have no strong preference on line length but if we do opt for a longer
> length I'd like to see checkstyle enforce the limit.
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

Re: Code style rules: Line length

Posted by Nick Williams <ni...@nicholaswilliams.net>.
On Aug 8, 2013, at 12:50 PM, Mark Thomas wrote:

> Currently, Tomcat has an 'guide' of a maximum of 80 characters for line
> length. It has been a while since we reviewed this and as we are looking
> at style rules...
> 
> As a starting point what do folks think of the following options:
> 
> Line length:
> 80 - the current
> 100 -
> 120 -

I'm for 120. Every single other OSS project I work on is 120. Tomcat is the only thing that's less.

> Strictness
> Informal - the current
> Enforce  - Use checkstyle to enforce whatever limit is chosen

I'm for enforcing. That's another place Tomcat is different from other OSS I work on. The current informal policy is actually more of a pain than I thought it would be. Instead of having a hard rule you know you can depend on, you never know whether someone is going to complain about a line or two being to long in a patch. Often, it varies depending on which committer reviews the patch.

> Pros for longer lines:
> - code easier to read
> 
> Cons
> - diffs may wrap in mail clients

I hope nobody is still reading mail at 800x600. ;-)

> - harder to work with code in a pure text interface (particularly if
> that interface is limited in width to 80 chars)

True, but FYI, if I open a terminal window on my Mac or on any of the Linux distros I use, the width defaults to 140-180 characters. Plenty.

Nick

> Comment
> - With increasing screen resolution I expect IDEs to manage widths upto
> 120 or possibly even more
> - Few (any?) folks will ever need to work in a pure text UI where the
> line length is limited
> - My only concern is readability of diffs
> 
> I have no strong preference on line length but if we do opt for a longer
> length I'd like to see checkstyle enforce the limit.
> 
> Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: Code style rules: Line length

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Mark,

On 8/8/13 1:50 PM, Mark Thomas wrote:
> Currently, Tomcat has an 'guide' of a maximum of 80 characters for line
> length. It has been a while since we reviewed this and as we are looking
> at style rules...
> 
> As a starting point what do folks think of the following options:
> 
> Line length:
>  80 - the current
> 100 -
> 120 -

FWIW, there are lots of folks who have word-wrapping GUI code editors
where mostly the line length does make a lick of difference. Until
recently, I used text-mode Emacs for everything and has an 80-line display.

While Emacs does do word-wrapping, it doesn't treat wrapped-lines like
"normal" lines while using arrow keys to navigate (at least not in
whatever mode I was using). So if you are on line 100, column 120 on a
word-wrapped 80-line screen, pressing UP gets you to line 99, column 120
(or the last column on that line if c < 120) instead of line 100 column
40 (which would be directly above line 100, column 120 on the screen).
While this is a mere inconvenience, it's an inconvenience that happens
*all the time* when long lines are often used (and, in this proposal,
encouraged).

While I now use an editor that doesn't exhibit this behavior, I still
tend to stick to 80-column-max for a number of reasons:

1. I still think it's easier to read
2. diffs are still readable on 80-column terminals
3. My devs don't all use the same IDE/editor/etc. and 80-column lines
are generally more consumable

My vote is to stick with 80-column lines when possible. Sometimes, it's
really silly to break a line -- especially when the result is to have
two lines where the first one has 79 columns and the second line has 85
columns of mostly whitespace.

> Strictness
> Informal - the current
> Enforce  - Use checkstyle to enforce whatever limit is chosen

I strongly support informal strictness. Otherwise, we'll end up with
hard-to-read code that is hard-to-read merely because checkstyle is
being stupidly draconian about the rules. I think humans can exercise a
modicum of self-control in this area.

> Pros for longer lines:
> - code easier to read

I think it's /sometimes/ easier to read. Then again, I'm a fan of method
calls that look like this when the lines are longer than maybe 50
characters:

methodCall(argument1,
           argument2,
           argument3,
           argument4,
           argument5);

This gets IMO more readable when the arguments themselves are method
calls to other things.

> Cons
> - diffs may wrap in mail clients

Yes. I find this very ugly. Unreadable diffs are very frustrating.

> - harder to work with code in a pure text interface (particularly if
> that interface is limited in width to 80 chars)

I do a lot of diff-inspection directly in my terminals (which I keep at
80-columns).

> I have no strong preference on line length but if we do opt for a longer
> length I'd like to see checkstyle enforce the limit.

I do agree with this: I think checkstyle should enforce /some/ arbitrary
(high) limit on line length. Even if we settle on an 80-column
(informal) limit, I think checkstyle should be configured to prohibit,
say, 200-column lines.

-chris