It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
This can be an entire OS or system architecture, a particular snippet of FORTRAN, or whatever else have you.

However, there are some rules here.

1. Not your own code.

2. You have to explain WHY it is bad. Not, 'Haha Windows 95 eats babies'.

3. It can't be code that is bad on purpose. So no befunge, INTERCAL, or Chef.

I'm sure GOGdlyites have come across some impressively bad machining. :V
I would go with Wizardry 1's (MA)HAMAN routine.

Here is how the code looks like when reverse engineered:

:1 110 CASE RANDOM MOD 3 * MAHAMFLG OF (* MAHAMFLG IS 6 OR 7 *)
:1 121 0, 1, 2, 3, 4, 5: HAMCURE; (* 1? 2? 3? 4? 5? *
:1 125 7, 8, 9, 10, 11: HAMSILEN; (* 8? 9? 10? 11? *
:1 129 12, 13, 22, 23: HAMMAGIC; (* 13?, 22?, 23? *
:1 133 14, 20, 21: HAMTELEP; (* 14?, 20? *
:1 137 6, 15, 19: HAMHEAL; (* 15?, 19? *
:1 141 17: HAMPROT; (* 17? DEAD COD
:1 145 16, 18: HAMALIVE; (* 16?, 18? DEAD COD
:1 149
:1 149 (* MAYBE THEY WANTED "RANDOM MOD (3 * MAHAMFLG)",
:1 149 AND MAHAMFLG = 6 OR 8 DEPENDING ON SPELL *)

Basically, it reduces the number mod 3 and then multiplies by 6 or 7, depending on which spell is cast. Therefore, the only possible results are 0, 6, 12 (for HAMAN) or 0, 7, 14 (for MAHAMAN). As a result, two of the effects can't happen.

Another example of code I hear is bad is SaGa 1's combat routine, which contains a bunch of ridiculous bugs (things like, blindness halves your agility, except when a basic STR-based attack is used, in which cast not being blind halves your agility) as well as one of the worst PRNGs I've encountered in a video game. (Luck manipulation is easy in this game even without emulator tools; I have seen a run on an actual Game Boy that used heavy luck manipulation.)

As for an example I encountered, while in college I was helping somebody else with homework, and like many homework assignments, the student was instructed not to modify a certain part of the code. Said part of the code contained a call to the gets() function. To quote the Linux manpage, "Never use this function" (underlined for emphasis). From FreeBSD's manpage, "The gets() function cannot be used securely." From OpenBSD 4.6 manpage, "...programs should NEVER use gets().". OpenBSD 5.6's release announcement has "gets(3) has been removed." listed as a security improvement. Even the newest version of the C standard (which strives to maintain backward compatibility) removed that function.
Can't tell any particular snippet, but from my POV bad code is what makes debugging and supporting it later hard.

The last system I had the displeasure to work on, which I had to convert from Mac OS to Windows, used OpenGL, and to overcome limitations of the graphics cards when it was written (texture size and card RAM limits) a layer was written which replaced OpenGL calls with functions by the same names which did a lot more (such as break textures into smaller ones and cache them, including loading and saving from disk). To add insult to injury some files had both real OpenGL and pseudo-OpenGL. That thing was debugging hell (as was the rest of the system).

Currently I'm working on something where a young and energetic programmer designed the code using iterators and decorators, so that when you do '*iter' it does all the processing, by doing more '*stuff'. It's not a terrible mess, but I really prefer calls that are readable and call trees which are reasonably flat.

Pet peeve: a 'bool' operator that initialises the object, or changes it in any way. That first system I mentioned had an 'if (something)' statement that initialised the object implicitly, and even though I knew it was there I fell for it numerous times. But I've seen it elsewhere.

Edit: When I said 'initialised' I meant created a document tree including loading parts from disk and caching them in a temp directory, that kind of stuff.
Post edited December 28, 2015 by ET3D
Variant solutions to the following school problem:
Consider the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, etc formed by extracting the digits of the natural numbers. For a given number, find the indices of its earliest representation in the sequence.
As you've probably guessed, any solution involving actually generating this sequence is a crime against humanity.
The problem with this is that while many of us have probably seen some spectacularly bad code over the years, we can't remember it in detail, and don't have access to it anymore, so it's not something we can post.

I have seen some bad decisions made in implementing some solutions though.

I once saw a colleague do something I considered phenomenally stupid. We worked on a system which handled orders and subscriptions for a fiber company, and the addition of a new IPTV product necessitated saving a PIN code in the order data structure during order processing. Rather than making a new column in the relevant database table, he chose to simply use an existing column which was no longer in use. Hence, the IPTV PIN code was saved in a column called something along the lines of dep_name_of_previous_customer. I tried to explain to him that eventually, someone else would have to do maintenance and debugging of that particular part of the system, and no amount of intuition would be able to tell them that the value in that column was in fact the IPTV PIN code. He couldn't see the problem, so he left it as it was.
avatar
dtgreene: I would go with Wizardry 1's (MA)HAMAN routine.

Here is how the code looks like when reverse engineered:

:1 110 CASE RANDOM MOD 3 * MAHAMFLG OF (* MAHAMFLG IS 6 OR 7 *)
:1 121 0, 1, 2, 3, 4, 5: HAMCURE; (* 1? 2? 3? 4? 5? *
:1 125 7, 8, 9, 10, 11: HAMSILEN; (* 8? 9? 10? 11? *
:1 129 12, 13, 22, 23: HAMMAGIC; (* 13?, 22?, 23? *
:1 133 14, 20, 21: HAMTELEP; (* 14?, 20? *
:1 137 6, 15, 19: HAMHEAL; (* 15?, 19? *
:1 141 17: HAMPROT; (* 17? DEAD COD
:1 145 16, 18: HAMALIVE; (* 16?, 18? DEAD COD
:1 149
:1 149 (* MAYBE THEY WANTED "RANDOM MOD (3 * MAHAMFLG)",
:1 149 AND MAHAMFLG = 6 OR 8 DEPENDING ON SPELL *)

Basically, it reduces the number mod 3 and then multiplies by 6 or 7, depending on which spell is cast. Therefore, the only possible results are 0, 6, 12 (for HAMAN) or 0, 7, 14 (for MAHAMAN). As a result, two of the effects can't happen.

Another example of code I hear is bad is SaGa 1's combat routine, which contains a bunch of ridiculous bugs (things like, blindness halves your agility, except when a basic STR-based attack is used, in which cast not being blind halves your agility) as well as one of the worst PRNGs I've encountered in a video game. (Luck manipulation is easy in this game even without emulator tools; I have seen a run on an actual Game Boy that used heavy luck manipulation.)
Ah, Video game RNG and dice. Sometimes I wonder if NIntendo still uses an RNG based on RANDU.
My neighbor's safe. Honestly, it's like people don't have any trust in others these days.
I'm going to say any text adventure written in BASIC. And we're talking the original 8bit basic which didn't include functions you can define and only included a handful defaults.

The reason being that the only way to get around is goto, and gosub&return. Everything is global, and the very nature of it's structure ensures it's spaghetti code. Text adventures specifically because they use a t0 more memory and space so are less likely to have remarks and comments to document anything.

from Advert. a quick glance confirms there's no comments to explain the logic, you're better off playing it, saving all the output, and rebuilding it from scratch...

[code]
367 FOR J=O TO 6:IF ASC(D$(J))>99 THEN O(Z)=ASC(D$(J))-H:GOTO H
370 NEXT J:? "You can't go that way.":GOTO B
375 IF S<53 AND S>46 THEN O(69)=O(Z):O(Z)=2:GOTO H
380 IF S=34 THEN O(Z)=39:GOTO H
381 IF S=35 THEN 900
382 IF S<47 AND S>42 THEN O(Z)=(S=43)*11+(S=44)*13+(S=45)*10+(S=46)*9:GOTO H
383 IF S<59 AND S>52 AND O(2)<255 THEN ? "It's closed":GOTO B
384 IF S<59 AND S>52 THEN O(Z)=(S=53)*6+(S=54)*4+(S=55)*15+(S=56)*14+(S=57)*27+(S=58)*38:GOTO H
390 IF S=40 THEN O(Z)=7:GOTO H
392 IF S=36 THEN O(Z)=33:GOTO H
393 IF S=38 THEN ? "a long way downJump-wwhheee-THUD!!!You missed the swimming poolBroken neck!!!":GOTO 8000
399 ? "Nope.":GOTO B
400 IF Q THEN GOSUB 700:GOTO 725
405 IF S>20 THEN ? "You can't get that.":GOTO B
410 IF O(S)<>O(Z) THEN ? "I don't see it.":GOTO B
415 IF O(68)=O(72) THEN ? "You can't carry any more.":GOTO B
[/code]
Post edited December 28, 2015 by rtcvb32
avatar
zeogold: My neighbor's safe. Honestly, it's like people don't have any trust in others these days.
How did you know about my safe -- US. spying confirmed :o)
VBA macros (yes, I worked a lot with those :( ) Often repairing others' "code".

The Microsoft employee who thought it would be a good idea to include "Record macro" with Excel, should be forced to work fixing the code people create using this function.

Example of one of the worst offenders:

To sort a column:
_Select the column
_Copy
_Create new sheet
_Paste
_Sort (using Excel's built in sort)
_Select the sorted column
_Copy
_Select original column
_Paste
Exult has some excessive use of static_cast in it.

Here is an example (from Actor::mend_wounds):

// Restore some mana also.
int maxmana = properties[static_cast<int>(magic)];
int curmana = properties[static_cast<int>(mana)];
clear_flag(Obj_flags::no_spell_casting);

if (maxmana > 0 && curmana < maxmana) {
if (maxmana >= 3)
curmana += 1 + rand() % (maxmana / 3);
else
curmana += 1;
properties[static_cast<int>(mana)] = curmana <= maxmana ? curmana
: maxmana;
}

Notice all those properties[static_cast<int>(mana)] in here? Reallt, there should be an automatic conversion defined here so that one doesn't need to be repeatedly static_casting the same thing repeatedly.

Also, I should point out that this does not match the actual behavior of real Ultima 7. In U7, the amount of MP you recover is equal to half the difference between your current and maximum MP, rounded up (assuming my memory is correct).
This thread reminds me a bit of thedailyWTF.
Although much cooler obviously.
avatar
Darvond: 1. Not your own code.
That rules out most of the examples I might have used XD

I've not often dealt with others code (other then when using engines or libraries) so I don't have many examples but one thing I did find was that when I built the website for my business I still wasn't all that confident with PHP / HTML / CSS (and I generally struggle to build something like a site from scratch) so I bought a template from a web site to start from.

And it was pretty badly done; the fade away nav bar could still be clicked on when it was invisible and stopped anything underneath it being clicked on, the actual mechanism for making it fade relied on I think three different classes being set on or off and a lot of other stuff didn't work if you wanted to make any changes to the default that had been included...
Also:

GOG forum code.
Oh yes, don't forget a bunch of funny entries on Computer Stupidities at Rinkworks!