Code so ugly it makes my eyes bleed!

Started by
47 comments, last by Zefrieg 21 years, 8 months ago
Well, I picked up Core C++: A Software Engineering Approach. I must say that some of his written code is the most ugly and unnatural looking syntax I have ever seen. In fact, if I worked with a programmer who programmed like him, I would kick the person in the head. It is a good book in the fact that he explains some good programming techniques, but the way he writes code is so freaking ugly! Here is an example:
    

int main()
{
 const int NUM = 100;                               
 double total, amount data[NUM]; int count;
 char buff[20];
 total = 0.0; count = 0;
do {
 cout << "Enter amount (or 'end' to finish): ";
 cin.get(buff,20); cin.ignore(2000, '\n');
// cout << "You entered '" << buff << "'" << endl;

 if (strcmp(buff, "end")==0) break;
 amount = atof(buff);
// cout << "Amount: " << amount << endl;

 if(amount <= 0)
  cout << "This value is discarded as incorrect.\n"
       << "Please reenter it correctly.\n";
 else
  { total += amount;
    data[count] = amount;
    count++; }
  } while (1 == 1);
cout << "\nTotal of " << count << " values is "
     << total << endl;
if (count == 0) return 0;
cout << "\nTran no. Amount\n\n";
for (int i = 0; i < count; i++)
 { cout.width(4); cout << i + 1;
   cout.width(11); cout << data[i] << endl; }
 return 0;
}

    
Now I left out the right side comments, but look at that freaking do-while loop! Eww Eww Eww! This is exactly how it looks. [edited by - Zefrieg on August 14, 2002 3:36:56 AM]
Advertisement
I think I''m gonna cry seeing that....

I couldn''t write code that bad if I tried.
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
I''ve written code worse than that, although mine was deliberately bad.
damn that code is horrible

I took the red pill and here i am.
I took the red pill and here i am.
what the hell is that grotness, wouldnt want to have that stuff on my resume for a job interview LOL :D
Humm? That piece of code isn't that bad IMO - pretty damn straightforward to see what it does. The only bad things are
-(1==1) instead of (true) in the loop ( while(true){} )
-no string class but a char array
-there's an obvious memory overwrite hazard
-data[] should've been replaced with an STL container to get rid of the hazard and to simplify things (no need for 'count')
-more than one command per line
-the if() blah; else {blah;} -structure. One should always use {} when using else statements
All in all, to me it looks like traditional C code with some cout/cin in there. Those things I mentioned aren't *that* horrible like you people are saying.. So educate me. Tell me what's so horrible about that code snippet.

The indenatition is bad though, but I don't think that's what bugged you ppl the most

[edited by - civguy on August 14, 2002 5:34:19 AM]
The formatting!

It''s absolutely HORRENDOUS.

It''s almost an obfuscated C contest entry.
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
ACCU Review.

quote:Original post by civguy
Humm? That piece of code isn''t that bad IMO

There''s always one...
quote:Original post by MadKeithV
The formatting!
Ah.. I didn''t pay attention to it that much since the source tags in gamedev tend to break formatting every once in a while (especially tabs)

*hits self*
I didn''t even read the first post carefully enough to see that Zefrieg was talking about the syntax of the code (instead of semantics)..

This topic is closed to new replies.

Advertisement