 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Phlip Guest
|
Posted: Sun Jun 04, 2006 9:10 am Post subject: The world's evilest code formatting style |
|
|
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!!! |
|
| Back to top |
|
 |
Noah Roberts Guest
|
Posted: Sun Jun 04, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
Phlip wrote:
| Quote: | Can anyone think of an eviler style, seen in published code?
|
Yes.
http://code.axter.com/dynamic_2d_array.h
Google groups is likely to do wonders here...all of the following is on
4 concurrent lines:
dynamic_2d_array(size_t row, size_t col):m_row(row),m_col(col),
m_data((row!=0&&col!=0)?new T[row*col]:NULL){}
dynamic_2d_array(const
dynamic_2d_array&src):m_row(src.m_row),m_col(src.m_col),
m_data((src.m_row!=0&&src.m_col!=0)?new T[src.m_row*src.m_col]:NULL){
for(size_t r=0;r<m_row;++r)for(size_t c=0;c<m_col;++c) (*this)[r][c]
= src[r][c];
}
Guess he didn't want to waste any space or enter characters. |
|
| Back to top |
|
 |
Nobody Guest
|
Posted: Sun Jun 04, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
Although that sucks... its not as bad as people who "right brace"... so
called "right bracers"... ie:
void Whatever() {
for (int i = 0; i < 100; i++) {
printf("whatever\n");
}
}
Thats just dumb beyond dumb. A guy I worked with actually said he does it
like that because "putting it on the next line just wastes a line". I'm
thinking the fact that he has a brain is just a waste of precious brain
cells that others could better utilize.
"Phlip" <phlipcpp (AT) yahoo (DOT) com> wrote in message
news:_Gvgg.37948$4L1.5691 (AT) newssvr11 (DOT) news.prodigy.com...
| Quote: | 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!!!
|
|
|
| Back to top |
|
 |
Phlip Guest
|
Posted: Sun Jun 04, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
Nobody wrote:
| Quote: | Although that sucks... its not as bad as people who "right brace"... so
called "right bracers"... ie:
void Whatever() {
|
Oh, my. I was this -><- close to putting in a disclaimer "don't bring up
braces", but I figured that nobody ... would.
Everyone complains about braces, and once you are over it, you are over it,
and you can read, edit, and refactor, regardless of whatever silly bracing
convention is used.
I suppose putting most (but not all) braces in the first column might be an
exception there...
Noah Roberts cited:
| Quote: | dynamic_2d_array(size_t row, size_t col):m_row(row),m_col(col),
m_data((row!=0&&col!=0)?new T[row*col]:NULL){}
|
Now now - you may as well bust on Dinkumware's old STL style. That gets
worse when your remote colleague writes unmaintainable BASIC and crams lines
full of run-on statements with 2-letter variables "because I can get more on
the screen like that".
Let's narrow the question to a style that is A> hallowable in a style guide,
and B> a failed attempt at clarity, not a successful attempt at obscurity.
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!! |
|
| Back to top |
|
 |
Kai-Uwe Bux Guest
|
Posted: Sun Jun 04, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
Nobody wrote:
| Quote: | Although that sucks... its not as bad as people who "right brace"... so
called "right bracers"... ie:
void Whatever() {
for (int i = 0; i < 100; i++) {
printf("whatever\n");
}
}
Thats just dumb beyond dumb.
|
Dear top-poster,
care to provide a reason ...
| Quote: | A guy I worked with actually said he does it
like that because "putting it on the next line just wastes a line". I'm
thinking the fact that he has a brain is just a waste of precious brain
cells that others could better utilize.
|
.... instead of jumping to insults right away?
[mindlessly copied original post redacted]
Best
Kai-Uwe Bux |
|
| Back to top |
|
 |
Kai-Uwe Bux Guest
|
Posted: Sun Jun 04, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
Phlip wrote:
| Quote: | 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!
|
I see the importance of grepability for code. However, there will be many
contexts where it does not read Home::inherits but just inherits anyway.
Full disclosure: virtually all of my code is templated which means I ditched
the distinction of header and implementation files since implementation
files would almost always be empty anyway (given that my compiler does not
suport export). Consequently, I also ditched declaration vs. definition,
i.e., everything is defined in place so that the class::method() form just
does not occur in the code. I never found a drawback with regard to
grepability or readability of code.
Best
Kai-Uwe Bux |
|
| Back to top |
|
 |
Phlip Guest
|
Posted: Sun Jun 04, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
Kai-Uwe Bux wrote:
| Quote: | void Whatever() {
for (int i = 0; i < 100; i++) {
printf("whatever\n");
}
}
Thats just dumb beyond dumb.
care to provide a reason ...
|
Because our last best hope for clarity among nested blocks is the ability to
see { in the same column as }.
(The goal "don't write too many lines in a block" also applies. And some
namespace situations make that impossible, too...)
| Quote: | [mindlessly copied original post redacted]
|
Redaction connotes emmending, not snipping. Try "elided". ;-)
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!! |
|
| Back to top |
|
 |
