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
"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.
Jun 4 '06 #11

Noah Roberts wrote:
Kai-Uwe Bux wrote:
Phlip wrote:
Kai-Uwe Bux wrote:

>> void Whatever() {
>> for (int i = 0; i < 100; i++) {
>> printf("whateve r\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 }.
I guess whether that poses a problem depends heavily on what you are used
to. I never found any difficulty with right-bracing in regard of clarity.
But then again, my blocks are not that deeply nested anyway.


I don't see it as a "problem" but braces on the next line are more
immediately readable to me.


I think it's a waste to put braces on the next line when you only have
one line of code.
Really, that is a small issue. The real issue is that whitespace
should at least be used somewhere and code should be written to be as
readable as possible without going really insain on the idea.


I also think it's a waste to put white spaces in code for one line of
code, just because you think there should be white spaces.
IMHO, if you cann't read the following line of code without white
spaces, then maybe you should be doing something else beside
programming in C++.
inline T* operator[](size_t i) {return (m_data + (m_col*i));}

I like to be able to read as much as my code in one page as possible,
and putting useless extra lines of code, makes that harder to do.

IMHO, throughing useless whitespaces and useless extra lines of code in
your code, makes it harder to read from top to bottom, and it can be
more of a destraction, then something that adds clarrity.

Jun 4 '06 #12
Kai-Uwe Bux wrote:
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.

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.


I totally agree with this method.
And if you notice, boost also does this a lot in it's implementation.

Jun 4 '06 #13
Jim Langston wrote:
"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.


I think what is even more evil is having the code indentation mixed
improperly.

void foo()
{
for(..)
{
while(..)
{
}
}
}

IMHO, this is even more evil then not having any indentation, because
in a large block of code, any one reading this, might not imediately
realize the mis-allignment and read the code improperly.
Although this can be easily fixed with an IDE, the damage migh already
have been done, if you had to waste extra time tracking down code in
the wrong section.

Jun 4 '06 #14

Axter wrote:
I think what is even more evil is having the code indentation mixed
improperly.

void foo()
{
for(..)
{
while(..)
{
}
}
}

IMHO, this is even more evil then not having any indentation, because
in a large block of code, any one reading this, might not imediately
realize the mis-allignment and read the code improperly.


If I was working on the C++0x standard, I would require the compiler
rejects code like this :) Don't just use indentation for marking blocks
like Python, but require the indentation matches the blocks.

Jun 4 '06 #15
Azumanga wrote:
If I was working on the C++0x standard, I would require the compiler
rejects code like this :) Don't just use indentation for marking blocks
like Python, but require the indentation matches the blocks.
Two reasons this thread is beyond stupid: astyle & indent.

;-)

(Before those knees jerk, I started the thread so I'm allowed to say
that...)

Jim Langston wrote:
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.


I tried to break such lines up with astyle but can't find the option. Yet I
posit that digging up such a feature is more fun than manually reformatting.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jun 4 '06 #16
> I tried to break such lines up with astyle but can't find the option. Yet
I posit that digging up such a feature is more fun than manually
reformatting.
Oh duh, it's --break-blocks. Someone had an obsolete man page...
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!

Jun 4 '06 #17

Nobody wrote:
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");
}
}

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.


And what sort of bracer are you, a droopy bracer? Every droopy bracer I
met is a Whacko, Barking, Bonkers, Raving Buffoon!

I call them drooly slobbery bracers and I tie their shoelaces together
so they fall over.

Then they look really stupid! Ha ha!

Jun 4 '06 #18

Axter wrote:
I also think it's a waste to put white spaces in code for one line of
code, just because you think there should be white spaces.
IMHO, if you cann't read the following line of code without white
spaces, then maybe you should be doing something else beside
programming in C++.
inline T* operator[](size_t i) {return (m_data + (m_col*i));}


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 know if I would be amazed or disgusted.

Worse than that is the following one liner right above the above quoted
code:

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. That is 148 characters, all on one line, not including
the indentation before the first character or the brace that
immediately follows.

Jun 4 '06 #19
On 4 Jun 2006 07:58:48 -0700, I waved a wand and this message magically
appeared from kwikius:
And what sort of bracer are you, a droopy bracer? Every droopy bracer
I met is a Whacko, Barking, Bonkers, Raving Buffoon!


What does their code looks like, just out of interest?

For the record (so you may laugh or not) I write code like this:

void foo(int bar)
{
for (int i = 0; i < bar; i++)
{
std::cout << "Nelly the elephant ";
std::cout << "makes great apple pie\n";
}
}

--
http://www.munted.org.uk

Take a nap, it saves lives.
Jun 4 '06 #20

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.