Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Code so ugly it makes my eyes bleed!

This topic is 5911 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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";
  { 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]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
what the hell is that grotness, wouldnt want to have that stuff on my resume for a job interview LOL :D

Share this post

Link to post
Share on other sites
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]

Share this post

Link to post
Share on other sites
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)

Share this post

Link to post
Share on other sites
*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)..

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!