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?

18 of 683 comments (clear)

  1. 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?

  2. 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
  3. 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
  4. 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.
  5. Re:Study Assignment by u.hertlein · · Score: 4, Insightful

    "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."

    This is so sad. He notices your code is faster and he's not the least bit curious? (I presume he's some kind of CS prof.) Anyway, good for you, but still... :-(

    --
    Geek by Nature - Linux by Choice.
  6. 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.
  7. Re:One word.. by zwei2stein · · Score: 3, Insightful

    Ewww.

    1) decent languages support labeled for/while cycles and apropriate "break label" constructs. It is not so different from using goto but has much better semantic meaning and thus allows neat optimalizations (with, say, paralelization in mind)

    2) if you do this kind of thing, you are MUCH better off separating lookup code to method or function and simply using return statement once you find it without having to break from cycles per se. Cleaner, more structured.

    --
    -- Technology for the sake of technology is as pathetic as eschewing technology because it's technology.
  8. 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.

  9. Wow am I the only one in here by Big+Hairy+Ian · · Score: 3, Insightful

    who just aims to get what is functionally absolutely needed finished & tested by the deadline? Bear in mind that most of my deadlines get set by clueless salesmen who even if they consult me generally tend to ignore what I say and tell the client what the client wants to hear.
    I haven't implemented a fully finished system by the deadline in years simply because I can't squeeze 3 months work into 1 month.

    --

    Build a Man a Fire, and He'll Be Warm for a Day. Set a Man on Fire, and He'll Be Warm for the Rest of His Life.

  10. Re:One word.. by FourthAge · · Score: 4, Insightful

    Hardly pedantic or lunacy. For example, pick one of the drivers from the Linux kernel, e.g. this one. Look in particular at the "geode_aes_probe" function.

    The structure looks like a pyramid. On one side is the setup phase, on the other side is the cleardown phase. If one of the setup operations fails, then the "goto" jumps to the appropriate cleardown operation and continues from there. If the top of the pyramid is reached, then return #1 (success) is used. Otherwise, return #2 (failure) is used.

    This function could be written in C without using goto. But would it be as easy to read and as easy to maintain? Doubt it. As it is, it's perfectly obvious what you would need to do in order to add a new capability to the driver. Tricks to work around "goto" would only obfuscate the functionality.

    --
    The tao of democracy: the government you can vote for is not the real government.
  11. Re:One word.. by 91degrees · · Score: 3, Insightful

    Surely you could do that as a nested if.

    Whether that is better or not is subjective. "Goto considered harmful" has become dogma, but while your example is a very good example of goto used well, most programmers would use it to write spaghetti code. Barring the use of the keyword means that it does only get used by people who know exactly what they're doing.

  12. 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.
  13. Re:One word.. by TheRaven64 · · Score: 3, Insightful

    Actually most exception handling constructs are even worse than goto, because they can unwind the stack an arbitrary amount. This is because they are taken from languages like Lisp and Smalltalk, which had accurate garbage collection and stack introspection and so could be used safely, and plonked into languages which have neither. In Java they're not too bad because you have to explicitly declare every exception that you can throw and so they become part of the interface, but they are horrendous in something in the C family. There's a nice Raymond Chen article where he writes the same bit of code with and without exceptions, and it's clear where the bug is in the exception-free implementation (error value ignored) but with exceptions it's very difficult to spot and the number of possible code paths grows alarmingly.

    Goto in C is not like goto in BASIC or many languages from the '70s and earlier, which was basically a higher-level wrapper around a jump instruction. In C, a goto statement is only allowed to jump within the current function, so it doesn't break structured programming too badly. Exceptions and longjmp(), do. Longjmp(), as it's traditionally implemented, is the worst because there is no way for any code in intervening stack frames to handle cleanup and so it's almost impossible to use without causing resource leaks of some kind. Non-local exceptions are almost as bad, because they hide multiple return paths. Sometimes it's cleaner to have two or three different return statements in a function, but with exceptions every single function call is a potential return path unless you wrap every single call in a try / catch block.

    --
    I am TheRaven on Soylent News
  14. 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;
    }

  15. Re:char Str[255] by dkleinsc · · Score: 4, Insightful

    I believe another name for that little snippet is "buffer overflow vulnerability".

    --
    I am officially gone from /. Long live http://www.soylentnews.com/
  16. Re:One word.. by Bakkster · · Score: 3, Insightful

    You use gotos when the normal control structures are inadequate somehow.

    This is the heart of the issue: control structures are a well defined, easy to follow, hard to fuck-up subset of the things you can do with goto. If you can do it reasonably with a control structure, you shouldn't use goto, because it makes your code more readable. If you can't, then you should consider if your program should be restructured (which is why goto is dangerous to novice programmers). If not, then you can use a goto.

    Of course, all bets are off when you're scraping for clock cycles with machine code, but that's not necessary most of the time.

    --
    Write your representatives! Repeal the 2nd Law of Thermodynamics!
  17. Re:Deadline is not the problem by russotto · · Score: 4, Insightful

    Nope. Deadlines are often unreasonable. Welcome to the real world. But as a good software developer, you should be able to cope with that too, and without last-minute hide-the-problem hacks.

    Wait, you were serious? Does your hair come to points on the side of your head, by any chance?

    If I could cope with unreasonable deadlines without some sort of nasty compromise, I wouldn't be developing software. I'd be turning water into wine, holding back the tide, etc. "Good software developer" doesn't mean "miracle worker". If the time isn't there before the deadline to solve the problem correctly, either the deadline will be missed or the problem will be unsolved or poorly solved. That's close to a tautology; it's implicit in the term "unreasonable".

  18. Not the only lesson by Jonathan · · Score: 4, Insightful

    Well, in part, but another important lesson in science labs is learning to report the truth, even if is disappointing and not what you want. This is an important lesson and unfortunately even some well known scientists don't learn it,