473,785 Members | 2,326 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 3904
> coders with "poor reading skills", the average coder takes more pride
in their work and in making sure they can be understood. Otherwise we


No, actually, most coders (including myself) don't give a bucket of canadian
moose piss about that and only care that they can maintain the code (to
protect their jobs in times of layoff). Being "the only one who can rapidly
work on this code" saved my ass in the last round of layoffs at my company
and the CEO himself even told me so himself. Its not that I write poor code,
in fact, I take time to VERY nicely format and comment code... when its
something *I* care about... like my personal projects. Going hogwild with
stylization and comments and formatting at work? Why bother? Selfish
attitude? of course... same attitude as every company has towards its
employees. Am I still employed while more concientious workers were let go?
Yup...

And anyone here who tells me they dont have this attitude is full of it...
someone at my work who EVERYBODY there considers the most concientious
worker recently confessed to me that he just gives that appereance, but
doesn't give a crap about the company or the product as long as he is
working on something interesting...
Jun 5 '06 #41

"Noah Roberts" <ro**********@g mail.com> wrote in message
news:11******** ************@g1 0g2000cwb.googl egroups.com...

Nobody wrote:
> I recommend you spend more time improving your code reading skills, and
> less time complaining about other programmer's code format.


Thats just dumb... I shouldn't need to "read" your code or spend a few
minutes analyzing what it does... I should be able to easily tell what it
does just by looking at it or having it clearly commented.


Personally I feel comments should be rarely required. Your code should
be self documenting and easily understood.

Granted, certain special cases make that difficult and the concepts
will need to be explained...but really, it is rather rare that you get
to do anything 'difficult' with code so most of the time comments
should be redundant.


True... I don't comment every line, and am definitely guilty of using
useless comments as a code formatting crutch... even in my personal comments
I have code like

// clear the menu flags

pDLL->bMenuFlag = FALSE;

// do something else

.....

While everybody in this thread will think thats an insanely dumb comment
(and it is)... it allows me to format the code to my liking.
Jun 5 '06 #42

Axter wrote:
I'm the second highest ranking Expert in the C++ topic area for the
Experts-Exchange:
http://www.experts-exchange.com/Cplusplus
The Experts-Exchange is a well know controlled forum. (User name Axter)


Oh jeesh...here we go again.

Ok, Mr. Expert...you have no excuse for sending people to that hackery
you call code in dynamic_2d_arra y then. I then have to assume you are
doing it to purposfully mislead those that are trying to learn C++.

'Cause that crap is crap. No two ways about it. It's riddled with bad
design, bad practice, and basic bugs. These numerous problems have
been pointed out to you several times and you've had plenty of time to
fix it (in fact you had time to make it worse) yet you continue to use
it as an example and hand it off to beginners trying to learn.

Frankly, the fact that a bunch of the poor suckers actually think
you've helped them is sad to say the least.

You know, I have also been published many times. My articles have been
translated to numerous languages including Chinese. But that is
completely irrelivant to whether I know wtf I'm talking about and it is
no different with you. Frankly, it doesn't take much to be published
anymore...espec ially on some free help website.

How is someone supposed to take you seriously when you call code like
your d2 array 'examples'? I've looked at your smart pointer a small
amount and it didn't show the basic flaws your d2 array does...I didn't
review it all but it definately isn't something I could chew up and
spit out like your d2 array...but you don't seem to be handing that one
out saying, "Here, this is how it is done." What you _are_ handing out
is just garbage and I for one hate seeing it being used for teaching
beginners....fi x it already....stop giving out bad advice.

Jun 5 '06 #43

Ian Collins wrote:
Nobody wrote:
I recommend you spend more time improving your code reading skills, and
less time complaining about other programmer's code format.

Thats just dumb... I shouldn't need to "read" your code or spend a few
minutes analyzing what it does... I should be able to easily tell what it
does just by looking at it or having it clearly commented.

Better yet, just read thought the unit tests.


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...espec ially
if I can get my employer to help. Anyone been to one?

Jun 5 '06 #44
Noah Roberts wrote:
Ian Collins wrote:
Nobody wrote:
I recommend you spend more time improving your code reading skills, and
less time complaining about other programmer's code format.
Thats just dumb... I shouldn't need to "read" your code or spend a few
minutes analyzing what it does... I should be able to easily tell what it
does just by looking at it or having it clearly commented.


