Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Programming Entertainment Games IT Technology

Dirty Coding Tricks To Make a Deadline 683

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?
This discussion has been archived. No new comments can be posted.

Dirty Coding Tricks To Make a Deadline

Comments Filter:
  • by Quartz25 ( 1195075 ) on Wednesday August 26, 2009 @01:43AM (#29197439) Homepage
    Right before I left from Microsoft: int security = *NULL; // eat it!
  • One word.. (Score:5, Funny)

    by consonant ( 896763 ) <shrikant.n@nOspAM.gmail.com> on Wednesday August 26, 2009 @01:47AM (#29197461) Homepage
    GOTO :-) (or is that two..?)
    • Re:One word.. (Score:5, Informative)

      by wilx ( 1065624 ) on Wednesday August 26, 2009 @02:12AM (#29197633)

      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.

      • Re: (Score:3, Informative)

        by Aladrin ( 926209 )

        I have not used a 'goto' statement in about 15 years now. But it's not some irrational fear. It was all due to someone saying 'there's no situation that requires a goto' and 'goto statements make code hard to read'.

        And after I used goto a little more, I realized they were correct. In any good, modern language, 'goto' is completely unnecessary and makes your code harder to read.

        If you're breaking out of a loop, you should use 'break'. If you're continuing a loop, 'continue'. If you're handling an error,

    • by krischik ( 781389 ) <krischik@users.sourc e f o r g e.net> on Wednesday August 26, 2009 @02:33AM (#29197771) Homepage Journal

      Have you ever wrote a function / procedure with more then one return statement? Or used break or continue in a loop? Then you can use goto as well. From a structure point of view goto, break, continue and return are all unconditional jumps. They are one of a kind. And looking back in retrospect: Since goto need to be paired with a label it's the least evil of the group.

      Note that Pascal the archetype of structured programming had goto but it did not have break, continue or return.

  • by buswolley ( 591500 ) on Wednesday August 26, 2009 @01:51AM (#29197479) Journal
    VBA
  • Balancing act (Score:4, Interesting)

    by Tubal-Cain ( 1289912 ) on Wednesday August 26, 2009 @01:51AM (#29197489) Journal
    If you have short deadlines, you end up with issues similar to the bugs Ubuntu needs to smooth out every release. If you go with "It'll be finished when it is finished", Your stable releases can become ridiculously out of date between versions. Debian did a good thing by abandoning the open-ended release cycle in favor of the extremely long but predictable two-year deadlines.
  • by Anonymous Coward on Wednesday August 26, 2009 @01:59AM (#29197539)

    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.

    • by consonant ( 896763 ) <shrikant.n@nOspAM.gmail.com> on Wednesday August 26, 2009 @03:59AM (#29198363) Homepage

      Similar story.

      In one of my "Intro to C" mid-term exam, one of the (sit down in the 'puter lab and spew code type) assignments was a simple string manipulation exercise. After I was done with the program, while sitting around waiting for the output-verifying lab drone to come over to my place, I noticed all she was doing for the other folks with the same assignment question was key in the same series of words as test inputs. I saw this, and quickly whipped up another little program that basically displayed a prompt, and did a printf("{hard-coded desired output for same set of words}"); and ran this piddly little pile of 'code' when she stopped by my machine.

      Sadly, I passed..

      • by Aladrin ( 926209 ) on Wednesday August 26, 2009 @05:57AM (#29199017)

        You laugh, but that's the basis of 'Test Driven Design'. :D You were only supplied with 1 test, and you passed it. Had their been more tests, your code would have had to be what was really wanted.

        I've started to think about how a class could be run like that... Create a series of unit test sets that progressively test more of the program. For each assignment, give the students the next set of tests and have them code to make the tests pass. In the next class session, work to show everyone how to make it happen, then give the next set.

      • Re: (Score:3, Interesting)

        by GTarrant ( 726871 )
        In one of my ASIC design classes, it was practically impossible for the professor to really go through everyone's design and ensure that they all worked properly - they were far too complicated. Likewise, it was difficult for students to ensure, while designing things, that the chip itself also worked as intended, because it was an error correction algorithm being implemented, so you had to sort of KNOW what a desired output would be. So the professor gave a sample input, and the intended output for this
    • > 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...

      I once did almost the same thing, except that I wrote the entire assignment the first day we got it, during class. But I couldn't turn it in yet. And nearly forgot about it. So I turned it in at the last minute...

      Except that I had misread the specification! Oh, the program worked just fine, but it printed everything to the screen. It was *supposed* to go

  • Wolf 360 hack (Score:4, Interesting)

    by anss123 ( 985305 ) on Wednesday August 26, 2009 @02:06AM (#29197599)

    The deadline is looming, I can't spend much more time on this. So, I did the unthinkable -- I packed the controller id into the pointer parameter. I marked it as a horrible hack in a 4-line all-caps comment, and checked it in.

    Does not sound so horrible, just make sure the 1,2,3,4 pointers never point at anything "free()"able and it'll work fine.

    BTW, is that Wolf 360 game out?

    • Re: (Score:3, Funny)

      by andy_t_roo ( 912592 )
      my favorite hack is doing object click detection by rendering objects in a function pointer (4 byte pointers, rgba colour buffer .... ) -- when you click, a render pass is done with no lighting, effects, ... , and with each object coloured according <rgbaColour>object->onClick. To act on a click, read of the colour of the pixel under the mouse, and call it :)

      (oh, and solaris lies about giving you rgba -- it only gives you rgb -- my code would work on one of the uni servers, but not on another)
  • Wrong question (Score:5, Insightful)

    by julesh ( 229690 ) on Wednesday August 26, 2009 @02:07AM (#29197601)

    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?

  • Never (Score:4, Funny)

    by ChienAndalu ( 1293930 ) on Wednesday August 26, 2009 @02:09AM (#29197617)

    My boss however *only* does coding tricks. And he puts them in one big 1k line function.

    And is proud of it.

  • by Anonymous Coward on Wednesday August 26, 2009 @02:14AM (#29197645)

    When my deadline comes up and I haven't produced I wait for my boss to ask me for the code then I sucker punch him and run away. The trick is to hold down short term contracts and give false references and hire someone to back them up (another dirty trick). That also makes it easier to dodge the cops when your boss presses charges. It's getting harder though with all this talk of test driven development and short incremental releases. Then the trick becomes to write the most meaningless trivial unimportant tests first - but crucially tests that you can make pass quickly so you don't have to do any real work.

    (For anyone insane enough not to realise it, this is a joke. Don't try this at home...or at work).

  • Game Art (Score:5, Interesting)

    by j-stroy ( 640921 ) on Wednesday August 26, 2009 @02:32AM (#29197759)
    A 3d model export would break regularly screwing up the texture map orientation on certain polygons. The godawful export couldn't be fixed on the deadline, and risk management said best not to touch it cuz EVERYTHING might bust, let alone all the coders being nailed to the wall by the ship date. So I fixed the model files in an ascii editor. All the art builds that had tweaks needed this "touch" Since it was a hockey game, you can imagine how many goalie pads that was. Oh yeah, you couldn't see if the fixes were correct except in the game engine after more pipeline.

    Technically not a code fix, but still a valid solution.
  • seen some bad shit. (Score:5, Interesting)

    by Ziest ( 143204 ) on Wednesday August 26, 2009 @02:33AM (#29197765) Homepage

    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.
     

    • Even worse stuff! (Score:5, Interesting)

      by syousef ( 465911 ) on Wednesday August 26, 2009 @04:09AM (#29198415) Journal

      Some of the worst I have seen:

      In critical C code:

      if (some condition)
              i *= 0;
      else
              i *= 1;

      And I was the actual variable name.

      Even worse, on a different project, an Easter egg that told the user their hard drive was about to be erased, and another that popped up about 30 dialog boxes full of banter between Spock and Kirk. Worst of all this code written in VB and was licensed for megabux then we got hold of it for orders of magnitude more megabux (Most of the original coders were hired fresh out of highschool). It ended up being rewritten (thankfully NOT by me) but we had to get the source to work out how it worked in the first place.

      I wish I was making this up.

  • Train simulation (Score:5, Interesting)

    by LucidBeast ( 601749 ) on Wednesday August 26, 2009 @02:50AM (#29197863)
    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.
  • by LKM ( 227954 ) on Wednesday August 26, 2009 @02:55AM (#29197887)

    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.

    • by u.hertlein ( 111825 ) on Wednesday August 26, 2009 @03:09AM (#29198001)

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

      • Prolog Assignment (Score:5, Interesting)

        by becker ( 190314 ) on Wednesday August 26, 2009 @04:21AM (#29198469)

        That's completely understandable in this case of programming in Prolog.

        Prolog is a declarative language.

        You declare the rules, and the system figures out a result that matches those rules.

        The problem is that this basically doesn't work. So a Prolog programmer has to write the "declarative" rules in a procedural order so that the run-time system doesn't have to try every possible combination to find (or fail to find) a matching result.

        The proper ordering of declarations can be quite subtle. With a modestly complex program you can make a seemingly unimportant change in the order of the declarations and have the runtime go from a second to a week.

        In this case the professor didn't (couldn't) know how long a Prolog program to solve this problem should take. He just assumed that you had found a more efficient ordering for the declarations. He might even have thought it was luck rather than deep insight that your program was faster than his. But you have to a decent understanding of the limits of Prolog to get a complex program to complete in a reasonable time, so you had to be good before you could get that lucky.

        If you couldn't already tell, I have a low opinion of Prolog and declarative languages. They are "parlor tricks". Much like computer 'Life' and neural networks, simple programs can produce unexpected seemingly-sophisticated results. But they don't get better from those initial results. To compute the answers or results you want in a reasonable time, you end up with at least the complexity of writing things in the traditional explicitly procedural method.

        The promoters of declarative language typically don't mention that you end up writing rules in an explicitly procedural order if you want the program to work. If you press them on the issue, they then say "well, OK, it's not actually any easier to write, but it's easier to verify that you've correctly specified the desired result." But if you have to carefully shuffle declarations around, and even then some results unpredictably take centuries to compute, pretty much no one cares.

  • by Anonymous Coward on Wednesday August 26, 2009 @03:04AM (#29197957)

    I worked with some finance guy who was convinced that the square root of a negative number -x was -sqrt(x), and wouldn't hear otherwise. I hacked sqrt(x) to return sgn(x)*sqrt(fabs(x)), but he complained that when he squared the answer, he didn't get back a negative number. Luckily our code was C99 so I changed his dollar type to be "double complex", made him use the complex sqrt, and changed his print function to display creal(x) - cimag(x). The guy said things worked great. I was glad to hear that, but it still feels wrong that part of our finance system is handling complex number of dollars, whatever that means.

    • Re: (Score:3, Funny)

      by Xenographic ( 557057 )

      > I was glad to hear that, but it still feels wrong that part of our finance system is handling complex number of dollars, whatever that means.

      What? I'm sure most finance guys are adept enough at counting both real and imaginary dollars, so having complex dollars isn't really that complex...

  • Who hasn't? (Score:5, Funny)

    by Opportunist ( 166417 ) on Wednesday August 26, 2009 @03:29AM (#29198139)

    After years of programming, I guess everyone had to cut some corners sometimes. It's also not (always) a problem of goofing off, a module you depend on not shipping in time but you being required to keep your deadline can already force you into doing just that: Delivering a hack that 'kinda-sorta' works, or at least the customer won't notice 'til we can ship the patch.

    Yes, that happens often. It's dubbed "Bananaware". Delivered green and ripens with the customer.

  • by FranTaylor ( 164577 ) on Wednesday August 26, 2009 @04:23AM (#29198481)

    it made a total hash out of what I was trying to do. But he lost the source code, so I couldn't prove that he did it. Of course we couldn't fix it either. It was in code that calculated people's paychecks. He got fired. I quit.

  • by Big Hairy Ian ( 1155547 ) on Wednesday August 26, 2009 @04:50AM (#29198653)
    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.
    • Re: (Score:3, Interesting)

      by wrook ( 134116 )

      Here is my strategy for dealing with this situation:

      1) Tell the salesmen that you have absolutely no problem with them telling the customer whatever they want. Their function is to make sales to customers. Your function is to write software. You won't try to tell them how to do their job, because quite frankly you aren't qualified to know what's best for sales. Of course the implication is that they shouldn't tell you how to write software, but you probably don't have to tell them this explicitly (well,

  • Customers (Score:3, Insightful)

    by CarpetShark ( 865376 ) on Wednesday August 26, 2009 @05:11AM (#29198781)

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

    Yes. But mostly it's not to "make it work"; it's because the customer wants something that is entirely against the original design they asked for.

  • char Str[255] (Score:3, Informative)

    by dargaud ( 518470 ) <slashdot2@gd a r gaud.net> on Wednesday August 26, 2009 @05:47AM (#29198957) Homepage
    My worst shortcut is to use fixed-sized strings with non size limiting functions, as in:
    char Str[255];
    sprintf(Str, "%s, %s", Lastname, FirstName);
    I really wish snprintf was available on my C implementation.
  • Configurable sleep() (Score:3, Interesting)

    by Get Behind the Mule ( 61986 ) on Wednesday August 26, 2009 @06:15AM (#29199103)

    So we had a race condition on database transactions using two-phase commit, your usual mind-fucking WTF situation, drove us up the walls for days, you all know what I mean. We knew it was a race condition because if we put a sleep() statement at the end of one of the transactions, everything ran fine. sleep(10) was always long enough, and since all of this ran asynchronously in the back end, an end user would never notice the difference.

    So we went to the customer. We told them that we could continue to bust our brains trying to find a "real" fix, and didn't know how long that would take, or we could just leave the sleep() in. And we could even make the length of the sleep interval configurable, so they could try to make it shorter than 10 seconds, if they really felt like fiddling around with it.

    The customer went for the configurable sleep().

  • by netsavior ( 627338 ) on Wednesday August 26, 2009 @06:24AM (#29199153)
    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...
  • by selven ( 1556643 ) on Wednesday August 26, 2009 @07:20AM (#29199521)
    I always just hard-code all my levels - it's easier to just go back and recompile (which takes 15 seconds in C or 0 seconds in python) than code all the extra logic in for reading from files. As another plus, this makes it harder for other people to cheat. Speaking of cheating, once I called my player save file "makefile" to discourage people from looking at it or modifying it.

    And, I never split my code into multiple files - scroll and Ctrl+F were good enough for my grandfather, and they're good enough for me!
  • by ari_j ( 90255 ) on Wednesday August 26, 2009 @07:51AM (#29199897)
    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.

It's a naive, domestic operating system without any breeding, but I think you'll be amused by its presumption.

Working...