473,856 Members | 1,662 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 12157
In article <48********@new s.mel.dft.com.a u>,
Gianni Mariani <gi*******@mari ani.wswrote:
>
Do you have a preference on maximum line width for C++ code?
I'll go against the grain and stay that IMO, 80 characters per line is
an outdated standard which is only useful for situations where codes
is viewed using very old technology.

By all mean, don't go wild and make 200 characters lines, but on the
other hand, I find that a hard 80 characters limit can results in too
much vertical white space which lowers readability. Vertical
scrolling is annoying too, not only horizontal scrolling.

So personally, I aim toward a soft 80-ish characters line but use
judgement to decide if the code will be clearer with an overflowing
line or a splitted line.

Typically, most lines fall under the 80 soft limit. However, some
overflow. Typically, the most common cases are:

Right hand side comments. e.g.
int angle; ///< angle in degree between .... ... (range 0..180)

(such a line clarifying something gain very little from being split
and in fact splitting them obfuscate the rest of the code because the
clarification is not something that you want to refer to most of the
time so it is good to have it less in your face)

Comments, especially doxygen ones

/// \param[in] angle ...

Function/method declaration
class Foo
{
public:
void bar(..., std::string const & logfile = DEFAULT_LOGFILE );
}

Now, there can easily be cases with foo, logfile and/or
DEFAULT_LOGFILE becoming longuer identifiers where it is almost
impossible to split that in line usefully or readably.

Function/method calls where they just about overflow the 80 chars.

templates where trying to keep everything below 80 chars while
respecting indentation might end up requiring 3-4 lines

Anyway, my contrary 2 pennies

Yannick

Oct 14 '08 #41
yt******@nyx.ny x.net (Yannick Tremblay) writes:
In article <48********@new s.mel.dft.com.a u>,
Gianni Mariani <gi*******@mari ani.wswrote:
>>
Do you have a preference on maximum line width for C++ code?

I'll go against the grain and stay that IMO, 80 characters per line is
an outdated standard which is only useful for situations where codes
is viewed using very old technology.
Of course. But how can you be sure there won't be some terrorist
attack by EMP bomb this night? Then tomorrow morning, you'll be happy
if you can still read your sources on a 132-column line printer and
type them back into your electro-mechanical computer using 80-column
punch cards.

That's why I keep all my programs in uppercase even! :-)

By all mean, don't go wild and make 200 characters lines, but on the
other hand, I find that a hard 80 characters limit can results in too
much vertical white space which lowers readability. Vertical
scrolling is annoying too, not only horizontal scrolling.
Yes. When you can keep calm your paranoid neurons, go ahead, and use the horizontal space available. Nowdays, splitting a screen
in two gives you a lot of horizontal space, even with readable fonts. As long as you don't go beyond the 132-column limit of a
line printer, I'll be OK with it.

There's also a trick to increase the available column count: use a proportional font. I know that with a lot of programming
languages I don't like that, but with the best programming languages, only the left indentation is really used most of the time,
so you can easily use a proportional font, and tuck 160 or 200 proportional characters where only 80 or 100 Courier characters
would stand.

There's also the question of the column width. It's better for the readability to use narrower columns. 80 columns is narrow
enough. If you need to typeset your code in a scientific paper, it'll be easier if you format it in 80 columns or even less.
That's a good reason why C++ templates shouldn't be used in scientific papers, lisp or haskell are better formated there. :-)

--
__Pascal Bourguignon__
Oct 14 '08 #42
James Kanze wrote:
On Oct 10, 7:51 pm, Hendrik Schober <spamt...@gmx.d ewrote:
>James Kanze wrote:

[...]
>> The problem is things like the size of paper,
for example (my printer won't handle much larger than A4).
> I can't remember the last time I printed code.

Code review.
Beamers.

Schobi
Oct 14 '08 #43
On 14 Oct 2008 12:48:31 GMT, yt******@nyx.ny x.net (Yannick Tremblay)
wrote:
>In article <48********@new s.mel.dft.com.a u>,
Gianni Mariani <gi*******@mari ani.wswrote:
>>
Do you have a preference on maximum line width for C++ code?

I'll go against the grain and stay that IMO, 80 characters per line is
an outdated standard which is only useful for situations where codes
is viewed using very old technology.
I set two markers - one at 80 and one at 132. Both are guides, not
absolutes. Both figures are obviously taken from old VT standards.

Narrow code can be useful when you need two or more listings on
screen, but there's always horizontal splitters, multiple monitors,
widescreen monitors etc.

But as you say, most lines are nowhere near 80 chars, let alone 132.
And with the few lines that do get long, there's usually vertical
alignment benefits to line-splitting anyway.

Often, very long lines mean you should be using some kind of alias or
indirection (typedef, access method, reference variable or whatever)
or perhaps a using clause. But even decluttering is about readability
rather than line length.

Oct 15 '08 #44
On Tue, 14 Oct 2008 15:23:01 +0200, pj*@informatima go.com (Pascal J.
Bourguignon) wrote:
>There's also a trick to increase the available column count: use a proportional font. I know that with a lot of programming
languages I don't like that, but with the best programming languages, only the left indentation is really used most of the time,
so you can easily use a proportional font, and tuck 160 or 200 proportional characters where only 80 or 100 Courier characters
would stand.
You use tab for indentation and vertical alignment, don't you. Come on
- confess your sins ;-)

