473,705 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's your maximum line size preference?


Do you have a preference on maximum line width for C++ code?

I've seen the craziest debates on this most silly of topic.

I have witnessed engineers spent oodles of time fiddling with line
breaks just to get it right. I find in general a prescriptive rule
makes for markedly less readable code, which unfortunately is a
subjective argument, however, the waste of time modifying code when it
does not need to is not.

I'm interested in knowing what you'all do.

G
Oct 9 '08 #1
53 12122
Gianni Mariani wrote:
>
Do you have a preference on maximum line width for C++ code?
About 80. I find I seldom write lines longer than this and I prefer to
have several files open side by side.

--
Ian Collins.
Oct 9 '08 #2
Gianni Mariani wrote:
Do you have a preference on maximum line width for C++ code?
Historically 80 characters has been the recommended maximum because
text terminals were that many character wide, and trying to edit code
lines longer than that would require either scrolling horizontally
(assuming your text editor supported that) or ugly line wraps.

Nowadays 80-character-wide terminals are seldom used for programming
and instead freely-resizeable graphical editors on high-resolution
monitors are used instead, so there's no practical or technical limit.

However, personally I still keep my emacs at 80 characters and avoid
lines longer than that when programming. IMO code lines which are too
long are a bit like text lines which are too long: Hard to read. The
very worst case scenario is when code lines are so long that they won't
fit the width of your monitor and you either need to scroll horizontally
to see the entire line (very bad usability) or the lines are wrapped,
which makes the code even harder to read. I have seen code out there
which badly break this concept and use humongously long lines, which is
a braindead idea.

I think the 80 characters is a good width, although I wouldn't oppose
something slightly larger, eg. 100 characters.
Oct 9 '08 #3
Gianni Mariani wrote:
Do you have a preference on maximum line width for C++ code?

I've seen the craziest debates on this most silly of topic.

I have witnessed engineers spent oodles of time fiddling with line
breaks just to get it right. I find in general a prescriptive rule
makes for markedly less readable code, which unfortunately is a
subjective argument, however, the waste of time modifying code when it
does not need to is not.

