SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


The Worst Code


The Worst Code

Author
Message
Gary Varga
Gary Varga
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27601 Visits: 6555
John Hanrahan (3/18/2014)
Well maybe close to the worst code I have ever seen was written by me. We had 16k of room to print out a large document in an old version of BASIC. I kept running out of memory space trying to print it so the code ended up with more GOTO's than sand grains in a small beach. I SWEAR there was no other way to write it but when one of the other programmers had to upgrade it to a newer version of that BASIC he was not 'happy'. I actually felt fortunate that I was his boss at the time as otherwise I would have had to upgrade the code. :-D


Love the honesty. I have written bad code. Its just that I have seen worse. That says more about them than me.

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
Eric M Russell
Eric M Russell
One Orange Chip
One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)

Group: General Forum Members
Points: 29627 Visits: 11545
Whether the worst code we've ever seen was somebody's elses or ours is not what's important. We have to own our code, just like we own the responsibility of our kids. We can examine our own stored procedure that been running "just fine" in production for years and make it run 2x faster by day's end, or we can spend forever pointing out flaws in someone elses code and accomplish nothing.


"The universe is complicated and for the most part beyond your control, but your life is only as complicated as you choose it to be."
thood1
thood1
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 44
The article is so true. I've been a developer since before the COBAL and Fortran days and long before the interactive programming days came along. But there is one thing I'll always remember from my first Programming 101 course: my instructor told us up front that coding is like making pancakes, the first program is always for throw-away! The batter's not correct, the griddle is not hot enough, etc. The dog gets the first pancake!

Unfortunately, most of our employers don't want to pay us to make the second pancake even when we learned from our first attempt exactly how to make the perfect second one.

Also unfortunately, most of us figured out that we always learned from each additional pancake flipped that there was an additional pancake that we could make that would be so much better than the last. And it is this knowledge that can frustrate the hell out of you the longer you program.
Gary Varga
Gary Varga
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27601 Visits: 6555
thood1 (3/18/2014)
The article is so true. I've been a developer since before the COBAL and Fortran days and long before the interactive programming days came along. But there is one thing I'll always remember from my first Programming 101 course: my instructor told us up front that coding is like making pancakes, the first program is always for throw-away! The batter's not correct, the griddle is not hot enough, etc. The dog gets the first pancake!

Unfortunately, most of our employers don't want to pay us to make the second pancake even when we learned from our first attempt exactly how to make the perfect second one.

Also unfortunately, most of us figured out that we always learned from each additional pancake flipped that there was an additional pancake that we could make that would be so much better than the last. And it is this knowledge that can frustrate the hell out of you the longer you program.


I never let the dog eat the first pancake...I like it!!!

What does that say about my code? Ermm

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
jarick 15608
jarick 15608
Old Hand
Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)Old Hand (338 reputation)

Group: General Forum Members
Points: 338 Visits: 485
I love the pancake analogy. It perfectly describes my first attempts. The problem I see is too many developers never throw away that first pancake but add tons of syrup and toppings to cover for the crappy pancake and in the end, you get really sick eating the thing.

Translation: to support a bad application we, as DBAs are forced to try and tune the database instance and hardware to make up for the bad code and we end up with a monster server for a solution that could have run faster on a tenth the resources.
Dave Poole
Dave Poole
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17086 Visits: 3403
My thought question: Have you ever been told that your query runs too fast?


YES. Our chief exec stood up before the entire company and said that a web site feature had had to have a delay introduced into it because the DB returned results so fast the customers didn't believe it was working:-P

LinkedIn Profile
www.simple-talk.com
thood1
thood1
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 44
Your executive was probably somewhat correct. If the normal response to activities on your inter/intranet are at one general speed then both a slow response activity AND a fast response activity are perceived by users as abnormal. You really do need to 'normalize' all activities to maintain credibility. I know this goes against the grain, but you really do have a duty to look at things from your user's point of view. And unfortunately their view is what pays the freight.
dwain.c
dwain.c
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18321 Visits: 6431
SQLRNNR (3/18/2014)
dwain.c (3/18/2014)
Oh God Steve, don't get me started!

Good editorial!


Oh please - get started Dwain ;-)


If you insist Jason. :-P Bad code can be judged on many levels (some of which previous posters have alluded to):

- Doesn't meet the functional requirements
- Generally meets the functional requirements but is riddled with defects when it reaches UAT (and/or SIT).
- Isn't fast
- Isn't pretty (Make it Work, Make it Fast, Make it Pretty)
- Is unmaintainable (for some of the reasons mentioned above)
- Is not extensible (but not too extensible so as to be developed out-of-budget)
- Doesn't have full functional coverage. For example, perhaps the development team didn't want to add a "delete transaction" button because that would have been too difficult, so instead the package comes with a support contract that allows for those cases where a delete is required but handled by "painstaking" analysis/scripting

IMHO, a lot of this comes out of two issues:
- Software engineering (a somewhat laughable term, again IMHO) has yet to achieve the level of maturity that other engineering disciplines have long ago achieved, despite 40+ years of practitioning.
- Instruction in software development, usually in a university or possibly a company specializing in training, is rarely conducted by expert software developers. "Those that can do, those that can't teach."

Now you see why I suggested you don't get me started.


My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Gary Varga
Gary Varga
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27601 Visits: 6555
thood1 (3/18/2014)
Your executive was probably somewhat correct. If the normal response to activities on your inter/intranet are at one general speed then both a slow response activity AND a fast response activity are perceived by users as abnormal. You really do need to 'normalize' all activities to maintain credibility. I know this goes against the grain, but you really do have a duty to look at things from your user's point of view. And unfortunately their view is what pays the freight.


I trust that the delay was put in the web page and NOT with the query!!!

Just in case it is uses elsewhere.

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
Eric M Russell
Eric M Russell
One Orange Chip
One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)

Group: General Forum Members
Points: 29627 Visits: 11545
David.Poole (3/18/2014)
My thought question: Have you ever been told that your query runs too fast?


YES. Our chief exec stood up before the entire company and said that a web site feature had had to have a delay introduced into it because the DB returned results so fast the customers didn't believe it was working:-P

If the response time of a data driven website is too fast, some users may abuse it by repeatedly clicking and posting-back. I'm thinking something like a live traffic, auction, or stock trading website. So, I can see the need to leverage something like javascript to delay the enabling of submit button, links, etc. to few seconds after page load.


"The universe is complicated and for the most part beyond your control, but your life is only as complicated as you choose it to be."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search