Personal computing discussed

Moderators: SecretSquirrel, just brew it!

just brew it!
Gold subscriber
Topic Author
Posts: 52171
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

### Re: Worst code ever

JustAnEngineer wrote:
I'd already discarded the spreadsheet (which I had to use because my calculator is in the other room) but I am certain that anything that is divisible by both 3 and 5 is divisible by 15. This is the union of the two sets.
For 100, 3 and 5, I get 1683 + 950 - 315 = 2318.
For 1000, 3 and 5, I get 166833 + 99500 - 33165 = 233168.

Like 10 seconds after my previous post the light bulb went on. Hence the edit.
Nostalgia isn't what it used to be.

dmjifn
Gerbil First Class
Posts: 103
Joined: Thu May 15, 2003 4:21 pm
Location: Indianapolis

### Re: Worst code ever

anotherengineer wrote:
Hmmm checked out that problem...

Re: Having little to no coding experience
Then this little hurdle did its job!

Re: The question possibly being too clumsy
Sometimes I do wonder. But I put it another way: If they don't understand, I need them to ask questions and work it out with me. That's the part of the "how do you work" question. If we can't navigate through this problem, then they sure as heck can't be given the keys to a system that processes Medicaid cost reports. The rules for that look like the scarier part of the tax code.

just brew it! wrote:
JustAnEngineer wrote:
I'd already discarded the spreadsheet (which I had to use because my calculator is in the other room) but I am certain that anything that is divisible by both 3 and 5 is divisible by 15. This is the union of the two sets.
For 100, 3 and 5, I get 1683 + 950 - 315 = 2318.
For 1000, 3 and 5, I get 166833 + 99500 - 33165 = 233168.

Like 10 seconds after my previous post the light bulb went on. Hence the edit.

Either of you guys want a job in Indianapolis as a .NET programmer?

Redocbew
Gold subscriber
Gerbil Jedi
Posts: 1768
Joined: Sat Mar 15, 2014 11:44 am

### Re: Worst code ever

Depending on the work you do, being a developer can be one of those 90% boredom, 10% panic jobs also. If being able to think clearly while under pressure is important, then choking on a problem like that is doubly bad.
Do not meddle in the affairs of archers, for they are subtle and you won't hear them coming.

auxy
Graphmaster Gerbil
Posts: 1299
Joined: Sat Jan 19, 2013 4:25 pm
Location: the armpit of Texas

### Re: Worst code ever

just brew it! wrote:
dmjifn wrote:
Some of the worst code I've seen recently is in interviews where the candidate and I whiteboard a couple softball code problems. I ask a question that's pretty much Project Euler #1. This is tough exercise for most just because you're on the spot and out of your element. But we take pains to ease candidates into it. And I'm super liberal in accepting reasonable pseudocode, even letting them assume operators and API functions that don't exist but really probably could. Everyone we interview has a good resume listing very-likely-sounding accomplishments in the area of C# and .NET. Shockingly, less than half can even work through the logic of the problem, much less write the code.

That is truly scary. Although given some of the code I've seen "out in the wild" I guess I must acknowledge that professional developers with that shocking a lack of ability do exist. The solution is a half-dozen-ish lines of C (no external APIs/libraries required other than the ability to write to stdout), or, quite literally, a single line of Python. :roll:
I'm a reasonably intelligent person but I have very poor maths skills. I have absolutely no idea how to work out the logic of that problem! (ノД`)・゜・。

223 Fan
Gold subscriber
Gerbil
Posts: 58
Joined: Wed Jun 26, 2013 4:41 pm

### Re: Worst code ever

Putting try {...} catch (AssertionError ignored) {} around a unit test because they couldn't figure out how to fix the method to pass the test.

the
Gerbil Elite
Posts: 935
Joined: Tue Jun 29, 2010 2:26 am

### Re: Worst code ever

just brew it! wrote:
FWIW the 1-line Python solution is:
print sum(set(range(3,1000,3)+range(5,1000,5)))

Actually shouldn't it be this:

print sum(set(range(3,1000,3)+range(5,1000,5)-range(15,1000,15)))

