back to article Good thing this dev quit. I'd have fired him. Out of a cannon. Into the sun

Roll up, roll up. It's your Wednesday dose of ridiculous code spotted in the wild. If you've seen some horrors, send over your tales, please, and we'll share them with our readers. We've had a great response so far, which perhaps is a damning indictment for the software engineering industry. It can't be all bad, though – …

Page:

  1. theOtherJT

    Let me guess, that last one was an academic?

    There's something about academics and amusingly ancient versions of Fortran. Well, they would be amusing, but when they show up in your office with a Fortran IDE on floppy disk and want it installed on the managed desktops it stops being amusing really quickly.

    1. theModge

      Re: Let me guess, that last one was an academic?

      I know of pretty of chemistry academics still using fortran. The real question is are they using anything so modern as fortran 77? Or is it still the really old version that's formatted to fit on punch cards?

      1. Paul Crawford Silver badge
        Pint

        Re: anything so modern as fortran 77?

        Converting FORTRAN IV from https://celestrak.com/NORAD/documentation/spacetrk.pdf in to C was not much fun, but sadly it was necessary to have any sane way forward. Start with f2c conversion, spend time sorting out the weird functions it used to make Fortran-like calls (i.e. by reference) instead of C-like (usually by-value) and finally work out how to restructure to code so it looked sane and still worked.

        Oh, and a subroutine with multiple ENTRY points also had to be converted, but thankfully it was just a dodgy way of having shared auto-allocated (implicit declaration & typing) variables. Anyone writing Fortran without "implicit none" deserves a serious slapping!

        Needed oh so much =>

    2. elDog Silver badge

      Re: Let me guess, that last one was an academic?

      I'm guessing the chap (or chapstress) was playing with memory caching. We used to put items that were frequently used together (input and output cells) in proximity since fetching from a block of contiguous memory was more efficient.

      Actually, that brings up another wonderful trick from the early 8088 days: execute code on the stack since it was guaranteed to be ready/available and easily reachable via ,SP. Ah, the good old days of coding animation for the PC Jr. (Thanks Time-Life, Broderbund, etc.)

    3. BoldMan

      Re: Let me guess, that last one was an academic?

      Oh this brings back terrible memories trying to support FORTRAN written by "clever" scientists, using nested arithmetic gotos and other such horrors.

      Scientists/academics should not be allowed to write code that anyone else needs to touch! :)

    4. Anonymous Coward
      Anonymous Coward

      Re: Let me guess, that last one was an academic?

      There is something about academics that mean they can't code....

      Seriously, I think only one professor in my university knew how to write good code, and that was because he'd worked commercially in addition to being a professor....

      I often re-wrote the helper classes & methods we were given to use, purely because they were so badly written it frustrated me to even try and use them....

      I would tell the lectureres I re-wrote them, why I did it and then ensure they had my updated code for future years...

      1. keithpeter
        Coat

        Re: Let me guess, that last one was an academic?

        "There is something about academics that mean they can't code...."

        I suspect the OA was talking about academics in other subjects rather than computing lecturers. Physicists and Biologists and Chemists live very close to their problem domains and probably see the computer as a huge calculator that can print things nicely (well, I did). They may not need/want to abstract away the underlying logic of whatever problem they are trying to solve...

        PS: @Tom 13 I used to number my punched cards in pencil on the back just in case I dropped the stack. That was considered to be a useful innovation at the time...

        1. Vincent Ballard

          Re: Let me guess, that last one was an academic?

          Some computer science academics have experience in the real world and know how to write good software. Others are complete disasters. They know how to write for the common case, which is all they need to get the results they want for their papers, but don't know anything about writing software which handles corner cases and is robust enough for the real world.

        2. Phil O'Sophical Silver badge

          Re: Let me guess, that last one was an academic?

          I used to number my punched cards in pencil on the back just in case I dropped the stack. That was considered to be a useful innovation at the time...

          That's why Fortran only uses columns 1-72, you punch sequence numbers in the last 8 columns (going up in 10s so you can insert missing cards later, just like you used to do for BASIC line numbers). Then when you drop the stack you can load them in any order and have the system reorder them for you.

          1. keithpeter
            Coat

            Re: Let me guess, that last one was an academic?

            "That's why Fortran only uses columns 1-72, you punch sequence numbers in the last 8 columns (going up in 10s so you can insert missing cards later, just like you used to do for BASIC line numbers)."

            Excellent, I wish I could go back in a time machine and tell the 22 year old me about that. That old mainframe was the first card-punch input machine I had used. 'Coffee batch' before that.

            Mind you, those card punches took a bit of typing. We did Algol as an undergrad, I had to learn FORTRAN on the 'job'.

          2. Dyspeptic Curmudgeon

            Re: Let me guess, that last one was an academic?

            I am pretty sure that Fortran started out to use only 1-72. The ability to add line-numbers in columns 73-80 came a little later.... If memory serves ( but sometimes it can only volley at all well) the changeover was about 1970 or so. Since I can remember writing line numbers on the cards and only later being able to use the end columns..... Dropped a box containing a ~4000 line program down a stairwell once. Luckily it was AFTER numbered columns were available...

            Long ago in a galaxy far far away....

        3. The Rest of the Sheep

          Re: Let me guess, that last one was an academic?

          My favorite way is simpler - a diagonal stripe across the top of the card deck. Maybe not as exact as numbering, but will get you very close.

      2. druck
        Unhappy

        Re: Let me guess, that last one was an academic?

        AC wrote:

        I often re-wrote the helper classes & methods we were given to use, purely because they were so badly written it frustrated me to even try and use them....

        I would tell the lectureres I re-wrote them, why I did it and then ensure they had my updated code for future years...

        I can imagine how well the egotistical bastards took that - did you managed to graduate?

        I was lucky enough to get one one of the first Computer Science courses in the country using C++. The language was only a couple of years old, and the only compiler was CFront. There was no teaching books on it at the time, so the lecturer writing one based on the course. At the end of the year he gave us the draft printout of the book, and promised a pint for each mistake anyone spotted. I had a list of 10 by the next day, did I get as much as a single pint? The hell I did, and strangely enough things started getting a lot more difficult after that.

    5. Tom 13

      Re: on floppy disk and want it installed on the managed desktops

      Be thankful it was at least on a floppy disk. Could be worse; it could be magnetic tape or even punch cards.

    6. /dev/null

      Re: Let me guess, that last one was an academic?

      I once worked on a complex Fortran-77 "code" (hard scientists always use the word "code" as a singular noun, not a mass noun) where all the important data was held in one giant 1-dimensional array. Some of it was integers, some floating-point, some elements were "pointers" into other parts of the array...

      And then there was the module that was written by a mathematician who never added comments to his code because they would slow down the execution...

      1. dajames Silver badge

        Re: Let me guess, that last one was an academic?

        I once worked on a complex Fortran-77 "code" (hard scientists always use the word "code" as a singular noun, not a mass noun) ...

        I've noticed that trait, and ascribed it to non-native English speakers ... bit while 'hard scientists' may not be capable of speaking plain English, many of them certainly are native English speakers.

        At least "a code" is better than "a soft".

    7. fajensen Silver badge

      Re: Let me guess, that last one was an academic?

      Academics always have to prove how clever they are at whatever task attempted - and thus we get abominations such as: "NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)" - where parentheses are banned from really hairy expressions because only a moron will be ignorant on the evaluation order of C operators.

      .... and the lesser academics are copy-pasting the "FORTRAN in any language with C-quirks on top" code that they ripped from books all over the matrix.

      1. Alan Johnson

        Re: Let me guess, that last one was an academic?

        I actually quite like numrical recipes at least the numerical parts but the code style is awful, not least in the use of single letter variable names starting with a and working through the alphabet as if the length of variable name was related to efficiency or memory usage.

        The attitude of mind was illustrated when I tried to compile the code that goes with the book on a unix system. The numerical recipes code had a function called 'select'. This caused a lot of header file/linking issues with the completely unrelated POSIX call of the same name. Anyway after working around the issue I sent a nice e-mail describing the problems and suggesting that in time they modified all of the function names by adding a prefix to make the names unique or at least much less likely to conflict. The reply was that they considered the problem a bug in the OS I was using and they had no intention of changing!

        Maybe not an example of awful coding but an example of an awful attitude.

        1. Simon Harris Silver badge

          Re: Let me guess, that last one was an academic?

          "not least in the use of single letter variable names starting with a and working through the alphabet as if the length of variable name was related to efficiency or memory usage."

          If they'd started out using interpreted BASICs (well those that actually allowed long variable names) then it probably was related, and of course, if they'd used versions that didn't allow such things, then single letter names would be what they were used to.

        2. GrumpenKraut Silver badge
          Boffin

          Re: Let me guess, that last one was an academic?

          > ...numerical recipes...

          A word of warning: the books are OK for a first intro, especially if you check the referenced papers (though these urgently needed updates last time I look).

          Actually using the code is VERY ill advised. There are enough problems with correctness and performance to screw your project. A friend of mine got bitten by this: mentioning "numerical recipes" next to him is now outright dangerous.

          Finally, the license terms are bonkers.

        3. Sam Liddicott

          Re: Let me guess, that last one was an academic?

          and an example commercial naivety

          Did they want the major conversations about their book to be about how people couldn't get the code to link properly? Or to be stories of success and usefulness?

      2. GrumpenKraut Silver badge

        Re: Let me guess, that last one was an academic?

        > Academics always have to prove how clever they are at whatever task attempted...

        Wrong. Yours, an academic.

  2. Anonymous Coward/2.0
    Facepalm

    re: left to my own devises

    I used to program in Coral66 which institutionalized something akin to the wonderful #defines in the article. In Coral66 keywords are in primes, e.g. 'IF', 'THEN', 'ELSE', 'BEGIN', 'END' and so on.

    This fine except that it meant that you could spaces in variable names but the spaces were ignored by the compiler. These all refer to the same thing -

    my variable, myvariable, m y v a r i a b l e, my variable

    As you can imagine it became a nightmare trying to find a variable in a big program where developers had used spaces in their own unique way. We tried to ban the use of spaces inside variable names but there were always the maverics that insisted on using them and legacy code and the careless Friday afternoon code post pub lunch.

  3. JimmyPage Silver badge
    Flame

    Ah, VB ... "variants"

    I once worked on a sizeable project in Weath Managment.

    Written in VB (I hail from a C/C++ background) they had tried to be "all grown up" and name variables correctly. So you had iCount, dblPrice, strName etc.

    Problem was, they were all variants.

    Which meant, if there was a fuck-up in the chain, and a string got accepted for a numeric value, the error could be propagated a long way from the source.

    1. Kubla Cant Silver badge

      Re: Ah, VB ... "variants"

      iCount, dblPrice, strName etc.

      Aaargh! The abominable Hungarian notation!

      It's just about excusable in a language with few data types, where it provides some sort of validation, if anybody bothers to read it. The trouble is, nobody does.

      Then the type gets changed, but the Hungarian remains the same, because development environments where Hungarian notation is used rarely support refactoring. At which point it's actively misleading.

      Then developers who don't know how it's supposed to work start devising their own Hungarian prefixes, often to indicate the usage of the variable, eg domNumber because it holds the day of the month.

      (Apologies to any actual Hungarians reading this.)

      1. Someone Else Silver badge
        Pint

        @Kubla Cant -- Re: Ah, VB ... "variants"

        Aaargh! The abominable Hungarian notation!

        Any enemy of Hungarian Notation is a friend of mine. For you, my friend --->

        1. J.G.Harston Silver badge

          Re: @Kubla Cant -- Ah, VB ... "variants"

          Hungarian notation is ok, but for /meaning/, not for typing.

          timerInit, timerSlice, fnameExpand, ctxOld, ctxCurrent, ctxNext, etc.

    2. Bc1609

      Re: Ah, VB ... "variants"

      While the variant type is indeed abominable, it is sometimes preferable to the cock-ups you can get when using the proper number types. Because VB/VBA creates types for you if they're not specified properly you can end up with exceptions just by multiplying five-digit numbers together.

      (Of course, a competent coder wouldn't have that issue, but the entire problem is that we're not dealing with competent coders...).

    3. Kubla Cant Silver badge
      Flame

      Re: Ah, VB ... "variants"

      Another VB horror I had to sort out.

      A developer writes a critical routine that takes a datetime parameter. This routine eventually gets called from hundreds of locations all over the system. Often it's actually passed a datetime value, but sometimes it gets a variant and sometimes it just gets a string. VB says "that's cool, just pass any old thing and I'll make it work".

      Years pass, and it starts to become clear that there are some bad dates in the system. It turns out that VB's way of turning strings into dates is to ignore the system locale and try to guess what the format might be. Pass in "25/12/2015" and it correctly assumes DMY and returns 25 December, but when it sees "10/12/2015" it returns 12 October! Finding the bad calls is more or less impossible, given the lack of VB code analysis tools.

      The cause of this problem is a thing called cdate() that lives deep inside the run-time infrastructure. It turns out that the only way to fix it is to add code that patches the run-time after it's loaded into memory, not something you really want to do on a mission-critical server.

      Thank you, Microsoft.

      1. I'm Brian and so's my wife

        Re: Ah, VB ... "variants"

        No - never, never use CDate() since it'll happily wave through Yank dates.

        Also, IsNumeric() will allow through 123,,445,,6,5,4

        I ended up writing helper functions that employed regex to ensure that the values matched.

  4. Anonymous Coward
    Anonymous Coward

    How does bad code like this ever reach released state? Isn't all code peer-reviewed and approved?

    Individuals can make mistakes and poor judged decisions. But since the 60's we've known that quailty requires a code review process. You don't just bung it from development direct to functional test.

    1. A Non e-mouse Silver badge

      Because coders don't always work in teams? Maybe the code started out as a niche project which grew beyond its original use case? Maybe the boss didn't want to "waste time" tidying up or re-writing something that already works.

      As to "Testing", well, that's just overhead, so just go straight from development to live...

    2. Jason Bloomberg Silver badge

      Ah, in such a perfect world. Unfortunately it's often not. When code is being screamed for it's whatever works no matter how bodged, fudged and kludged it has to be. Often the programmer committing the atrocity knows that's exactly what they are doing, knows what nightmares they are creating along the way, but they don't get to call the shots.

    3. Just Enough

      Coding by geniuses

      Because the code monkey writing the shitty code usually has a boss who knows nothing about writing code. So all the boss knows is that the code appears to work, was written really quickly, and only the code monkey understands it. Therefore the code monkey must be a freaking genius.

      Experience shows that if you are in a new job, and are introduced to a colleague by the boss as a "genius we couldn't do without", it often means that they are a dangerous lone developer who produces shitty code that no-one else has ever been asked to review.

      1. matchbx

        Re: Coding by geniuses

        I work with one of these geniuses..... He's a very knowledgeable developer, but he never tests anything and is often surprised when a bug occurs in his code. He lives and dies by the motto, how fast can I have this done. His code is usually overly complicated, cause it's a micro second faster to do it this way, but you waste hours trying to figure out what he wanted to accomplish.

        I use him as an information source and a sounding board only. I NEVER follow his advice on how to implement any code routine.

        A few years ago at Christmas, I almost bought him a t-shirt from thinkgeek:

        "I don't often test my code, but when I do, I do it in Production."

        anonymous..... cause he might be reading this.

        1. GrumpenKraut Silver badge

          Re: Coding by geniuses

          > anonymous..... cause he might be reading this.

          Oh dear, you missed that button before going into production.

          1. matchbx

            Re: Coding by geniuses

            yea... I see that now that it's too late to update.....

            I must have been busy reviewing my code......

      2. Brewster's Angle Grinder Silver badge

        Re: Coding by geniuses

        "...and are introduced to a colleague by the boss as a "genius we couldn't do without", it often means that they are a dangerous lone developer who produces shitty code that no-one else has ever been asked to review."

        *holds up hand*

        Yup, that'd be me.

        Although I'm not as bad as the one matchbox encountered: some of my code has test cases.

      3. LucreLout Silver badge

        Re: Coding by geniuses

        @Just Enough

        Because the code monkey writing the shitty code usually has a boss who knows nothing about writing code. So all the boss knows is that the code appears to work, was written really quickly, and only the code monkey understands it. Therefore the code monkey must be a freaking genius.

        This ^^^

        I've suffered that situation so often over the past 20 years that I now simply quit when encountering said monkeys. There's nothing you can do for them because both the monkey and the manager are equally convinced of the monkey magic, and neither can grasp why its wrong, expensive, frustrating, and dangerous (from a risk PoV).

        I've seen nothing over the past 20 years that has in anyway persuaded me that our industry is better for not being regulated, similar to the GMC etc. It's the only way to keep the monkeys in the zoo rather than wandering through your business causing havoc.

      4. Nick Ryan Silver badge

        Re: Coding by geniuses

        I first encountered this when working on an industrial placement as part of my Uni course.I was given the task to take over code from the resident genius. His code was concise, fast and didn't work.

        It was so concise there were often no, or few validation checks with error messages. If something didn't work it was often ignored, and this "something" could have been any one of a dozen things in a single compound logic statement. Every bit of code worked like this, therefore when something didn't work it was next to impossible to work out why.

        Needless to say I simplified things and logged every damn error message so we knew exactly wasn't working, where and when which gave us a start as to why.

    4. d3vy Silver badge

      "How does bad code like this ever reach released state? Isn't all code peer-reviewed and approved?"

      Ha.

      Good one.

    5. Anonymous Coward
      Anonymous Coward

      Usually, "peer reviewing" code is the best way to create a lot of enemies. Very few people on average like people reviewing (and criticizing) their work - unless working in environments were that's enforced for some reasons. I had many issues while pointing out bad code (and thoroughly explaining why it is bad, with a lot of references to books, best practices, standards, etc. etc.), or looking like the one who likes to put others into bad light, up to the point I was recalled by HR telling me explicitly "you need to learn how to relate to people properly" AKA don't "annoy" anybody and who cares if a lot of crappy code goes into production, HR doesn't care as long as it's not an HR issue.

      All I wish is to avoid that, because when the fans start to throw s**t around, it's not usually the "original developer" who is called to fix things quickly, and calm an angry and unwillingly to pay customer, but me, and I'm quite tired to fix someone else ugly buggy code - often needing a complete rewrite in a too short time.

      Lately I stopped reviewing completely, leaving that code entering production. After a while, I was even asked "please, oversee X to ensure he doesn't create troubles", and my answer was "I have my own tasks to finish. I have no time to babysit anyone. And if I advise him, he doesn't listen, is piqued, and then complains to HR. Choose: we get rid of X, and I write the code when I can, or he writes the code but I won't accept any responsibility of it, nor I'll babysit him". After a couple of times they choose solution 2, and customers were not happy at all, and s**t started to hit someone above me, a couple of developers were moved to other roles...

      Also in many software companies that have promotion states, those reviewing the code before accepting into an "higher" branch are not usually those who have the expertise to properly review it. It may happen in some notable projects like the Linux kernel, but in other situations they are often less skilled devs (or even testers) checking only if the code does pass tests.

    6. Code For Broke

      @Denigor: I honestly can't tell if you are joking or not. Is this what they call the "dry British wit"? Because, honestly, have you even ever used a computer, or looked at source code?

  5. GrumpenKraut Silver badge
    Mushroom

    thermonuclear FORTRAN

    Approximately 11000 lines, all screaming capitals, no indentation. Of course no subroutines! About a hundred magic numbers, The program had 1 (one) comment in total, midway in, after a goto jumping almost 1000 lines forward. The comment read: "not needed".

    I warned the poor guy supposed to polish this monstrosity that he'd have a "window job": if you try this, you'll jump out of a window in despair. He left after spending eight weeks of trying with exactly zero progress. I was glad he did, as he looked unhappier every week and very much like a zombie near the end.

    Beat this.

    1. Androgynous Cupboard Silver badge

      Re: thermonuclear FORTRAN

      My first job out of university was an insurance broking system originally written in basic that had been automatically converted to C. Lots of fun stuff: I remember methods like b_streq(string1, string2) where 0 meant the strings were equal. Dozens of source files, each with a two or three methods several thousand lines long peppered with code like "goto b_2405" for flow control. Oh, and every variable was global, including loop counters, which meant every change had to be analyzed to see if the value of the variable was used later in the code without being reset.

      I don't recall if comments were included in the conversion, but I doubt they would have helped. Sadly I don't have any code from those days, otherwise I'd be submitting it.

    2. John Sager

      Re: thermonuclear FORTRAN

      The electromagnetic field modelling package NEC2 is a bit like this, though one part of the user manual does try to explain things. It uses magic numbers, particularly a high value (10,000) added to the segment number. Guess what happens when you have more than 9999 segments in a model...

      Of course the code was written in the days when a 9999 segment model would a) take far more memory than the computers in those days could handle and b) take longer than the age of the universe to run.

      Nowadays it's still used a lot by radio amateurs to model antennas so we run into these limits (amongst others in this package). I have hacked it to model up to 30k segments on Linux, but beyond that it runs into yet another, more fundamental limit.

    3. Anonymous Coward
      Anonymous Coward

      Re: thermonuclear FORTRAN

      I inherited some image processing code in my younger days when I was still a scientist. C++, written by a Pole who (when he commented at all) commented in phonetic Russian. Oh, and he really LOVED pointer arithmetic.

      Me, a polish - russian dictionary, russian - english dictionary and a great big bruise on my forehead from banging it on the desk. Pre-inernet (well mid 90s) so no online translation or anything else.

      I still wake up sweating occasionally!

    4. keithpeter
      Windows

      Re: thermonuclear FORTRAN

      @Grumpen

      "I warned the poor guy supposed to polish this monstrosity that he'd have a "window job""

      Honest question: would it not have been easier to find out what this thing did by running it with a variety of inputs covering most cases and simply re-code it? I mean is there a point where you just decide to start again with a (comparitively) small system?

      PS: I think we need a thread for code that has been kept in systems for decades but never run.

      1. GrumpenKraut Silver badge

        Re: thermonuclear FORTRAN

        This did run, it was a physics simulation of the most non-trivial kind. It was quite valuable to the department. Programmer had long left. There were _one_ _hundred_ magic numbers, and changing any single one simply broke things. As far as we saw the program was many different algorithms (entirely undocumented) made into one program. One could _guess_ what some places did, but no more than that.

        Re-writing the fucker would have been then plan, even though boss was delusional enough to think it could be tidied up in some way. But the value of the code was in the horribly convoluted variations of the (partly known) algorithms.

        Not a chance in hell.

        1. keithpeter
          Coat

          Re: thermonuclear FORTRAN

          @Grumpen

          "...it was a physics simulation of the most non-trivial kind....the value of the code was in the horribly convoluted variations of the (partly known) algorithms."

          Look for the notebooks. All the serious physicists I have worked with kept a notebook for each project. Everything went in the notebook and was dated. Theoreticals for claiming priority and keeping track of what you refer to as magic numbers (aka 'parameters') and the experimentalists just in case of little ...err... upsets(*) in the lab.

          (*) slide 25 makes especially instructive reading. Writing it down helps you think it through before modifying equipment...

Page:

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2019