Slashdot Mirror


Dirty Coding Tricks To Make a Deadline

Gamasutra is running an article with a collection of anecdotes from game developers who had to employ some quick and dirty fixes to get their products to ship on time. Here's a brief excerpt: "Back at [company X] — I think it was near the end of [the project] — we had an object in one of the levels that needed to be hidden. We didn't want to re-export the level and we did not use checksum names. So right smack in the middle of the engine code we had something like the following. The game shipped with this in: if( level == 10 && object == 56 ) {HideObject();} Maybe a year later, an artist using our engine came to us very frustrated about why an object in their level was not showing up after exporting to what resolved to level 10. I wonder why?" Have you ever needed to insert terrible code to make something work at the last minute?

27 of 683 comments (clear)

  1. Here's one... by Quartz25 · · Score: 5, Funny

    Right before I left from Microsoft: int security = *NULL; // eat it!

    --
    Most people don't get why the integral of "e to the x" is so funny. Most math majors don't have a sense of humor.
    1. Re:Here's one... by pinkushun · · Score: 5, Funny

      Were you also responsible for #DEFINE RND_BSOD = 1 ?

  2. One word.. by consonant · · Score: 5, Funny

    GOTO :-) (or is that two..?)

    1. Re:One word.. by wilx · · Score: 5, Informative

      The goto statement is very useful. Your dislike of it is irrational. Do you even know why you do not like it? Often, goto is the best solution to given problem.

    2. Re:One word.. by Derleth · · Score: 5, Insightful

      Breaking out of a deeply-nested loop, as can happen when you’re looking for a specific element in a multidimensional array. The alternative involves adding state variables and complicating the logic terribly.

      --
      How can you use my intestines as a gift? -Actual Hong Kong subtitle.
    3. Re:One word.. by Derleth · · Score: 5, Insightful

      I’m a goto-user, but this is a bad reason to use them: If you regard language features as ‘just’ syntactic sugar, why aren’t you programming in raw machine code? That is what everything eventually gets turned into anyway.

      You use gotos when the normal control structures are inadequate somehow. It doesn’t matter what the compiler does; source code is for humans.

      --
      How can you use my intestines as a gift? -Actual Hong Kong subtitle.
    4. Re:One word.. by hairyfeet · · Score: 5, Interesting

      I like the way my former VB teacher put it (and yes I use the occasional GOTO, but then again I learned in the real BASIC-Commodore BASIC) he said "The GOTO is like a chainsaw. yes, some folks can actually make good things, and even make really nice carvings with a chainsaw. most just make a big fucking mess."

      Of course me and him both laughed our asses off when some 19 year old tried to rip off my code and pass it off as his own. After laughing and giving the kid a big F the kid said "How do you know that he didn't steal it from me?". So he asked the kid where he learned VB and which OS and the kid said "Windows 98 and the VB I got from this class!" and the teacher projected the code onto the board and said "Now class, does anybody notice something a little...weird about this code?" and a girl popped up and said "Why are their numbers before the lines, and what is a GOTO?".

      The teach just laughed and said "once upon a time their weren't any GUIs on personal computers. All you got when you turned it on was a blinking CLI and you had to write your own programs, using VERY old syntax. The person who wrote this is used to working in teeny tiny amounts of memory and using the old style, which works just fine if you know what you are doing, but if not it'll blow in your face like Mr. Greene found out when he tried to snatch this code and incorporate it into his own without knowing how it works" he then turned to me after staring at the code for a minute and said "Atari or Commodore?" and I looked shocked and said "Commodore VIC20, but how did you know that?" and he said "because I have been around long enough to have coded on just about everything, and that looked liked Atari or Commodore code. Very efficient, but about as subtle as a chainsaw." which is when he gave me the chainsaw quote.

      So I have never forgotten the chainsaw quote, and while I can wield the chainsaw without making a mess, I saw first hand when others in the class tried to use GOTO what a mess you can make if you don't know EXACTLY what your code is doing. He caught me outside a month later and said "thanks a lot, I hadn't seen a GOTO in ages and then you come along and it spreads like the damned clap. Giving these youngsters GOTO is like handing a monkey a sledgehammer and letting them loose in a bomb factory. There is no doubt they are going to go boom, the only question is when." but what can I say, I'm just an old greybeard that was used to numbered lines and GOTO.

      --
      ACs don't waste your time replying, your posts are never seen by me.
    5. Re:One word.. by FourthAge · · Score: 5, Insightful

      I'd agree with all of that. Like C itself, goto is a powerful tool that is easily misused by beginners, but is still very useful in the right circumstances.

      --
      The tao of democracy: the government you can vote for is not the real government.
    6. Re:One word.. by robfoo · · Score: 5, Insightful

      I can't figure out if I'm the only sane one or the only crazy one. Especially given the 'pyramid' referred to - I don't see a pyramid unless it's rewritten to use nested ifs.

      To me, nested ifs are much easier to read - they convey the meaning/intent of the code a lot better. As in 'if this function call works, then do this. Otherwise, just clean up and exit'

      How is this so hard to understand?

      geode_aes_probe(struct pci_dev *dev, const struct pci_device_id *id) {
              int ret;

              if ((ret = pci_enable_device(dev)))
                      return ret;

              if (!(ret = pci_request_regions(dev, "geode-aes"))) {
                      _iobase = pci_iomap(dev, 0, 0);
                      if (_iobase == NULL) {
                              ret = -ENOMEM;
                      }
                      else {
                              spin_lock_init(&lock); /* Clear any pending activity */
                              iowrite32(AES_INTR_PENDING | AES_INTR_MASK, _iobase + AES_INTR_REG);
                              if (!(ret = crypto_register_alg(&geode_alg))) {
                                      if (!(ret = crypto_register_alg(&geode_ecb_alg))) {
                                              if (!(ret = crypto_register_alg(&geode_cbc_alg))) {
                                                      printk(KERN_NOTICE "geode-aes: GEODE AES engine enabled.\n");
                                                      return 0;
                                              }
                                              crypto_unregister_alg(&geode_ecb_alg);
                                      }
                                      crypto_unregister_alg(&geode_alg);
                              }
                              pci_iounmap(dev, _iobase);
                      }
                      pci_release_regions(dev);
              }
              pci_disable_device(dev);

              printk(KERN_ERR "geode-aes: GEODE AES initialization failed.\n");
              return ret;
      }

    7. Re:One word.. by geminidomino · · Score: 5, Funny

      Pyramid? It looks more like the players' ship sprite from Galaga, rotated 90 degrees...

      Damn, now I want to play Galaga...

  3. University Assignments. by Anonymous Coward · · Score: 5, Funny

    Once I had an assignment due and at the last minute before being evaluated, realized I had made a huge mistake, even though the code looked OK...

    Too much time playing games in class and I was about to fail the course unit if I didn't pass that one test (right at the end of a semester)

    So I ran the program, adjusted the output in a word processor, saved it as a file and threw some code hidden in the comments that read the file, outputted it and exited.

    Three minutes later my code was evaluated... I was the only one who passed.

    Fortunately, no one investigated too carefully at the time why I was the only one who passed, because after trying to fix the code later in my own time, I realized the source data we were all supplied was corrupted.

    Inevitably, Later the same lecturer came to the same conclusion when his program didn't work either and cornered me to ask why mine worked (of course he was suspicious). Thinking quickly, I told him my source data was corrupted and that I fixed that first so my program would work. I don't know if he believed me, but he accepted the story.

    Fortunately, I got away with it and I got to keep the pass.

  4. Re:Wow. Talk about old news. by melikamp · · Score: 5, Funny

    The editor might have approved this submission just to meet some kind of deadline or a minimum requirement.

  5. Wrong question by julesh · · Score: 5, Insightful

    Have you ever needed to insert terrible code to make something work at the last minute?

    Wouldn't "have you ever shipped a product without needing to insert terrible code to make something work at the last minute?" be a more sensible question?

  6. Re:Wow. Talk about old news. by shish · · Score: 5, Insightful

    This is one of those stories where the story isn't the point, it's the comments that are worth reading, so it's only a problem if we have the same comments :-P

    --
    I mod down anyone who says "I will be modded down for this", regardless of the rest of their comment
  7. seen some bad shit. by Ziest · · Score: 5, Interesting

    I once worked at a Fortune 25 company in Chicago. They had this ENORMOUS mainframe program written in COBOL that ran their order inventory system which accounted for 20% of the companies revenue. All the guys who wrote this grunting pig of a system had either retired or had passed away. In the middle of the code was the following;

        *
        * We don't know what this does.
        * Please leave it alone !
        *
            SET INSIDE-INDEX TO 1.
        *
        * We don't know what this does.
        * Please leave it alone !
        *

    If this statement was commented out or removed the system stopped working. No one could find the problem. People had spent years looking for it but the code was such a mess and the documentation was so useless that they just left it alone and made a note that when the order inventory was re-done to make sure they left this "feature" out. I have been told that many old system have similar problems.
     

    --
    Another day closer to redwood heaven
  8. Re:Deadline is not the problem by 93+Escort+Wagon · · Score: 5, Insightful

    In the real world there are deadlines, and it's entirely the developer's responsibility to be able to meet those deadlines without using such "dirty coding tricks". Good developers should have tested their code so as to not have serious problems to fix at the last minute, and designed it so as to be able to extend it easily.

    Yes, because deadlines are always reasonable and never pushed up. And change orders are a myth.

    --
    #DeleteChrome
  9. Train simulation by LucidBeast · · Score: 5, Interesting

    Way back we had a project where we had to simulate entire train traffic entering Helsinki train terminal. Someone else had made the simulator and it ran pretty neatly, but unfortunately crashed mysteriously after about four - six hours of simulation time. Our customers were coming the on monday and I spent my sunday trying to figure out how this simulation worked and what crashed it. Finally I caught the problem, which was as simple as some null pointer to a train schedule or something similar which needed to be referenced. I couldn't figure out why it was null in time, so I just added test for null pointer, which skipped said code. Program ran fine and we got our money. Never figured out what was wrong with it. Luckily it was only a simulation.

  10. Study Assignment by LKM · · Score: 5, Funny

    This was a pretty important assignment back when I was studying computer science. It added to the final mark mark for that particular class. The task was to write a reasonably complex application in Prolog or some functional programming language, I can't remember which it was. I think the goal was to pair males and females based on their preferences, and find the optimal solution. Of course, I screwed up royally, and nothing worked five minutes before I had to demonstrate my solution.

    So in the final five minutes, I changed my code so it would avoid the parts which put it into an infinite loop, and instead simply output a random result. My goal was to tell the prof that it had worked a few minutes earlier, and that I didn't know what had gone wrong, and could I please have another week?

    So I demonstrated my app, it gave its random output, and I was about to start with my "damn, it used to work properly" spiel when he said (and this is actually true, even though it sounds unbelievable):

    "That's great! The result is correct, and your app is also quite a bit quicker than my own implementation of the problem. Congratulations, I think you're the only one so far who managed to get the correct result so far."

    I was so taken aback that I probably just stared at him for a few seconds. Then, I stupidly said "So... You want to see my code?" but he was like "No, the result is correct, and your implementation is very fast, so I don't need to see the code. Good job. Send in the next guy."

    And so I did.

  11. Example by Anonymous Coward · · Score: 5, Interesting

    Example?  Right here:
    #include <stdio.h>

    void    *f(void)
    {
    a:
        printf("Here!\n");
        return &&a;
    }

    int     main(int ac, char **av)
    {
        goto *f();
        printf("There\n");
        return 0;
    }

    1. Re:Example by 7+digits · · Score: 5, Informative

      OMG. I didn't even knew you could write that in C (and I have my name in the comp.lang.c FAQ...)

      Of course, I checked C99, and, no, you can't write that:

      3.6.6 Jump statements

      Syntax

                          jump-statement:
                                          goto identifier ;
                                          continue ;
                                          break ;
                                          return expression<opt> ;

      identifier being defined as:

      identifier:
                                          nondigit
                                          identifier nondigit
                                          identifier digit

      So, goto *f() is a no-no (as is probably &&a)

      But, anyway, wow. Gcc actually compiles that to something that somewhat runs...

  12. Re:Deadline is not the problem by oldhack · · Score: 5, Funny

    Slashdot sorely needs "douchebag" moderation.

    --
    Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
  13. Re:Wow. Talk about old news. by 7+digits · · Score: 5, Funny

    > it's the comments that are worth reading

    More specifically the comments in the article. I loved this one:

    "Back on Wing Commander 1 we were getting an exception from our EMM386 memory manager when we exited the game. We'd clear the screen and a single line would print out, something like "EMM386 Memory manager error. Blah blah blah." We had to ship ASAP. So I hex edited the error in the memory manager itself to read "Thank you for playing Wing Commander.""

    That's awesome.

  14. Re:yuck by quintesse · · Score: 5, Insightful

    Basically ALL the software you use works like this.
    Welcome to the real world, no need to feel bad.

  15. VB6: Lost source code - Ultimate repack by netsavior · · Score: 5, Interesting

    So it was 1999 and I was working for a mom and pop software shop, we had been acquired by a dot com. All our money and toilet paper stock options were held until we delivered the re-branded product with source. Part of the "rules" said we had to have only C/C++ and VB6 source, NO OTHER LANGUAGE.

    . We finished converting a few rogue scripting modules and things like that, which creep in over time. But we COULD NOT find the source code to one of our VB6 DLLs (an old one that had not been changed since it was first compiled in VB6). We searched and searched and eventually the fastest coder(not me) started rewriting it. We were 1 day from delivery date and there was no way he could finish it, so I ran it through a disassembler.

    the C++ code we delivered looked like this:

    int functionName(int parm) {
    _asm {
    push esi
    mov esi, dword ptr ds:[esp+8]
    mov dword ptr ds:[edi], esi
    retn
    }
    ....(you get the idea)
    It was unreadable, but it compiled and worked and we got our money. I still wonder what they ever did with that... since the software is still in use...

    1. Re:VB6: Lost source code - Ultimate repack by mrwolf007 · · Score: 5, Funny

      Yeah, just think what those guys thought when they saw the code.
      "Wow, assembler code."
      "It must be highly optimized."
      "Told you it was a good idea to buy it."

  16. Re:Here's another one... by Tuna_Shooter · · Score: 5, Interesting

    This is the code for the Apollo 11 lunar lander flight computer.

    http://code.google.com/p/virtualagc/source/browse/trunk/Luminary099/LUNAR_LANDING_GUIDANCE_EQUATIONS.s?r=258

    and yes some of my code is in there along with the equivalent of a few "goto's

    Lots of bright people worked on this and in some circumstances a "goto" is required.

    --
    *--- Sometimes a majority only means that all the fools are on the same side. ---*
  17. The Fucksort Incident by ari_j · · Score: 5, Funny

    Back in college, we were at a programming competition and I was the on-the-keyboard coder for one of the problems. We had 10 minutes for the problem and I coded it quickly, having decided on the best algorithm before sitting down. Part of the solution was a sorting routine on a list. We were using Visual C++ although we were all not C++ experts at the time, and so rather than mess with the STL and the possibility of having to read documentation, I did it all from scratch. I knew that sort was already in use by the standard library, so I called my routine mysort.

    Apparently, however, Visual C++ includes a mysort in its standard library. So, with the clock ticking down and the solution's only impediment to our victory being an identifier conflict, I renamed the routine the way that any one of us would have: myfuckingsort. We won the competition.

    In this particular competition, the judges were not supposed to read our code - they just run the output of your code on the input and check for correct output - so I felt safe when I typed what I did. However, one of them came up to us afterwards and told us that they do in fact usually read the code of the winning team to see if we did anything unique in our solution. Yep. Sure did. And my classmates and professors never did let me live down what was affectionately nicknamed the fucksort algorithm.