The reason being is that 15 and other common multiples of 3 and 5 are included in both range functions.

EDIT: While my coding is OK, not so much my reading comprehension of the rest of the thread as that concern has already been addressed.

Of course the answer doesn't require iteration if you're willing to do a bit of math. This changes the algorithm from order(n) to order(1).

Thus for C you get:

``#include <stdio.h>int main(int a, int b, int range) {printf("%i",0.5*a*((range-1)/a)*(((range-1)/a)+1)+0.5*b*((range-1)/b)*(((range-1)/b)+1)-0.5*a*b*((range-1)/(a*b))*(((range-1)/(a*b))+1)); return 0;}``

Executing with the inputs of 3 5 1000 gets the proper result of 233168.

That's technically five lines but all the real work is done on a single line with the rest being standard C necessities.

And for completeness, their is a bug in the above code. It doesn't work for cases where b%a=0 or a%b=0. For example, it'd fail if you want the sum of the natural numbers divisible by 3 and 9 for a range.
Last edited by the on Sun Apr 26, 2015 1:51 am, edited 1 time in total.
Dual Opteron 6376, 96 GB DDR3, Asus KGPE-D16, GTX 970
Mac Pro Dual Xeon E5645, 48 GB DDR3, GTX 770
Core i7 3930K@4.2 Ghz, 32 GB DDR3, GA-X79-UP5-Wifi
Core i7 2600K@4.4 Ghz, 16 GB DDR3, GTX 970, GA-X68XP-UD4

drsauced
Gerbil Jedi
Posts: 1543
Joined: Mon Apr 21, 2003 1:38 pm
Location: Here!

### Re: Worst code ever

I don't have any worst code experience since I haven't done any coding since the late 90's. I was pretty good, though, top of the class back then as I remember, but it could be the beer goggles clouding things

Anyway, my story is sitting next to a large Texan, complete with the white shorts, pressed shirt, and a big ass hat. He was a programmer for the Gov't, working on a 'big project.' Well. It's kinda like meeting a dude at the laundromat who asks you to play a game of chess, not knowing that you're going to pay for their washing. I do IT, I tell the Texan, and he simply says, "Oh, really?" So we get into a problem, calendars. How do you deal with calendars in code? I dunno, count in seconds from 1970, or something. Right. This is a flight from Florida to San Francisco, non-stop. Yep, 16,200 seconds later, I get schooled in all things Gov't calendering. And all I was hoping he'd divulge some secret spy network or something.

I know, you're thinking, did I get the job? No. Close, but no hats for me. Stay in school, y'all.
Calm seas never made a skilled mariner. But, sadly I'm an A's fan.

esc_in_ks
Gerbil
Posts: 78
Joined: Sun Nov 08, 2009 4:55 pm
Location: Kansas

### Re: Worst code ever

This is a fun topic.

I worked in telecom back in the late 90s. I worked on a team of about 12 people. I was the only person with a computer science degree. Despite my other team members being pretty smart people and quite experienced, they were all new to software. Most came from electrical engineering backgrounds. Just like you probably wouldn't want me (a software guy) designing your complicated circuits, I didn't really like them (hardware guys) designing your complicated Windows GUI software.

One person who was rather smart otherwise, designed every component of their part of the system to take one parameter, a string, and return one parameter, a string. The string would contain semicolon separated values of a variety of things and then send you back a semicolon separated list of things. This was rather than, you know, *using function parameters*. He did this to mimic the ASCII protocol one would use to talk over the network to the device despite the fact that this code really had nothing to do with protocol---we were far, far away from the wire. This engineer used this take-a-string, return-a-string approach just because it's all they knew. This "protocol" wasn't documented either, so it meant reading his code to figure out what you needed to send it. It was like doing reverse engineering where the slightest mistake caused a crash and a visit from Dr. Watson.

I tried to show him better ways to do it, but I was very junior at the time, and there wasn't anyone listening.

