FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Bloated code...

   
Author Topic: Bloated code...
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
Whew. So I'm looking at some code written by one of my colleagues, and boy does it have cruft. Quite apart from stylistic issues like "if(somePointer!=0)" and "if(someBool==true)", he repeats code all over the place. Which tends to happen when you're building functionality incrementally, sure; but still, I just reduced the code from 1600 lines to 700 by abstracting out things, for the same functionality. Not to mention removing his really horrible memory leaks, made twice as bad by the liberal use of a 'square' macro. (He was actually creating an object, quite a large one in fact, inside a square macro, so that he could call a single function from it and square the result... and then failing to clean up the objects! Granted, the 'new' is hidden since it's other people's code, but still, "you get ownership of the result of a create call" is one of the first things you ought to learn.) Then there was the function he'd taken over from me back in the day, which did this:

code:
OurStorageClass* pointerForThisFunction;
if (doingOneThing)
pointerForThisFunction = &storageForOneThing;
else
pointerForThisFunction = &storageForOtherThing;

(...)

pointerForThisFunction->doStorageThings(someData);

which is very reasonable indirection when you have three or four different Things, and ten or so pointers. It's not quite so reasonable when you're only doing one Thing. In fact, it's totally pointless and confusing!

Sheesh. It's enough to make you ponder the advantages of brain****. You'd still be tearing your hair out, but at least you'd know that the language is designed for it.

Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Mike
Member
Member # 55

 - posted      Profile for Mike   Email Mike         Edit/Delete Post 
I prefer malbolge for this sort of thing.
Posts: 1810 | Registered: Jan 1999  |  IP: Logged | Report this post to a Moderator
B34N
Member
Member # 9597

 - posted      Profile for B34N   Email B34N         Edit/Delete Post 
What language is it. I have to use the same code over sometimes in the same project when I code in ActionScript but then again I'm not a programmer, just a designer who has to program to be effect in the industry.
Posts: 871 | Registered: Jul 2006  |  IP: Logged | Report this post to a Moderator
Nighthawk
Member
Member # 4176

 - posted      Profile for Nighthawk   Email Nighthawk         Edit/Delete Post 
When I began work on Canvas 6 by Deneba Software, I was given complete jurisdiction over the entire printing engine with only one rule: "make it work."

The printing engine, in some places, looked like it was written by a chimpanzee. After a solid nine months or so, I have to say I'd probably rewritten 90% of the code, leaving the remaining 10% only because it miraculously worked and wasn't documented well enough anywhere to reproduce (things like font parsing and rendering, low level PostScript, etc... stuff that one can't even research adequately).

I've found that, in situations like this, it's most of the time more cost and time effective to simply can it all and rewrite it from scratch. But that's a really hard thing to sell to upper management; although the end result might be achieved faster and cheaper, it doesn't make logical sense to them. As far as they know, most of the work is done already, right? What's the problem?

Posts: 3486 | Registered: Sep 2002  |  IP: Logged | Report this post to a Moderator
Will B
Member
Member # 7931

 - posted      Profile for Will B   Email Will B         Edit/Delete Post 
I completely relate. I just spent some 32 hours adapting code for loading and displaying a 3D model so it could work with mine. The reason it took so long is that almost everything was global; things that had nothing to do with each other would be done in the same function; there would be pointers used for no particular reason.

Argh!

But I'm not really unhappy, because it's done now!

Posts: 1877 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
Xavier
Member
Member # 405

 - posted      Profile for Xavier   Email Xavier         Edit/Delete Post 
I used to program with a guy who called his variables things like "a" and "b". That crap is fine as a loop index, but not when the variable is really secondaryInterestRate or something which people need to use.

But trust me KoM, you've seen nothing yet [Smile] .

One of my tasks this past few weeks has been to read hundreds of thousands of lines of Java code written by old COBOL programmers, and try to determine what in the heck they were trying to do. I've had to sift through if/else's that had the first 'else if' about 5,000 lines below the 'if', and then the next 'else if' thousands of lines before that. Inside each of those monster blocks of code are more complicated looping and flow control statements. It's like they thought they had to limit their programs to one method.

Oh and they are in love with Strings for some reason!

They will use them as booleans:

String isWhatever = "false";
...
if(isWhatever.equals("true")){
...
}

And they will use them in their objects for everything! They will take a double, make it into a String to store in their objects, and then turn it back into a double when they need it again.

No comments anywhere! Or wait, there are comments, but they are questions!

//TODO: Should I be calculating this value this way?

I don't know buddy, should you have been? Perhaps you should have asked? Maybe you could give a clue as to what you were trying to calculate, so that perhaps I could ask someone? This is a 4 million dollar piece of software which processes millions of dollars, and you guessed what the correct calculation was?

The thing is, I'm actually very good at it analyzing other people's code, I just hate to do it. I like to get my code to sparkle, and I am intolerant of lazy/incompetent coding by others.

The problem is, good software engineers are not easy to find, and being a great coder is probably less than half of what it takes to be a great software engineer. It's easy to lose perspective on that in this field.

Posts: 5656 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
Nighthawk
Member
Member # 4176

 - posted      Profile for Nighthawk   Email Nighthawk         Edit/Delete Post 
Another hilight of my job...

One of the owners was a programmer and notoriously bad speller; he was responsible for the text engine among other things.

Some things of note:

1) He was a copy and paste fanatic. He'd rather copy and paste three characters than have to type them over and over again.

