Sanding our assholes with 150 grit. Slowly. Lovingly.

How to be a better coder

Look at reallllllllly, realllllllllllly, realllllly bad code.

Good code or working code looks ok, it is formatted, there are comments you don't even notice it.

Bad code will punch in the face, you should study it and will help you appreciate writing readable, maintable code.

Imagine this code, (any language):

Embedded SQL in the code, the embedded SQL is 1000 lines of code.  There are 500 columns in the SQL (and only 20-30 columns in the various tables.  How do you come up with 500 colums = (select -1, -1, -1 ...., etc).

Also, how would access the data of 500 columns and various unions and rows.  Well, this crack pot developer gets the column data through indexes, eg.

val = row[48 * 10]

Now, imagine if somebody wants to add a new column or display a different set of data.

Since I am working with this code.  I suggested rewriting the entire app (all 400 classes).  But that is just me.
Permalink Bot Berlin 
July 26th, 2007 10:16am
You may be staring at generated (or obfuscated) code. If it is poorly (but legally) formatted, lacks comments apart from maybe a date, uses dreadful variable identifiers usw then it may be such. If so, get hold of the original coding, modify that, then feed it through the same mangle.

OTOH it could be 30000 lines of SpagBasic. Good luck.
Permalink trollop 
July 26th, 2007 10:27am
No, not generated.  And wouldnt be so bad if you had one reference.

row[ 34 * 3 ];

But brainiac decided to build this report page using a row array data structure and then build the entire report accesing the data based on hardcoded integer values.  Basically the code is beyond worthless.
Permalink Bot Berlin 
July 26th, 2007 10:32am
Gak
Permalink trollop 
July 26th, 2007 10:35am
trollop is German?
Permalink Send private email Locutus of Borg 
July 26th, 2007 10:36am
> Bad code will punch in the face

For every 4 people there are 7 opinions of what is bad code. Same for what is simple code.
Permalink son of parnas 
July 26th, 2007 10:43am
I don't think reading bad code will make you a better coder.  It will make you a bitter coder, howerver.
Permalink SaveTheHubble 
July 26th, 2007 10:45am
Betty Botter bought a bit of better butter, which made Betty Botter's bitter batter better.
Permalink Send private email JoC 
July 26th, 2007 10:56am
I like TDWTF.

I can't say specifically that I've ever gone 'nope, not doing it that way, I saw that on TDWTF'.

But I do think it helps because sometimes in the criticism of such things I have picked up tid bits I didn't know that did have smaller impacts on how I do stuff.
Permalink Send private email JoC 
July 26th, 2007 10:57am
> I am working with this code

You're screwed. You are so screwed.
Permalink man on the stair 
July 26th, 2007 11:02am
Sharp eyes there LoB, but no.
Permalink trollop 
July 26th, 2007 11:05am
It looks like report code. That's what OLAP/report code ends up looking at. Wide sql tables and mega-selects.

The only way to generate a report on how many kitchen sinks were done in time period grouped by widget X, is to stick the kitchen sink column into the table.
Permalink strawdog soubriquet 
July 26th, 2007 11:07am
But this is not about me.

How does stuff like that code get through into production? Who signed off on it? Why? When?
Permalink trollop 
July 26th, 2007 11:09am
"How does stuff like that code get through into production? Who signed off on it? Why? When?"

It is 9 year old java code, that is part of the main issue.  The question, is why don't "developers" refactor every once in a while.

I am in a shop where users are king.  Who cares about new frameworks, old, broken code.  Develoeprs do, users dont.
Permalink Bot Berlin 
July 26th, 2007 11:11am
Developers don't refactor because there is no perceived benefit to the business.

The system works, even if it is shit-encrusted under the hood.

Users, your boss, and his boss don't really care about that. If you really want to refactor, you should break it.
Permalink Send private email JoC 
July 26th, 2007 11:15am
Jumpin' Jiminy, Java is only about 10 years old itself. Time does fly.
Permalink trollop 
July 26th, 2007 11:18am
I have botlist, I am happy.  Look at it now, it is looking better?
Permalink Bot Berlin 
July 26th, 2007 11:21am
Less is more, man.
Permalink Send private email JoC 
July 26th, 2007 11:29am
It would be funny to meet a Mormon named Les.

You could tell people Les is Mormon.
Permalink Send private email JoC 
July 26th, 2007 11:30am
HERE LIES
LESTER MORE
Four slugs
From a forty-four
No Les
no more
Permalink trollop 
July 26th, 2007 11:41am
Got some code delivered from our offshore people.

It was littered with Thread.Sleep statements, with various values as a parameter that seems to have been pulled from a table of prime numbers.

Now, whenever I see Thread.Sleep, I automatically delete the line, whether I should or not.
Permalink Send private email xampl 
July 26th, 2007 12:52pm
> Now, whenever I see Thread.Sleep

It's usually a very bad sign. Sleeps mean they don't know what they are doing.
Permalink son of parnas 
July 26th, 2007 1:06pm
Wow, my is just bad code.  That code (Thread.sleep) could kill an application.

What are they trying to do?  Is that output coming in to fast or something.
Permalink Bot Berlin 
July 26th, 2007 1:37pm
Must have been from an old VB6 coder.  Old VB6 coders know you need a "DoEvents" every so often, if you want to be able to stop a runaway loop in your VB6 code.

Doing a "Sleep" every so often in Java does the same thing.  But yeah, it's kind of inept in Java code, especially if you have various 'Sleep' values put in.  That also implies they're trying to jigger the code so that multi-threaded code reaches 'rendevous' at the right time. 

The problem with that of course being that they've now optimized their code for ONE platform, running at ONE speed, with ONE mix of other code running.  VERY non-portable, in other words.
Permalink SaveTheHubble 
July 26th, 2007 2:09pm
botlist bit the dust.
Permalink Bot Berlin 
July 26th, 2007 3:16pm
>> That also implies they're trying to jigger the code so that multi-threaded code reaches 'rendevous' at the right time. <<

That was exactly it.
No thread synchronization objects in use -- just sleeps with various hard-coded values.
Permalink Send private email xampl 
July 26th, 2007 3:24pm
I am glad I missed the VB craze.  Sounds crazy.
Permalink Bot Berlin 
July 26th, 2007 4:05pm
Here is some date validation code:

if (edate!=null&&(edate.endsWith("9999")||edate.endsWith("2099")||edate.endsWith("0001")||edate.endsWith("1900")))

They are checking for invalid dates, converting the "datetime" value to a string and then checking the end of the string as opposed to using the datetime classes.  Genius I tell you.
Permalink Bot Berlin 
July 26th, 2007 4:42pm

This topic is archived. No further replies will be accepted.

Other topics: July, 2007 Other topics: July, 2007 Recent topics Recent topics