It was a scary job to have just out of college. I was pretty sure the industry just might be completely broken! Fortunately, I moved on pretty quickly and realized that there are plenty of reasonable people to work with.
Home: PC-D600, Seasonic 850 Titanium, Apex X299, 7940X @ 4.1 GHz, H115i, 32G DDR4 3200, 960 Evo 1T+500G, 850 EVO 1T, GTX 1080, U3818+2x U2515h, Linux, Win10
Work: Arc Midi, 650TX, P8Z77-V LK, 3770, 32G, 830 128G, 2x1TB, NVS 295, 2xU3014, Linux

just brew it!
Gold subscriber
Topic Author
Posts: 52171
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

### Re: Worst code ever

esc_in_ks wrote:
Despite my other team members being pretty smart people and quite experienced, they were all new to software. Most came from electrical engineering backgrounds. Just like you probably wouldn't want me (a software guy) designing your complicated circuits, I didn't really like them (hardware guys) designing your complicated Windows GUI software.

Over the years, I've concluded that a big difference between EE and CS people is that most EE people seem to automatically think they know how to write software, whereas CS people generally understand their limits (at least with regards to hardware...), and wouldn't touch circuit design with a 10 foot pole unless they've had at least some prior experience. With only a few exceptions, crossover EE-CS people (especially recent ones) seem to write spectacularly bad code.

And then there's the incident from a few years ago that comes to mind... this EE guy was trying to modify a piece of firmware (written in C) for a microcontroller. At some point, he introduced an error in a header file, which caused compilation errors in the modules that included that header. His approach to "fixing" this was to start commenting out the lines with the compilation errors (which led to more errors). Lather, rinse, repeat. Eventually he got the compilation errors to go away... by commenting out nearly all of the code in the affected modules!
Nostalgia isn't what it used to be.

UnfriendlyFire
Posts: 264
Joined: Sat Aug 03, 2013 7:28 am

### Re: Worst code ever

just brew it! wrote:
esc_in_ks wrote:
Despite my other team members being pretty smart people and quite experienced, they were all new to software. Most came from electrical engineering backgrounds. Just like you probably wouldn't want me (a software guy) designing your complicated circuits, I didn't really like them (hardware guys) designing your complicated Windows GUI software.

Over the years, I've concluded that a big difference between EE and CS people is that most EE people seem to automatically think they know how to write software, whereas CS people generally understand their limits (at least with regards to hardware...), and wouldn't touch circuit design with a 10 foot pole unless they've had at least some prior experience. With only a few exceptions, crossover EE-CS people (especially recent ones) seem to write spectacularly bad code.

Would you trust a mechanical engineer to do programming and wiring controls systems (24V, 110V, 220V, 408V)?

BIF
Gold subscriber
Minister of Gerbil Affairs
Posts: 2316
Joined: Tue May 25, 2004 7:41 pm

### Re: Worst code ever

Many years ago I interviewed with a big newspaper for my first job out of college. Their "DP Manager" asked me some questions about COBOL and JCL, which I was able to answer. But the clue had already been given earlier: I know you've programmed in all these languages, but that was for school. Here in the real world, we'll teach you how it's REALLY done.

Didn't get that job, but I think there probably were a hundred other 22 year-olds going for the same single job. And another hundred other 24 year-olds with 2 years of experience already. They probably went with one of the latter.

Edit: Oh yeah, and I've had to fight my way through my share of awful code. Some sewers are cleaner.

UnfriendlyFire
Posts: 264
Joined: Sat Aug 03, 2013 7:28 am

### Re: Worst code ever

meerkt wrote:
UnfriendlyFire wrote:
the compiler that converts the code that we type on our computers and write it to the control systems isn't guaranteed to work with Windows 8/10. The compiler uses Windows 7's compatibility mode.
So a VM or DOSBox?

No, just compatibility mode. Mind you, the software has to have USB, Ethernet, or wireless connection in order to give the compiled code to the newer systems. The older controls systems only have a RS-232 port.

On a side note, we do have two 3-axis robotic arms from the 1980's, even though almost all of the others are the latest 5-axis or 6-axis models. Those 1980's robotic arms' compiler software isn't compatible with Windows XP, nevertheless Windows 7. Every time they need reprogramming, we would have to bring out a Windows 98 SE laptop.

