Jump to content

Coding blunders


Geonovast

Recommended Posts

Between a thread that went off the rails a little while ago, and what I just did, for a second time, made me think we should have a thread where we share horrific coding blunders.  Terrible things caused by even the omittence of a single character.

For example, I'm working on a project for work, to integrate all of our antiquated service order, purchase orders, sales order, whatevers into one system designed specifically for us.

I was tweaking a PHP script that automatically generates a certain number of input lines, just a basic for loop.

for ($T = 1; $T <= 12; $T++) {

   // Make HTML line

}

But I needed to add a checker to do something special on just the first line, so I went put in...

for ($T = 1; $T <= 12; $T++) {

   if ($T == 1) {

      // Do special thing

   }

   // Make HTML line

}

Which is fine.  However, what I actually put in locked up Firefox, seized my entire computer, couldn't so much as Ctrl-Alt-Del, and I'm confident it could bring down an army.

for ($T = 1; $T <= 12; $T++) {

   if ($T = 1) {

      // Do special thing

   }

   // Make HTML line

}

It's amazing what using '=' instead of '==' can do.

I've now done this twice.

Whatcha got?

Link to comment
Share on other sites

7 hours ago, Geonovast said:

Whatcha got?

More than I’m allowed to ever discuss......

I was recently dealing with an issue similar to yours, except it was designed to be an infinite loop to keep a piece of software running. ... At some point that software died a grisly death [corruption by way of: voodoo, cosmic radiation,  wrong phase of moon, insert your software boogeyman of choice], with segfaults at load time.

There was no delay built in to this script, so it ran amok and ate the CPU (200% usage!?!) while crashing hundreds of times per second. To top it off, this was logged in triplicate, so our log partition very quickly filled up. Fun.

 

I wish I could tell you about some code I wrote that intentionally divides by zero, why it needs to exist, and all the hoops one has to go through in this age of child-safe-software to convince a compiler to allow you to build software that intentionally divides by zero... but I can’t. Ask me again in a hundred years or so. 

Edited by Cydonian Monk
Link to comment
Share on other sites

 

8 hours ago, Cydonian Monk said:

 

I wish I could tell you about some code I wrote that intentionally divides by zero, why it needs to exist, and all the hoops one has to go through in this age of child-safe-software to convince a compiler to allow you to build software that intentionally divides by zero... but I can’t. Ask me again in a hundred years or so. 

That sounds interesting.

Pretty much all the coding I do is various embeded devices we need for our small company. Since I'm not much of a programmer, I mostly play with Arduino stuff which has a lot of safety features built in, so what's the worst I've done in code? Probably forgot the pinMode (pin, OUTPUT), then spent hours debugging the hardware (which is also my design, so I'm thoroughly convinced that the problem is equally likely to be in either place). Not nearly as interesting as crashing an entire data center or something.

I'm much more proficient in destroying hardware, though.

Link to comment
Share on other sites

10 hours ago, Cydonian Monk said:

More than I’m allowed to ever discuss......

I was recently dealing with an issue similar to yours, except it was designed to be an infinite loop to keep a piece of software running. ... At some point that software died a grisly death [corruption by way of: voodoo, cosmic radiation,  wrong phase of moon, insert your software boogeyman of choice], with segfaults at load time.

There was no delay built in to this script, so it ran amok and ate the CPU (200% usage!?!) while crashing hundreds of times per second. To top it off, this was logged in triplicate, so our log partition very quickly filled up. Fun.

 

I wish I could tell you about some code I wrote that intentionally divides by zero, why it needs to exist, and all the hoops one has to go through in this age of child-safe-software to convince a compiler to allow you to build software that intentionally divides by zero... but I can’t. Ask me again in a hundred years or so. 

Proficient error handling, or a switch... platform would make a difference.

 

Once upon a time, had to write a software lock which left user's data intact. Client didn't want to pay the bill. I didn't like the idea, but that's what you have to do sometimes when you work for somebody else. Once paid, all went well after inserting an 'update' disc.

 

But long before that; My claim to infamy. Real-time environment; data collection, analysis, results distribution. Software predecendant to that of Monday, October 19, 1987. Correct; It wasn't entirely to blame, but I know what they did, why they did it, why it went wrong, and even commented about the potential for it years earlier. Again... when you work for somebody else..........

Link to comment
Share on other sites

1 hour ago, Joseph Kerman said:

When I forget a semicolon that I didn't see at first glance.

I had a basic C programming class a few years ago, and the IDE the class used was very unforgiving.  A forgotten semicolon at the beginning of a page could cause the IDE to give a "99+ errors.  Please improve your skills" message.  Pretty condescending for a single missing character, I thought.

Link to comment
Share on other sites

Some programmers make it a habit to always put the constant first.

If (1 = T$) will give you a syntax error, not a logical error.

