473,554 Members | 3,181 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
53 12062
On Oct 9, 6:17 pm, Juha Nieminen <nos...@thanks. invalidwrote:
Tim Slattery wrote:
Juha Nieminen <nos...@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.
What does interactive programming (whatever that means) have to
do with it? Fortran restricted line width to 72 characters,
ignoring the last 8 on the card (so that you could put sequence
numbers there---very useful for resorting the code if you
accidentally dropped the deck). The reason most terminals where
80 characters per line is *because* that was the width of the
cards.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 10 '08 #11
On Oct 9, 11:30 am, Gianni Mariani <gi4nos...@mari ani.wswrote:
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.
It depends somewhat on the context:

-- Fundamental technological constraints (and yes, they are
still relevant today) means 80 characters, no tab characters
(and displays with fixed with fonts) are an absolute
maximum. At least for code which has to be readable over a
more or less long period of time or with different (possibly
unknown today) equipment; I'll occasionally break the rule
when I'm just experimenting, say to find out what a compiler
will do.

-- If you're posting a sample in a newsgroup, you'll want to
make is shorter; anything over something between 72 and 80
characters will get its formatting messed up, and since
follow-up postings, quoting it, will add a few characters to
the beginning, I generally try to limit it to 64 characters.
(On the other hand, like everyone else, I'll copy/paste my
code directly from the original source, so if I post actual
code from elsewhere, it is wider. And its formatting does
get messed up.)

-- If you're concerned purely about readability, look at a
newspaper column. They're sized for maximum readability.
Of English, anyway---I suspect that code follows slightly
different rules. Still, anything over about 60 characters,
*not* including indentation, will probably cause problems
for the reader. See Ian's comments with regards to finding
the start of the next line. I don't know if this is the
reason, but there have been concrete studies on this
subject. (Again, concerning native languages, not code.
And resulting in the optimal length being that of a
newspaper column. In English, anyway.)

So as a general rule: a maximum of 80 characters, total, and
between 60 and 70, without the leading indentation.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 10 '08 #12
James Kanze wrote:
What does interactive programming (whatever that means) have to
do with it?
I meant interactive text editing. With text editing programs.
Fortran restricted line width to 72 characters,
ignoring the last 8 on the card (so that you could put sequence
numbers there---very useful for resorting the code if you
accidentally dropped the deck). The reason most terminals where
80 characters per line is *because* that was the width of the
cards.
I know *why* text terminals were 80 characters wide. What I am saying
is that program source code lines have usually been restricted to 80
characters precisely because *terminals* have been 80 characters wide.
If terminals had been 100 characters wide, then 100 characters would
have been the historical limit. But terminals were not 100 characters
wide but 80 instead (because of the punch cards).

In other words, I'm saying that the 80 character line length is
because of terminals, not because of punch cards. If terminals had
always have some other width, that would have been the historical limit
for source code lines as well.
Oct 10 '08 #13
After takin' a swig o' grog, Hendrik Schober belched out
this bit o' wisdom:
Chris Ahlstrom wrote:
(But then I had never had to look at code at a machine which
only has vi. And hopefully I'll never will. :^)
What does vi have to do with it? There's GUI vi's. You can even plug
vi (vim) into Visual Studio, apparently.

--
It is only people of small moral stature who have to stand on their dignity.
Oct 10 '08 #14
After takin' a swig o' grog, James Kanze belched out
this bit o' wisdom:
So as a general rule: a maximum of 80 characters, total, and
between 60 and 70, without the leading indentation.
Check out Ch. 32 of BEAUTIFUL CODE, entitled "Code in Motion". Here's
the article it is based on:

http://www.perforce.com/perforce/papers/prettycode.html

Seven Pillars of Pretty Code

Christopher Seiwald

--
The more pretentious a corporate name, the smaller the organization. (For
instance, The Murphy Center for Codification of Human and Organizational Law,
contrasted to IBM, GM, AT&T ...)
Oct 10 '08 #15
Chris Ahlstrom wrote:
After takin' a swig o' grog, Hendrik Schober belched out
this bit o' wisdom:
>Chris Ahlstrom wrote:
(But then I had never had to look at code at a machine which
only has vi. And hopefully I'll never will. :^)

What does vi have to do with it? There's GUI vi's. You can even plug
vi (vim) into Visual Studio, apparently.
If you can do this, you're most likely not on a machine
that only has vi. (And if you are, chances are that you
won't have more than 80 chars per line.)

Schobi
Oct 10 '08 #16
On Oct 10, 11:18 am, Juha Nieminen <nos...@thanks. invalidwrote:
James Kanze wrote:
What does interactive programming (whatever that means) have
to do with it?
I meant interactive text editing. With text editing programs.
But I don't see where that really makes a difference. If I'm
editing with a card punch, I have an even more rigorous set of
constraints.
Fortran restricted line width to 72 characters, ignoring the
last 8 on the card (so that you could put sequence numbers
there---very useful for resorting the code if you
accidentally dropped the deck). The reason most terminals
where 80 characters per line is *because* that was the width
of the cards.
I know *why* text terminals were 80 characters wide. What I am
saying is that program source code lines have usually been
restricted to 80 characters precisely because *terminals* have
been 80 characters wide. If terminals had been 100 characters
wide, then 100 characters would have been the historical
limit. But terminals were not 100 characters wide but 80
instead (because of the punch cards).
In other words, I'm saying that the 80 character line length
is because of terminals, not because of punch cards. If
terminals had always have some other width, that would have
been the historical limit for source code lines as well.
But program source code lines were limited in length long before
terminals (at least those with screens) were around. As I said,
Fortran limited the length to 72 characters. I think you're
confusing cause and effect; early terminals only displayed 80
lines (except that many displayed 132---the width of most
printers at the time) because that's what the existing line
length limits were.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 10 '08 #17
On Oct 10, 10:13 am, Hendrik Schober <spamt...@gmx.d ewrote:
Chris Ahlstrom wrote:
After takin' a swig o' grog, Erik Wikström belched out
this bit o' wisdom:
[...]
(But then I had never had to look at code at a machine which
only has vi. And hopefully I'll never will. :^)
Not sure what vi has to do with it. Vi displays in whatever the
window width is. The problem is things like the size of paper,
for example (my printer won't handle much larger than A4).

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 10 '08 #18
On Oct 10, 1:42 pm, Chris Ahlstrom <lino...@bollso uth.nutwrote:
After takin' a swig o' grog, James Kanze belched out
this bit o' wisdom:
So as a general rule: a maximum of 80 characters, total, and
between 60 and 70, without the leading indentation.
Check out Ch. 32 of BEAUTIFUL CODE, entitled "Code in Motion".
Here's the article it is based on:
http://www.perforce.com/perforce/papers/prettycode.html
Seven Pillars of Pretty Code
Christopher Seiwald
Which starts well, and gets worse as it goes along, ending up
with some of the worst coding practices imaginable.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Oct 10 '08 #19
James Kanze wrote:
On Oct 10, 11:18 am, Juha Nieminen <nos...@thanks. invalidwrote:
>James Kanze wrote:
>>What does interactive programming (whatever that means) have
to do with it?
>I meant interactive text editing. With text editing programs.

But I don't see where that really makes a difference. If I'm
editing with a card punch, I have an even more rigorous set of
constraints.
Are you *reading* the cards? If you're not, how is *readability*
involved? Wasn't that the issue the OP brought forth? The cards need
to be readable, but not by a human.
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 10 '08 #20

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

Similar topics

2
1467
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
7596
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...
0
7519
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...
0
7798
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7560
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6140
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...
1
5431
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...
0
5152
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...
1
2015
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
838
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...

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.