chuckula
Gold subscriber
Gerbil Jedi
Posts: 1941
Joined: Wed Jan 23, 2008 9:18 pm
Location: Probably where I don't belong.

### Re: Worst code ever

BTW, for anyone who wants to see just how much I suck at coding, here's the card deck program that I wrote in a more Pythonesque manner. This is the better solution that I made up for that assignment that our office intern had to do.

A few notes: The print-out had to be made in a predetermined order, so you see a little extra complexity in the "showhand" and "showdeck" functions to generate the output in a predetermined suit/card face order instead of just dumping the contents of the deck or a hand. It's definitely not a work of art, but at least it attempts to be a Python program instead of a very low-level C program written in Python.

``#!/usr/bin/python2# Randomly draw cards from a deck for two players and print out # the randomly drawn hands. Implemented in a Pythonesque mannerimport random, copy# Global Defines:CARDFACES = ("Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King")CARDSUITS = ("Hearts", "Diamonds", "Clubs", "Spades")# Our main card deck that can deal randomized cards.# Note: It might make sense to make the individual card hands be subclasses of the deck object, or# make an abstract parent class for both CardDeck and PlayerHand to reduce code duplication.class CardDeck:   # Setup our card deck    def __init__ (self, cardSuitsParam = CARDSUITS, cardFacesParam = CARDFACES, startShuffled = True):          self.cardSuits = copy.copy (CARDSUITS) # internal copy of all the card suites     self.cardFaces = copy.copy (cardFacesParam) # internal copy of all the card faces, used for printouts.     # Generate our card deck as a list of tuples. Each list entry includes a tuple (Suit, Face)      # that identifies a card (e.g. [("Hearts", "Three"), ("Clubs", "Two"), ("Spades", "Queen") . . . ])     self.cardList = []     for nextSuit in self.cardSuits:       for nextFace in self.cardFaces:         self.cardList.append ((nextSuit, nextFace))      # Now shuffle the deck if the startShuffled parameter is true (see shuffle method below):     if startShuffled:        self.shuffle ()    # This shuffles the deck using a randomized card swap process.   # Note: A full deck or a non-full deck can be reshuffled.   def shuffle (self):          random.shuffle (self.cardList)  # easy... just use random.shuffle!             # prints out contents of deck. Optionally adjust suit & face order of output using the suitOrder &    # faceOrder parameters.   def showCards (self, suitOrder = CARDSUITS, faceOrder = CARDFACES):      cardSet = set (self.cardList) # sets have more efficient search functions      for nextSuit in suitOrder:        for nextCardFace in faceOrder:          # only print if a card is actually present in the deck:          if (nextSuit, nextCardFace) in cardSet:            print "%s of %s in deck." % (nextCardFace, nextSuit)    # Deals a number of cards (default to 5) at random that are removed from the deck.   # Returns: A list of (suit, face) tuples (e.g. [("Hearts, "Two"), ("Clubs", "Eight") . . . ]):.   def dealCards (self, numCards = 5):          # sanity check: If numCards is greater than the total number of cards left in the whole deck, fire an exception.     if (numCards < 1) or (numCards > len (self.cardList)):       raise ValueError ("Insufficient cards remaining in deck or invalid draw request!")     # Now pull the cards. We pop numCard cards from self.cardList and place the popped entries in outputCardList     outputCardList = [self.cardList.pop () for II in xrange (0, numCards)]           return (outputCardList)     # Dummy function right now, but this adds cards back into the deck:   def addCards (self, cardList):     return (None)# A hand given to a player:class PlayerHand:   def __init__ (self, initialCards = [], cardSuitsParam = CARDSUITS, cardFacesParam = CARDFACES):     # setup a hand including an optional set of initialCards. Similar to the deck initialization, but we start out     # with no cards present in the hand.     # Each card in initialCards is added as a tuple of (suit, face) (e.g. ("Spades", "Ace"))          self.cardSuits = copy.copy (CARDSUITS) # internal copy of all the card suites     self.cardFaces = copy.copy (cardFacesParam) # internal copy of all the card faces, used for printouts.     self.cardList = []         if len (initialCards) > 0:       self.addCards (initialCards)           # Almost the same as showCards in CardDeck class (could be refactored for common code??)   def showCards (self, suitOrder = CARDSUITS, faceOrder = CARDFACES):      cardSet = set (self.cardList)            for nextSuit in suitOrder:        for nextCardFace in faceOrder:          # only print if a card is actually present in the hand:          if (nextSuit, nextCardFace) in cardSet:            print "%s of %s in hand." % (nextCardFace, nextSuit)      # This function receives a list of cards cardList as (Suit, Face) tuples (e.g. ("Hearts", "Jack") and adds them   # to the hand.   def addCards (self, addedCards):          # error checking:       for nextSuit, nextFace in addedCards:          if (nextSuit not in self.cardSuits) or (nextFace not in self.cardFaces):           raise ValueError ("Invalid card suit or face name %s, %s" % (nextSuit, nextFace))       self.cardList.extend (addedCards)               # Dummy function right now, but this discards cards from the hand:   def discardCards (self, discardedCards):     return (None)if __name__ == "__main__":    # start by generating our deck and hands  pokerDeck = CardDeck ()  myHand = PlayerHand ()  computerHand = PlayerHand ()  # Show deck prior to dealing  print "Cards in Original Deck: "  pokerDeck.showCards ()  # Now deal out two hands. Note: To be even more realistic, deal out 1 card at a time to each player in a loop.  myHand.addCards (pokerDeck.dealCards ())  computerHand.addCards (pokerDeck.dealCards ())  # print out our player & computer hands, then print out the deck again:  print "\nPlayer's Hand:"  myHand.showCards ()  print "\nComputer's Hand:"  computerHand.showCards ()    print "\nRemaining Cards in Deck:"  pokerDeck.showCards ()``
4770K @ 4.7 GHz; 32GB DDR3-2133; GTX-1080 sold and back to hipster IGP!; 512GB 840 Pro (2x); Fractal Define XL-R2; NZXT Kraken-X60
--Many thanks to the TR Forum for advice in getting it built.

