473,725 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!!!
Jun 4 '06
93 3869
Noah Roberts posted:

I would really like to meet the person who knows what this code does
without having to do a double or triple take at least.

for(size_t r=0;r<m_row;++r )for(size_t c=0;c<m_col;++c ) (*this)[r][c] =
src[r][c];

I don't mean to boast, but the meaning of that line is pretty clear to
me.

For each iteration of the loop, there is an inner loop within which an
assignment is performed. I'd separate the lines and indent however:

for( size_t r = 0; r != m_row; ++r )
for( size_t c = 0; c != m_col; ++c )
(*this)[r][c] = src[r][c];

dynamic_2d_arra y(const
dynamic_2d_arra y&src):m_row(sr c.m_row),m_col( src.m_col),
m_data((src.m_r ow!=0&&src.m_co l!=0)?new T[src.m_row*src.m _col]:NULL)

I don't think any programmer in their right mind would say whitespace
is THAT scarce.

Once can become accustomed to reading code which contains the minimum
whitespace, things like:
a=b*c+4/2;

That is 148 characters, all on one line, not including
the indentation before the first character or the brace that
immediately follows.

I keep my line width below 80.
--

Frederick Gotham
Jun 9 '06 #91
Nobody posted:
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("whateve r\n");
}
}


I use next-line braces for functions, or anything which contains
executable code, e.g.:
void ArbitraryFunc()
{
do
{
/* Loop Body */
} while ( /* Condition */ );
for(;;)
{
/* Loop Body */
}

}
And line-edge braces everywhere else:
struct ArbitraryStruct {
/* Members */
};

union ArbitraryUnion {
/* Members */
};

namespace ArbitraryNamesp ace {

}
--

Frederick Gotham
Jun 9 '06 #92

Frederick Gotham wrote:
Noah Roberts posted:

I would really like to meet the person who knows what this code does
without having to do a double or triple take at least.

for(size_t r=0;r<m_row;++r )for(size_t c=0;c<m_col;++c ) (*this)[r][c] =
src[r][c];

I don't mean to boast, but the meaning of that line is pretty clear to
me.

For each iteration of the loop, there is an inner loop within which an
assignment is performed. I'd separate the lines and indent however:

for( size_t r = 0; r != m_row; ++r )
for( size_t c = 0; c != m_col; ++c )
(*this)[r][c] = src[r][c];


Yes, that makes it much more clear. The point isn't that _I_ can't
read and understand the code; the point is that it is much more
difficult to because of the piss poor coding style.

Yes, it is relatively simple code and anyone experienced can read it
but try the bug test someone else posted here in this thread and tell
us how long it took you to find the error.

Even experienced coders hate sifting through spaghetti...esp ecially
when there is no need.

Jun 9 '06 #93

Phlip 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.


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.

Jun 10 '06 #94

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

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.