Steve Pope Guest
|
Posted: Mon Jun 05, 2006 6:18 am Post subject: Re: The world's evilest code formatting style |
|
|
<Vkwgg.178431$bm6.26661@fed1read04>, Nobody <nobody (AT) cox (DOT) net> wrote:
| Quote: | ... its not as bad as people who "right brace"... so
called "right bracers"... ie:
void Whatever() {
for (int i = 0; i < 100; i++) {
printf("whatever\n");
}
}
Thats just dumb beyond dumb.
|
Certainly is. It should be:
void Whatever()
{
for (int i = 0; i < 100; i++) {
printf("whatever\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 |
|
| Back to top |
|
 |
kwikius Guest
|
Posted: Mon Jun 05, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
Phlip wrote:
| Quote: | Noah Roberts wrote:
Unit testing and TDD are not something I was taught in school or have
been mentored into. I have grabbed some books on the subject and am
delighted at how useful I am finding it. I have been thinking of
spending the 2 grand on one of the object mentor courses...especially
if I can get my employer to help. Anyone been to one?
If you are near Southern California I can save you 1 grand. ;-)
http://www.zeroplayer.com/cgi-bin/wiki?TestFirstUserInterfaces
|
Aint you one of the guys always telling everyone how O.T. they are...
:-)
regards
Andy Little |
|
| Back to top |
|
 |
I V Guest
|
Posted: Mon Jun 05, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
On Sun, 04 Jun 2006 22:25:43 -0700, Noah Roberts wrote:
| Quote: | How about this:
void f()
{
if (preconfail)
goto end;
|
....
| Quote: | 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. |
|
| Back to top |
|
 |
John L Fjellstad Guest
|
Posted: Mon Jun 05, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
"Phlip" <phlipcpp (AT) yahoo (DOT) com> writes:
| Quote: | 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 |
|
| Back to top |
|
 |
Nobody Guest
|
Posted: Mon Jun 05, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
"Steve Pope" <spope33 (AT) speedymail (DOT) org> wrote in message
news:e60icb$a06$1 (AT) blue (DOT) rahul.net...
| Quote: | Vkwgg.178431$bm6.26661@fed1read04>, Nobody <nobody (AT) cox (DOT) 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("whatever\n");
}
}
Thats just dumb beyond dumb.
Certainly is. It should be:
void Whatever()
{
for (int i = 0; i < 100; i++) {
printf("whatever\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("whatever\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("whatever\n");
}
Have a nice day you stinkin' right bracer!  |
|
| Back to top |
|
 |
Kaz Kylheku Guest
|
Posted: Sat Jun 10, 2006 9:10 am Post subject: Re: The world's evilest code formatting style |
|
|
Phlip wrote:
| Quote: | 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.
|
I have a simpler explanation. Someone blindly ran a C formatting tool
on C++ code.
There is a traditional C style in which the indentifier in a function
definition is placed at the beginning of a line. This style is used in
C++ also, but it looks like this:
void
Home::inherits(...)
{
}
Some dumb code formatting tool for C might get confused and treat the
Home and :: as part of the declaration specifier list. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|