localhostrulez
Minister of Gerbil Affairs
Posts: 2481
Joined: Sun Mar 09, 2014 11:26 pm

### Re: Worst code ever

just brew it! wrote:
Over the years, I've concluded that a big difference between EE and CS people is that most EE people seem to automatically think they know how to write software, whereas CS people generally understand their limits (at least with regards to hardware...), and wouldn't touch circuit design with a 10 foot pole unless they've had at least some prior experience. With only a few exceptions, crossover EE-CS people (especially recent ones) seem to write spectacularly bad code.

And then there's the incident from a few years ago that comes to mind... this EE guy was trying to modify a piece of firmware (written in C) for a microcontroller. At some point, he introduced an error in a header file, which caused compilation errors in the modules that included that header. His approach to "fixing" this was to start commenting out the lines with the compilation errors (which led to more errors). Lather, rinse, repeat. Eventually he got the compilation errors to go away... by commenting out nearly all of the code in the affected modules!

Depends on what you mean by code. Can I write basic Arduino or PLC code? Yes. Do I trust myself to do networking stuff? Yes (though I've also done some IT stuff, so that's mainly why). Do I trust myself to write a full desktop program? Hell no. And with that project I'm working on, chances are I'll have a lot of the database code done by the CS people on the team for that very reason.

On another note, I've started wondering how I can, say, change the oil in a car. Easy if you know what you're doing, but I don't want to become one of those idiots who completely f**ks it up in the process (since I don't know what I'm doing there). Seen those people in IT, and I don't need to be among them.

BIF
Gold subscriber
Minister of Gerbil Affairs
Posts: 2316
Joined: Tue May 25, 2004 7:41 pm

### Re: Worst code ever

Changing one's own oil is not difficult. I just prefer not to do it anymore.

Redocbew
Gold subscriber
Gerbil Jedi
Posts: 1768
Joined: Sat Mar 15, 2014 11:44 am