Better yet, just read thought the unit tests.

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...espec ially
if I can get my employer to help. Anyone been to one?

Good to see someone with an open mind.

I don't have any experience with Object Mentor, but they do have a good
reputation.

Try asking on one of the XP or TDD yahoo lists.

Good luck,

--
Ian Collins.
Jun 5 '06 #45

Ian Collins wrote:
Noah Roberts wrote:
Ian Collins wrote:
Nobody wrote:

>I recommend you spend more time improving your code reading skills, and
>less time complaining about other programmer's code format.
Thats just dumb... I shouldn't need to "read" your code or spend a few
minutes analyzing what it does... I should be able to easily tell what it
does just by looking at it or having it clearly commented.
Better yet, just read thought the unit tests.

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...espec ially
if I can get my employer to help. Anyone been to one?

Good to see someone with an open mind


Yes well, I learned long ago that a closed mind is malfunctional and
try to remain as open as I can. Besides, it's hard to argue with
success.
I don't have any experience with Object Mentor, but they do have a good
reputation.


They certainly write good books.

Actually, I was conversing with them on Friday before I went home for
the weekend. If I could get 10 people in my area interested I could
probably get them up here and in a classroom. I'm in Lacey, WA. I get
the 10 I get my ride for free but would likely end up spending it on
the venue.

I'm interested in their TDD course that includes unit testing and
refactoring. It's 3 days and costs 2 grand. Anyone else interested?
Can't promise anything but if I can get enough people saying they want
to go that will in fact sign up I would be more than happy to continue
trying to get it happening.

Jun 5 '06 #46
Nobody wrote:
coders with "poor reading skills", the average coder takes more pride
in their work and in making sure they can be understood. Otherwise we
No, actually, most coders (including myself) don't give a bucket of
canadian moose piss about that and only care that they can maintain the
code (to protect their jobs in times of layoff). Being "the only one who
can rapidly work on this code" saved my ass in the last round of layoffs
at my company and the CEO himself even told me so himself.


Let me get this straight. The company rewarded heroism by dismissing the
team and keeping the hero. And now the boss's boss knows his next target.

Your only hope here is to make sure your bosses never learn that code can be
easily shared among programmers, particularily if it has short methods and
extensive unit tests.

Start at the top and work your way to the bottom of this checklist.

http://c2.com/cgi/wiki?JobSecurity
Its not that I write poor code, in fact, I take time to VERY nicely format
and comment code...


Ah, so it has short lines and methods, very little duplication, and eeeeunit
tests?

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jun 5 '06 #47
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...espec ially
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/wi...UserInterfaces

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jun 5 '06 #48
Nobody wrote:
// clear the menu flags

pDLL->bMenuFlag = FALSE;

// do something else


Comments suck.

<a beat>

<vbgdrc*>

--
Phlip
* very big grin; duck and run for cover
Jun 5 '06 #49
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 }.


Only if you are in the habit of inconsistency in using braces.

The source of this style, afaik, was a paper by AJ Sale proposing a
similar style for Pascal. The reason is to align the block structure of
the language's logical structure with the line-oriented layout of a text
document. Each language structure looks like:

starting template
...indented contents...
ending template.

So, your starting template is:

for (...;...;...) {

All of it is compulsory because it is a cookie-cutter template. That
means no 'naked' statements inside loops unprotected by curlies. To take
your example, another style might write:

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. So people write:

for (int i = 0; i < 100; i++)
printf("whateve r\n");

Then they remember they forgot a line, so they insert it:

for (int i = 0; i < 100; i++)
k = 2;
printf("whateve r\n");

and then they have a bug. I have used Sale's style, adapted for C and
C++, for decades, taught it to classes, and seen with my own eyes how it
lowers the bug level. It puts a good information density on a page,
aligns block structure with line structure, and allows spotting errors a
line at a time. Any line starting with 'for' and not ending with '{' is
wrong.

--
Ron House ho***@usq.edu.a u
http://www.sci.usq.edu.au/staff/house
Jun 5 '06 #50

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.