Now, think about that when the person can't spell a damn. One thing of note was a define called "BEZIER". He spelt it once "BEIZER", but because of his copy and paste craze it was misspelled across fifty files in a thousand places.

Every time I ran across it, I'd fix it and things would break. So much so that, at the top of every file, I had to add the lines:

#undef BEIZER
#define BEIZER BEZIER

...and problem solved.

2) He insisted on absurdly long function names and function bodies. One function, the core text rendering function, was literally ELEVEN THOUSAND lines long. That's ONE function, people! When you compile the entire program (all eleven million lines of code), you can literally see the compiler pause on that one file while it tries to figure out what to do with it.

And, again, with his copy and paste... he'd create a loop or some other process, and if he had to use the process further down he'd just copy it. Rather than create an external function, the loop would exist fifteen places in the same function.

3) He created a function, I'm not making this up, that was defined as:

bool WordIsReallyMispeellled( char *str );

Posts: 3486 | Registered: Sep 2002  |  IP: Logged | Report this post to a Moderator
Xavier
Member
Member # 405

 - posted      Profile for Xavier   Email Xavier         Edit/Delete Post 
Nighthawk, I found a method today that was easily 2,000 lines. What was it? A huge set of if/else blocks, with the EXACT SAME SIX LINES OF CODE INSIDE EACH BLOCK.

My mind was blown. I couldn't believe it at first [Big Grin] .

The best I could hope for was that the dude copied the code over and over again as place-holders, and was planning on making the code actually different for each case and never got around to it.

Posts: 5656 | Registered: Oct 1999  |  IP: Logged | Report this post to a Moderator
MrSquicky
Member
Member # 1802

 - posted      Profile for MrSquicky   Email MrSquicky         Edit/Delete Post 
I once redesigned a company's internal website, starting with taking all 1100 or so individual pages that were stored all in the same directory with names like "humanresourcesbenefitcalculationmedicalinsurancesecondform.html" and putting them into a hierarchical folder structure.
Posts: 10177 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
Tstorm
Member
Member # 1871

 - posted      Profile for Tstorm   Email Tstorm         Edit/Delete Post 
In the process of figuring out what the previous developer left me...I keep coming across old functions and code. Apparently, my predecessor was a huge copy and paste fanatic. He found code online, copied it, and pasted into our webpage. After some tinkering, he made it work.

At any rate, apparently he knew enough to keep things working fairly well. I'm grateful for the documentation he left behind.

I've enjoyed his prolific use of the pointers and variables "foo" and "bar". Though it's kinda difficult to determine what they do at first, it's been a source of humor for me.

Posts: 1813 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
TomDavidson
Member
Member # 124

 - posted      Profile for TomDavidson   Email TomDavidson         Edit/Delete Post 
You know, I've been tapped as a programmer recently by our college despite having no formal training and actually very little coding experience; basically, I'm a systems admin who picked up a little VBScript and Perl in order to automate some server processes who -- because I couldn't convince people that I didn't know what I was doing -- is now being forced to rewrite our ERP as a C#/.NET application.

*shudder* And yet, as often as I feel like I'm reinventing the wheel, I hear horror stories like this and think, "Okay, maybe I'm not quite so incompetent."

Posts: 37449 | Registered: May 1999  |  IP: Logged | Report this post to a Moderator
Nighthawk
Member
Member # 4176

 - posted      Profile for Nighthawk   Email Nighthawk         Edit/Delete Post 
I keep remembering horror stories...

Another popular function was a function to convert C-compatible strings (zero terminated) to Mac-friendly "Pascal" strings (first byte is length, followed by data).

The function was six or seven lines long, but everyone needed it sooner or later. So, rather than reference the function globally from one location, each programmer had the habit of copying this little itty bitty function in to the top of their source file(s).

So the "ctop_string" and "ptoc_string" function existed, identically, in a good four or five hundred source files in the entire codebase. It got so bad that you eventually *had* to put it in your source file because, if you tried to access it via "extern", the compiler didn't know which of the five hundred versions of it you might want; you had to define it within your file as "static".

Posts: 3486 | Registered: Sep 2002  |  IP: Logged | Report this post to a Moderator
King of Men
Member
Member # 6684

 - posted      Profile for King of Men   Email King of Men         Edit/Delete Post 
On the subject of comments : It's fine to tell us that your ellipse class may be rotated by the angle theta. That's good to know, although perhaps it might have been clearer if you just gave the parameter a descriptive name, like, y'know, rotationAngle. Then you could have spent your obviously limited comment-writing time informing us whether the angle is to be given in degrees or radians! [Mad] [Wall Bash]
Posts: 10645 | Registered: Jul 2004  |  IP: Logged | Report this post to a Moderator
Swampjedi
Member
Member # 7374

 - posted      Profile for Swampjedi   Email Swampjedi         Edit/Delete Post 
There are function calls in the AF mission data tool that I maintain that go 20 levels deep, and then return 0 all the way back up (due to removed functionality).

Then we have Fortran where people will use i from 1..N for an index and then reference it as (i-1). Gah.

Of course, we have the several hundred statement if blocks.

But you know, the worst are the goto statements. Especially when they're chained.

Posts: 1069 | Registered: Feb 2005  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2