### Re: Worst code ever

esc_in_ks wrote:
This was rather than, you know, *using function parameters*. He did this to mimic the ASCII protocol one would use to talk over the network to the device despite the fact that this code really had nothing to do with protocol---we were far, far away from the wire. This engineer used this take-a-string, return-a-string approach just because it's all they knew.

Yes, the Golden Hammer approach. I've seen that also. If it worked for some other completely unrelated problem, then it must be a good idea for this one also.

I worked on some code maybe a year ago where various data structures were serialized to XML and back again any time the data needed to be manipulated just because the people who wrote it didn't feel it was necessary to learn the APIs of the systems involved. Performance was terrible as a result, but at least it made diagnosing the problem easy. No need for a profiler when you find something like that.
Do not meddle in the affairs of archers, for they are subtle and you won't hear them coming.

localhostrulez
Minister of Gerbil Affairs
Posts: 2481
Joined: Sun Mar 09, 2014 11:26 pm

### Re: Worst code ever

BIF wrote:
Changing one's own oil is not difficult. I just prefer not to do it anymore.

Honestly, I'm on the solar vehicle team at my uni. And I feel like an idiot even for not knowing how to drive stick. (Seems like several of us don't know how and don't have a car, or do and own a stick.) I'm an EE, and I really ought to know how to do these things... I'm kinda getting the feeling that I may be one of those guys who buys a stick, and then figures out how to actually get good at driving it. My dad was one of those, right out of college. Very much like me actually. I'm figuring that out more and more as I get older...

I mean, I'm not going to call HP when something goes wrong with my computer (unless it's a defective/warranty part obviously), so why do that sort of thing with a car? OK, I'm exaggerating, but lol...

just brew it!
Gold subscriber
Topic Author
Posts: 52171
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

### Re: Worst code ever

Redocbew wrote:
Yes, the Golden Hammer approach.

When all you know how to use is a hammer, every problem looks like a nail...
Nostalgia isn't what it used to be.

JustAnEngineer
Gold subscriber
Gerbil God
Posts: 18398
Joined: Sat Jan 26, 2002 7:00 pm
Location: The Heart of Dixie

### Re: Worst code ever

just brew it! wrote:
Redocbew wrote:
Yes, the Golden Hammer approach.
When all you know how to use is a hammer, every problem looks like a nail...
The corollary is that if you give a small boy a hammer, everything needs pounding.
i7-9700K, H100i v2, Z390M Pro4, 32 GiB, RX Vega64, Define Mini-C, SSR-850PX, C32HG70, RK-9000BR, MX518

SecretSquirrel
Minister of Gerbil Affairs
Posts: 2489
Joined: Tue Jan 01, 2002 7:00 pm
Location: North DFW suburb...
Contact:

### Re: Worst code ever

dmjifn wrote:
Some of the worst code I've seen recently is in interviews where the candidate and I whiteboard a couple softball code problems. I ask a question that's pretty much Project Euler #1. This is tough exercise for most just because you're on the spot and out of your element. But we take pains to ease candidates into it. And I'm super liberal in accepting reasonable pseudocode, even letting them assume operators and API functions that don't exist but really probably could. Everyone we interview has a good resume listing very-likely-sounding accomplishments in the area of C# and .NET. Shockingly, less than half can even work through the logic of the problem, much less write the code.

``long int summit(int n) {  long int sum=0;  do {    if((n % 3)==0 || (n %5 )==0) {      sum+=n;    }  } while(n--);  return sum;}``

Couldn't resist the "old school" C solution. Any programmer worth their salt should be able to write that in just about any language given 30 minutes with a language reference/primer. And here is another one, just for the heck of it.