Especially in a language where the assignment and equality operator are the same (I’m looking at you, Visual Basic), it’s a healthy habit.

Link to comment
Share on other sites

1 minute ago, Kerbart said:

Some programmers make it a habit to always put the constant first.

If (1 = T$) will give you a syntax error, not a logical error.

Especially in a language where the assignment and equality operator are the same (I’m looking at you, Visual Basic), it’s a healthy habit.

I would have just been happy with any kind of error.  Instead I got a webpage creating an infinite amount of table rows.

I do like that though.  I may have to start doing that.

Link to comment
Share on other sites

3 hours ago, Geonovast said:

I would have just been happy with any kind of error.  Instead I got a webpage creating an infinite amount of table rows.

I do like that though.  I may have to start doing that.

Syntax error: your program goes boom

Logical error: your program runs “fine,” it’s just not doing what you wanted it to do. In your case you had a logical error. Syntax errors are always better!

Write your code as if it will be debugged by a homicidal psychopath who knows where you live” is another piece of advice I give everyone.

Link to comment
Share on other sites

12 minutes ago, Kerbart said:

Write your code as if it will be debugged by a homicidal psychopath who knows where you live

That is colorful to say the least. But probably good advice!

Why would a homicidal psychopath try to kill me though for some code?

Link to comment
Share on other sites

55 minutes ago, qzgy said:

Why would a homicidal psychopath try to kill me though for some code?

Because there's code that's written so, so badly... Bad variable names, bad comments, bad structure. All of the above. Don't be that person! :)

Here's another gem I was taught a long time ago:

It's hard to read your own code, it's impossible to read code written by someone else. And after six months, your code looks like it was written by someone else.

 

Link to comment
Share on other sites

12 minutes ago, Kerbart said:

Because there's code that's written so, so badly... Bad variable names, bad comments, bad structure. All of the above. Don't be that person! :)

Here's another gem I was taught a long time ago:

It's hard to read your own code, it's impossible to read code written by someone else. And after six months, your code looks like it was written by someone else.

 

And thats why comments exist.

Link to comment
Share on other sites

11 minutes ago, Geonovast said:

Well... if you use them.

And if they're meaningful.

stuff = do_stuff_and_return_it();
// multiply stuff with x and y
stuff = stuff * x;
stuff = stuff * y;
// double stuff five times
for(int i = 0; i<5; i++) {
    stuff = stuff * 2;
}

While this is not literally code I've encountered, I've seen plenty of lines comparable to this in my life. Mysterious variable names, and extensively commented... with absolutely useless comments. That's where the homicidal psychopath comes in.

Link to comment
Share on other sites

4 hours ago, Kerbart said:

Mysterious variable names, and extensively commented... with absolutely useless comments.

It's called code for a reason. If it's hard to write, it should be hard to decipher.

 

4 hours ago, Kerbart said:

And after six months, your code looks like it was written by someone else.

On more than one occasion:
"What is this?  What was this guy thinking?  What kind of imbecile would try to get something like that to work?!?"

"Oh, wait.  That was my code.  Well, at least I know it works."

Edited by razark
Link to comment
Share on other sites

Simple shell script to clean out a set of directories every night.

It went something like this:

for d in $dirs; do

    rm -fr $d/ *

done

Yup.  You guessed it.  This was run by cron every night.  Next morning, computer was dead, totally unresponsive, looking at the dusk showed no files.  That darned extra space deleted everything on the disk.

We didn't realize what happened, so we restored from backups, re installed the SAME script.  Next day, same thing, and that's when we realized what was going on.  The script had passed a code review as well, no one caught it.

That was a looonnngggg time ago

Edited by linuxgurugamer
Link to comment
Share on other sites

18 minutes ago, linuxgurugamer said:

That darned extra space deleted everything on the disk.

I missed the space, but the thought of what would happen if $d ended up being parsed to a blank space gave me chills.

Link to comment
Share on other sites

14 hours ago, Kerbart said:

It's hard to read your own code, it's impossible to read code written by someone else. And after six months, your code looks like it was written by someone else.

Truer words have never been spoken.

 

I once knew and worked with a guy who named all of his variables after farm animals. Try reading through something like that for an afternoon sometime. :confused:

Link to comment
Share on other sites

23 hours ago, Kerbart said:

Some programmers make it a habit to always put the constant first.

If (1 = T$) will give you a syntax error, not a logical error.

Which violates another programming rule: "no magic constants".

And anyway doesn't work with two variables.

P.S.
Similar problem: stupid compiler doesn't understand that
if (a = b) ...
is not an error, it's a laconism. You assign b to a and check if it's not zero.

P.P.S.
Infinite loops usually caused browser hanging but yet didn't put down a whole system on my side.

Edited by kerbiloid
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...