C++ers:
Feast your eyes:
void Home::
inherits (IdentifierPtr const& id)
{
...
}
For those of you who haven't figured it out yet, that's the method
Home::inherits( ).
I suppose the theory is that Home:: is an enclosing type, so it should
pretend to wrap the method, like a namespace.
Now that's not evil just because it's so contrary to common styles and hence
hard to read. It's totally evil when it makes Home::inherits impossible to
search for. Searching, for big projects, is kind'a important!
Can anyone think of an eviler style, seen in published code? ;-)
--
Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jun 4 '06
93 3901
Ron House wrote: for (int i = 0; i < 100; i++) { printf("whateve r\n"); }
But of course, no one does, precisely because of two wasted lines. That matters: too low an information density on a screen or page lowers comprehension in the same way as too high a density.
This is precicely what I do with one liners (except the braces go
either on the first column or have one indent and the code another).
I've never seen any case where this actually lowers readability.
Ron House wrote: Only if you are in the habit of inconsistency in using braces.
I'm sorry, but despite you have taught classes, you seem to have avoided
teaching me exactly what style you are talking about.
Please just write your favorite kind of if{} block here, without lectures or
alternatives. I promise not to bust on it.
--
Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
"Jim Langston" <ta*******@rock etmail.com> wrote in message
news:Iw******** *******@fe03.lg a... "Phlip" <ph******@yahoo .com> wrote in message news:_G******** **********@news svr11.news.prod igy.com... C++ers:
Feast your eyes:
void Home:: inherits (IdentifierPtr const& id) { ... }
For those of you who haven't figured it out yet, that's the method Home::inherits( ).
I suppose the theory is that Home:: is an enclosing type, so it should pretend to wrap the method, like a namespace.
Now that's not evil just because it's so contrary to common styles and hence hard to read. It's totally evil when it makes Home::inherits impossible to search for. Searching, for big projects, is kind'a important!
Can anyone think of an eviler style, seen in published code? ;-)
I have two, one easy to fix.
Some code I work with has no indentation whatsoever, everything is left justified. This is easy enough to fix in my IDE though, I just select everthing and hit a few keys to auto indent. Takes me a few seconds.
The second is code someone has me work with sometimes. Not only does it not have any indents, it has absolutely no whitespace, and many statements on one line. This takes a while to format so I can read it.
Oh, I forgot about something else this 2nd person does. He puts functions
in .h files. So he only has one .cpp file and everything else is included
in .h including functions, etc... Very bad, but I couldn't convince him of
that.
In article <_G************ ******@newssvr1 1.news.prodigy. com>,
Phlip <ph******@yahoo .com> wrote: C++ers:
Feast your eyes:
void Home:: inherits (IdentifierPtr const& id) { ... }
For those of you who haven't figured it out yet, that's the method Home::inherits ().
I suppose the theory is that Home:: is an enclosing type, so it should pretend to wrap the method, like a namespace.
In the original for the above code snippet, was there white space
at the beginning of each line, or were the lines (particularly
the one starting with "inherits") unindented?
If the latter, it is probably a continuation of an old C
formatting style wherein the definitions of each function
had the function name always the beginning of a line. This
makes it easy to find the function definition (as opposed
to function calls) with a text editor search.
Such formatting is obsolesced by modern tools, but was useful
in its day, and I used it myself (when working in C) up to about
five years ago.
Steve
Steve Pope wrote: If the latter, it is probably a continuation of an old C formatting style wherein the definitions of each function had the function name always the beginning of a line. This makes it easy to find the function definition (as opposed to function calls) with a text editor search.
My favorite:
void
kozmik()
{
}
That is beyond reproach. It puts the most important thing in the first
column, and the lessor thing.
Now replace 'void' with some huge type from hell, and that style gets even
better.
Such formatting is obsolesced by modern tools, but was useful in its day, and I used it myself (when working in C) up to about five years ago.
void
Foo::kozmik()
{
}
But the code I got that sample from was post-modern. It used Boost::Spirit,
and it used multiply nested namespaces. I'm beginning to think most of those
things are nothing but cures in search of diseases...
--
Phlip http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Phlip wrote: Steve Pope wrote:
If the latter, it is probably a continuation of an old C formatting style wherein the definitions of each function had the function name always the beginning of a line. This makes it easy to find the function definition (as opposed to function calls) with a text editor search.
My favorite:
void kozmik() { }
That is beyond reproach. It puts the most important thing in the first column, and the lessor thing.
How about this:
void f()
{
if (preconfail)
goto end;
while (something)
{
... do stuff
if (whatever)
goto end;
}
if (more stuff)
{
do X;
}
else
{
goto end;
}
end:
return;
}
Yes, I in fact ran into that in the REAL world.
<Vkwgg.178431$b m6.26661@fed1re ad04>, Nobody <no****@cox.net > wrote: ... its not as bad as people who "right brace"... so called "right bracers"... ie:
void Whatever() { for (int i = 0; i < 100; i++) { printf("whateve r\n"); } }
Thats just dumb beyond dumb.
Certainly is. It should be:
void Whatever()
{
for (int i = 0; i < 100; i++) {
printf("whateve r\n");
}
}
The idea is that to find the left brace for a given right
brace, go upwards until you find a line less indented than
the right brace.
The exception being the braces for the function itself,
which are both un-indented.
(Not that there aren't many other acceptable ways of
doing it...)
Steve
"Phlip" <ph******@yahoo .com> writes: John L Fjellstad wrote:
The other issue that always comes up in C styling is the placement of braces. Unlike the indent size, there are few technical reasons to choose one placement strategy over the other, but the preferred way, as shown to us by the prophets Kernighan and Ritchie, is to put the opening brace last on the line, and put the closing brace first, thusly:
if (x is true) { we do y }
That's not "preferred" - it's an artifact of writing a book. The "rationale" is only to save vertical space and make room for your wondrous prose.
Then why, for functions, they put brackets on a new line. If it was just to
save vertical space, why not be consistent?
And what's wrong with saving vertical space again?
--
John L. Fjellstad
web: http://www.fjellstad.org/ Quis custodiet ipsos custodes
Replace YEAR with current four digit year
On Sun, 04 Jun 2006 22:25:43 -0700, Noah Roberts wrote: How about this:
void f() { if (preconfail) goto end;
....
end: return; }
Yes, I in fact ran into that in the REAL world.
Well, everyone knows that structured code should only have one return
statement. If you have to use gotos to make sure you have structured
code, that's a sacrifice you'll just have to make.
"Steve Pope" <sp*****@speedy mail.org> wrote in message
news:e6******** **@blue.rahul.n et... <Vkwgg.178431$b m6.26661@fed1re ad04>, Nobody <no****@cox.net > wrote:
... its not as bad as people who "right brace"... so called "right bracers"... ie:
void Whatever() { for (int i = 0; i < 100; i++) { printf("whateve r\n"); } }
Thats just dumb beyond dumb.
Certainly is. It should be:
void Whatever() { for (int i = 0; i < 100; i++) { printf("whateve r\n"); } }
The idea is that to find the left brace for a given right brace, go upwards until you find a line less indented than the right brace.
The exception being the braces for the function itself, which are both un-indented.
(Not that there aren't many other acceptable ways of doing it...)
Steve
Thats even stupider... not only are you being inconsistent in your use of
braces... but your comment of "look at the indents to find the matching
brace" smells of .... well... lets be nice... but thats dumb... why would
you look at indents to match a brace when you could look at the MATCHING GOD
DAMN BRACE?!?!?!
Correct formatting is:
void Whatever()
{
for (int i = 0; i < 100; i++)
{
printf("whateve r\n");
}
}
And technically, its impolite to brace single lines (single SOURCE lines,
not single code lines... ie... if your single line of source wraps multiple
lines, it should be braced), but in the above case... CORRECT & POLITE
formatting is:
void Whatever()
{
for (int i = 0; i < 100; i++)
printf("whateve r\n");
}
Have a nice day you stinkin' right bracer! :) This thread has been closed and replies have been disabled. Please start a new discussion. |