``  ;n is passed in EAX  push EBX  ;save EBX and ECX as they will hold the sum while we run  push ECX  xor EBX,EBX  ;zero out ECX:EBX  xor ECX,ECXloop:  xor EDX,EDX  ;zero the high bits for the division  push EAX       ;save out current count  mov ESI, 3   ;divide by three   div ESI  pop EAX    ;restore our count.  We don't care about the quotient  test EDX   ;if the remainder is zero, then we add to our running sum  jnz div5   ;otherwise we skip to check for divide by 5  add EBX, EAX  ;add the low chunk first  adc ECX, 0      ;and propagate the carry into the high chunk  jmp decr_ndiv5:          ;same logic as the divide by 3  xor EDX, EDX  push EAX  mov ESI, 5  div ESI  pop EAX  test EDX  jnz decr_n  add EBX, EAX  adc ECX, 0decr_n:     ;decrement our count and loop until we hit 0  dec EAX  jnz loop  mov EDX, ECX   ;we are going to return our count in EDX:EAX  mov EAX, EBX  pop ECX  ;restore the values of the temp registers prior to function return  pop EBX  ret  ;sum is returned in EDX:EAX``

I doubt the assembly will compile and run the first time, but the general logic is right.

I think the worst code I have ever seen was a piece of C++ middleware that screen scraped the 80x25 output of a Micro VAX and turned it into something that could be rendered on a web page. The original designer went "object happy". Once you dug down an uncountable number of inheritance layers, it turned out that each character on the screen was an object. This meant things like string copies or comparisons were incredibly slow and the whole thing took way more memory that it should have. But! It was Object Oriented!!!

--SS

Redocbew
Gold subscriber
Gerbil Jedi
Posts: 1768
Joined: Sat Mar 15, 2014 11:44 am

### Re: Worst code ever

Ack. x86 assembly is not your friend. I know i just brought up the golden hammer and all, but I'm glad I came to the field at a time when there are high level languages around. However, I'm also glad I learned it. Being able to write code without really needing to know what its doing inside the machine is sure to be part of the problem in how all these stories came to be.
Do not meddle in the affairs of archers, for they are subtle and you won't hear them coming.

just brew it!
Gold subscriber
Topic Author
Posts: 52171
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

### Re: Worst code ever

Could be worse, could be i860 assembly language. That was some truly bizarre sh*t. Made even worse by crazy bugs in the silicon that you needed to be aware of if you wanted things to... you know... actually work. "Hi, I'm your CPU. Just so you know, every so often I find myself in a contrary mood, and will decide to ignore the first instruction of your exception handler for no particular reason. Or maybe I had too much coffee this morning, and just might accidentally execute it twice instead. Isn't this fun?"

The i860 is definitely the worst CPU I ever had to write (assembly) code for. CDC Cyber may very well be the oddest (by modern CPU architecture standards) system I've ever used, but I never had to write assembly code for it.
Nostalgia isn't what it used to be.

biffzinker
Gerbil Jedi
Posts: 1991
Joined: Tue Mar 21, 2006 3:53 pm
Location: AK, USA

### Re: Worst code ever

It would take you 2,363 continuous hours or 98 days,11 hours, and 35 minutes of gameplay to complete your Steam library.
In this time you could travel to Venus one time.

just brew it!
Gold subscriber
Topic Author
Posts: 52171
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

### Re: Worst code ever

just brew it! wrote:
As they say, "Those who can, do; those who can't, teach!"

I wish to apologize for the above comment. It was meant to be tongue-in-cheek, but is unnecessarily disparaging of those in the teaching profession. It was not my intention to offend. Any further discussion in this direction might be better taken to the R&P forum. Mea culpa.

We now return you to your regularly scheduled programming, "Bashing Former Co-Workers Who Can't Code"...
Nostalgia isn't what it used to be.

DieselPig
Gerbil
Posts: 24
Joined: Thu Oct 02, 2014 3:30 am
Location: England

### Re: Worst code ever

Worked for a company many moons ago who designed & manufactured industrial products & systems. We had 2 PC's in the company woohoo!

They hired this genius PhD to write a program (in basic) to calculate the profile of a tapered metal plug. 12 months later the program was finished and looked good, enter key numbers and CNC program was printed out. After PhD left we needed to add further sizes to this program.

I was tasked with this as I had just started a Software Engineering course & thus deemed the most competent (I am a Electronics Engineer). PhD had produced one page of the most horrendous spaghetti mess of code I have ever seen, it was undocumented, un-structered and had as many GOTO statements as lines of code.