Oct 15 '08 #45
In article <6i************ *************** *****@4ax.com>,
Stephen Horne <sh********@blu eyonder.co.ukwr ote:
>On 14 Oct 2008 12:48:31 GMT, yt******@nyx.ny x.net (Yannick Tremblay)
wrote:
>>In article <48********@new s.mel.dft.com.a u>,
Gianni Mariani <gi*******@mari ani.wswrote:
>>>
Do you have a preference on maximum line width for C++ code?

I'll go against the grain and stay that IMO, 80 characters per line is
an outdated standard which is only useful for situations where codes
is viewed using very old technology.

I set two markers - one at 80 and one at 132. Both are guides, not
absolutes. Both figures are obviously taken from old VT standards.

Narrow code can be useful when you need two or more listings on
screen, but there's always horizontal splitters, multiple monitors,
widescreen monitors etc.
Don't get me wrong. The huge majority of my code is less than 80
chars. I do appreciate narrow simple lines. Just that I dislike a
hard rule that nothing should ever be wider than 80 chars because IMO
it is outdated and results in lower readability.
>Often, very long lines mean you should be using some kind of alias or
indirection (typedef, access method, reference variable or whatever)
or perhaps a using clause. But even decluttering is about readability
rather than line length.
Indeed, the goal is readability and clarity. Very long lines tend to
be less readable. But at the same time, try reformatting the average
code as 40 chars columns. This would also make the code less
readable. IMO a hard 80 chars column also introduces readability
compromises that are undesireable (although to a much much lesser
extend).

In the same way that I think that functions should be kept shorts,
I will not put a hard rule that no function should ever be longer than
20 lines. I prefer guidelines with judgement applied.

Yannick
Oct 15 '08 #46
In article <12************ ***@irys.nyx.ne t>, yt******@nyx.ny x.net (Yannick
Tremblay) wrote:

[...]
Don't get me wrong. The huge majority of my code is less than 80
chars. I do appreciate narrow simple lines. Just that I dislike a
hard rule that nothing should ever be wider than 80 chars because IMO
it is outdated and results in lower readability.
If the huge majority of your code's lines are less than 80 characters, how
could limiting those few other lines make a big impact on readability?

[...]
But at the same time, try reformatting the average
code as 40 chars columns. This would also make the code less
readable.
And reformatting average code to 10-character lines would make it less
readable as well.
I prefer guidelines with judgement applied.
I agree; guides, not hard rules (in most cases).
Oct 15 '08 #47
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.

G
None

I will only insert an EOF character according to my own rule as follows:

1. After a semicolon
2. After the head part of conditional sentence (if, then, for, do,
while, switch, etc)
3. After {
Oct 15 '08 #48
On 15 Oct 2008 09:00:50 GMT, yt******@nyx.ny x.net (Yannick Tremblay)
wrote:
>In the same way that I think that functions should be kept shorts,
I will not put a hard rule that no function should ever be longer than
20 lines. I prefer guidelines with judgement applied.
Yes, agreed. Even a thousand line function need not be split, if it's
just a do-this-then-that sequence. Why break it up - all you do is
obscure the sequence. Unless there's a logical way to group it into
subsequences, which obviously there usually is.

That said, this is one area where my principles don't really match up
to reality. I'm terrible for growing huge functions that really need
refactoring, but never getting around to it. 99% of my functions are
still pretty small, of course, but there's some evil lurking in there
for sure.

Oct 15 '08 #49
On 15 Oct, 14:13, Michael <mich...@michae ldadmum.no-ip.orgwrote:
Gianni Mariani wrote:
Do you have a preference on maximum line width for C++ code?
<snip>
I will only insert an EOF character according to my own rule as follows:

1. After a semicolon
2. After the head part of conditional sentence (if, then, for, do,
while, switch, etc)
3. After {
and END-OF-FILE character?!

Oct 15 '08 #50

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

Similar topics

2
1482
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
11049
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10692
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10378
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
9527
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
7928
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
5956
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4568
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
2
4169
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3195
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.