I'm interested in knowing what you'all do.
Readability is a concern in our team because it's a few hundred strong.
Any time you write code, you have to consider that (a) it's not going
to be read by you and (b) if it's going to be read by you, it can be a
year or more later. So, based on that, I would think that if the line
fully fits in my editor's code window, so I don't have to scroll the
window horizontally to read the entire line, the width is acceptable.
Now, it probably means that on the other man's monitor it could be too
long (if the code window isn't as wide as mine), and unfortunately there
is no cure for that. Hopefully, the monitors do get upgraded and if the
line lengths don't change, eventually all lines will fit. <weakG>

Just like any other style element, the line length participates in a
compromise. For example, you can shorten your lines by using shorter
names for variables and functions, but it detracts from readability in
its own, possibly more unpleasant, way.

Whitespace (line breaks included) has an important role in the code
readability, but I would probably say, "don't get hung up on it". The
ability to read and understand any code without wasting too much time on
reformatting is a skill *every programmer* needs to develop.

Just my $0.04...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 9 '08 #4
Juha Nieminen <no****@thanks. invalidwrote:
>Gianni Mariani wrote:
>Do you have a preference on maximum line width for C++ code?

Historically 80 characters has been the recommended maximum because
text terminals were that many character wide,
Just a digression: the 80-character-per-line standard goes all the way
back to Herman Hollerith and his 80-column punch cards, long before
anybody ever thought of text terminals.

--
Tim Slattery
Sl********@bls. gov
http://members.cox.net/slatteryt
Oct 9 '08 #5
Tim Slattery wrote:
Juha Nieminen <no****@thanks. invalidwrote:
>Gianni Mariani wrote:
>>Do you have a preference on maximum line width for C++ code?
Historically 80 characters has been the recommended maximum because
text terminals were that many character wide,

Just a digression: the 80-character-per-line standard goes all the way
back to Herman Hollerith and his 80-column punch cards, long before
anybody ever thought of text terminals.
But interactive programming didn't become viable until text terminals,
which is one of the biggest reasons why 80 characters has always been
the limit.
Oct 9 '08 #6
On 2008-10-09 11:30, Gianni Mariani wrote:
Do you have a preference on maximum line width for C++ code?

I've seen the craziest debates on this most silly of topic.

I have witnessed engineers spent oodles of time fiddling with line
breaks just to get it right. I find in general a prescriptive rule
makes for markedly less readable code, which unfortunately is a
subjective argument, however, the waste of time modifying code when it
does not need to is not.
I'd say as short as possible without sacrificing the readability of the
code, but keep in mind that a modern monitor is wide. I also think that
different standards can be applied to different kinds of lines, I really
hate things like this:

SomeReturnType SomeClass::Some Method(SomeType 1 artument1,
SomeType3 argument3,
SomeType4 argument4,
SomeType5 argument5,
SomeType6 argument6,
SomeType7 argument7)
{
// ....
}

Since you (in my experience) seldom have to read or change the arguments
of functions (at least of working on a large code-base with a few years
worth of code) you can just keep them all on one line, which gives a
more uniform formatting of functions and makes it easier to quickly scan
the code.

Also, when you get a few indentation levels deep you generally do not
have many columns left (at least not if you have a tab-size of 4 spaces
or more). I therefore think that it might be useful to count the line-
width from the first non-whitespace character (though I've been unable
to convince my employers this is a good idea).

Having said that, take up a few novel (or some other book) and count how
many characters they put on a line and you get a number somewhere around
80, there might be a good reason for that.

--
Erik Wikström
Oct 9 '08 #7
Gianni Mariani <gi*******@mari ani.wskirjutas:
>
Do you have a preference on maximum line width for C++ code?

I've seen the craziest debates on this most silly of topic.

I have witnessed engineers spent oodles of time fiddling with line
breaks just to get it right. I find in general a prescriptive rule
makes for markedly less readable code, which unfortunately is a
subjective argument, however, the waste of time modifying code when it
does not need to is not.

I'm interested in knowing what you'all do.
I am trying to keep a single statement on a single line, unless it's
really starting to get off the screen. It seems the longest lines are
about 130-140 characters. Example of a line ending at pos 133:

HtmlCmdHandlerF ile* main_file_handl er = dynamic_cast
<HtmlCmdHandler File*>(HttpServ er::InstanceNoS tart().FindHand ler("file"));

And yes, when working on the laptop the ends of some lines are not
visible. Given that vertically the cpp file is not fully visible anyway
on the screen, I have not turned much attention to this, and my
colleagues have not complained either.

Regards
Paavo
Oct 9 '08 #8
Chris Ahlstrom wrote:
>
I disagree violently <grin>.

SomeReturnType
SomeClass::Some Method
(
SomeType1 artument1, /**< Destination for the stuff. More comment.*/
SomeType3 argument3, /**< blah blah blah */
SomeType4 argument4, /**< blah blah blah */
SomeType5 argument5, /**< blah blah blah */
SomeType6 argument6, /**< blah blah blah */
SomeType7 argument7 /**< blah blah blah */
)
{
// ....
}

I really prefer dragging my eyes /down/ the page, not left to right,
especially wayyyyyy to the right, then back leffffffffffft again,
then down.

Why do you think newspaper columns are so narrow?

I like code I can page down through quickly and grok at a glance.
That gets my vote. Having a child with an eye tracking problem, I've
been though all the exercises and it's surprising how long it takes for
a normal person to locate the start of the next line when scanning long
lines.

I've tried an edit window with 360 character lines and it isn't fun...
My guess is there's only so much text we can keep in short term memory,
so when a line is too long, we forget the beginning of the current line
which makes tracking to the next one hard.

I'm sure there's some papers on this somewhere!

--
Ian Collins
Oct 10 '08 #9
Chris Ahlstrom wrote:
After takin' a swig o' grog, Erik Wikström belched out
this bit o' wisdom:
>I'd say as short as possible without sacrificing the readability of the
code, but keep in mind that a modern monitor is wide. I also think that
different standards can be applied to different kinds of lines, I really
hate things like this:

SomeReturnTy pe SomeClass::Some Method(SomeType 1 artument1,
SomeType3 argument3,
SomeType4 argument4,
SomeType5 argument5,
SomeType6 argument6,
SomeType7 argument7)
{
// ....
}

Since you (in my experience) seldom have to read or change the arguments
of functions (at least of working on a large code-base with a few years
worth of code) you can just keep them all on one line, which gives a
more uniform formatting of functions and makes it easier to quickly scan
the code.

I disagree violently <grin>.

SomeReturnType
SomeClass::Some Method
(
SomeType1 artument1, /**< Destination for the stuff. More comment.*/
SomeType3 argument3, /**< blah blah blah */
SomeType4 argument4, /**< blah blah blah */
SomeType5 argument5, /**< blah blah blah */
SomeType6 argument6, /**< blah blah blah */
SomeType7 argument7 /**< blah blah blah */
)
{
// ....
}
Just for diversity, I like this:

SomeReturnType SomeClass::Some Method( SomeType1 argument1 /**< Destination for the stuff. More comment.*/
, SomeType3 argument3 /**< blah blah blah */
, SomeType4 argument4 /**< blah blah blah */
, SomeType5 argument5 /**< blah blah blah */
, SomeType6 argument6 /**< blah blah blah */
, SomeType7 argument7 /**< blah blah blah */ )
: data1(argument1 )
, data3(argument3 )
, data4(argument4 )
, data5(argument5 )
, data6(argument6 )
, data7(argument7 )
{
// ....
}

(But then I had never had to look at code at a machine which
only has vi. And hopefully I'll never will. :^)
[...]
Schobi
Oct 10 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1473
by: Robert | last post by:
dear sir: I have read the c++ primer plus 5 book, and do the chapter 12 programming exercises question 5, but the average_wait have negative result. I don't understand why? here is the code, thank you anyone replay me.:) /************************* customer.h *************************/ #ifndef CUSTOMER_H_ #define CUSTOMER_H_
0
8768
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8690
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7895
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6606
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5933
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2491
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2083
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.