PhD was revered during his tenure as someone who began coding at the dawn of the computer age, authored books and lectured at the highest level. I have never seen a book published by him or heard of the bloke since!

I re-wrote it in Microsoft Quick Pascal in 4 weeks and the company still use it 20 years after I left.
Last edited by DieselPig on Mon Apr 27, 2015 7:18 am, edited 1 time in total.

just brew it!
Gold subscriber
Topic Author
Posts: 52171
Joined: Tue Aug 20, 2002 10:51 pm
Location: Somewhere, having a beer

### Re: Worst code ever

Speaking of spaghetti code...

I remember seeing some C code years ago which had gotos back and forth between lines within if/else blocks. I.e. constructs of the form:
``if (condition1) {  <stuff>  label1:  <stuff>  if (condition2) goto label2;  <stuff>} else {  <stuff>  if (condition3) goto label1;  <stuff>  label2:  <stuff>}``

Gotos can have their uses. The above type of situation is not one of them!
Nostalgia isn't what it used to be.

notfred
Maximum Gerbil
Posts: 4532
Joined: Tue Aug 10, 2004 10:10 am

### Re: Worst code ever

People like to hate on x86 assembly language, but from a cache coherence and relatively strongly ordered memory it's way nicer processor to deal with than ARM when you are trying to talk to peripherals. Add in some bugs from the silicon vendor and you are in for a lot of fun - NOT!

Most bizarre processor I ever dealt with was the TMS320LC542 - in C everything was 32bits apart from long doubles. Char, int, long - all 32 bits. In assembly language it never stalled the pipeline and actually read the memory several instructions before the actual load and wrote to the memory several instructions after the store. Debugging step 1 consisted of adding 6 NOPs between each instruction and seeing if it then worked.

chuckula
Gold subscriber
Gerbil Jedi
Posts: 1941
Joined: Wed Jan 23, 2008 9:18 pm
Location: Probably where I don't belong.

### Re: Worst code ever

DieselPig wrote:
They hired this genius PhD to write a program.....

NOOOOOOO!!!!!!!

Yeah, PhDs and actual working software do not mix. Been there myself and it was never pretty. They are too wrapped up in their own theoretical genius to actually go through the process of developing code that can be understood and maintained by mere mortals.

Then again, you were able to re-implement a better version in 4 weeks... so maybe there was a little less genius involved than we thought.
4770K @ 4.7 GHz; 32GB DDR3-2133; GTX-1080 sold and back to hipster IGP!; 512GB 840 Pro (2x); Fractal Define XL-R2; NZXT Kraken-X60
--Many thanks to the TR Forum for advice in getting it built.

bthylafh
Maximum Gerbil
Posts: 4128
Joined: Mon Dec 29, 2003 11:55 pm
Location: Southwest Missouri, USA

### Re: Worst code ever

chuckula wrote:
Then again, you were able to re-implement a better version in 4 weeks... so maybe there was a little less genius involved than we thought.

In 4 weeks, after it took the PhD a year to write his version.
Hakkaa päälle!
i7-8700K|Asus Z-370 Pro|32GB DDR4|Asus Radeon RX-580|Samsung 960 EVO 1TB|1988 Model M||Logitech MX 518 & F310|Samsung C24FG70|Dell 2209WA|ATH-M50x

anotherengineer
Gerbil Jedi
Posts: 1573
Joined: Fri Sep 25, 2009 1:53 pm
Location: Northern, ON Canada, Yes I know, Up in the sticks

### Re: Worst code ever

So code monkeys no offense

I have another question for you guys. I have seen a lot of examples and most of them have been in regards to math. However, the programming language has been C or a derivative of, perl, .net, etc., etc.

I thought Fortran was more specifically geared to math. And from my limited use of MatLab is it specifically geared to math and very powerful in that regard, and even ranked #10 overall most common, from a previous link.

So does/has used either of those for work, why, or why not??
Life doesn't change after marriage, it changes after children!

### Who is online

Users browsing this forum: No registered users and 1 guest