Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
It's funny.  Laugh. Programming IT Technology

How To Write Unmaintainable Code 437

An anonymous reader writes "Make sure you're irreplaceable -' In the interests of creating employment opportunities in the Java programming field, I am passing on these tips from the masters on how to write code that is so difficult to maintain, that the people who come after you will take years to make even the simplest changes. Further, if you follow all these rules religiously, you will even guarantee yourself a lifetime of employment, since no one but you has a hope in hell of maintaining the code. Then again, if you followed all these rules religiously, even you wouldn't be able to maintain the code! You don't want to overdo this. Your code should not look hopelessly unmaintainable, just be that way. Otherwise it stands the risk of being rewritten or refactored. '"
This discussion has been archived. No new comments can be posted.

How To Write Unmaintainable Code

Comments Filter:
  • by rolfwind ( 528248 ) on Monday November 21, 2005 @12:43PM (#14082438)
    but why would you want to burden yourself by being bound to a program for the rest of its useful life?
  • by mymaxx ( 924704 ) on Monday November 21, 2005 @12:45PM (#14082455)
    Wow, I couldn't disagree with you more. This is an excellent....joke! Lighten up!
  • Re:missing icon? (Score:3, Interesting)

    by gbjbaanb ( 229885 ) on Monday November 21, 2005 @12:46PM (#14082471)
    Well, it did mention Java so it must be full of new funny ways you can break Java coding styles... forget that it contains references to all the old bad programming jokes from years past - eg. one section describes where the compiler only recognizes the first 8 characters so use_unit_update is the same as use_unit_setup.

    Its an old joke. with a new header. That's all. Next submission please.
  • Growth (Score:5, Interesting)

    by TheRealFritz ( 931415 ) on Monday November 21, 2005 @12:48PM (#14082500) Homepage
    I've heard fellow programmers suggest this before, but the way I see it, you are hurting yourself and here's why: when you become an absolute specialist in one area (in this case your particular implementation), you will be pigeon-holed into this role with no chance for growth.

    A much better approach to job security is to adapt to the needs inside the company and make sure your skills are needed. This will also lead to more opportunities for pay increases and general healthiness of your psyche.

    In the end, what makes you interesting as a developer should be your ability for problem solving and not your ability to obfuscate your work, unless, of course, your intention is not to work ;)
  • by Beatbyte ( 163694 ) on Monday November 21, 2005 @12:56PM (#14082584) Homepage
    if the program is utilized at a level that a business cannot operate without it, then you are forever a needed man/woman/slashdot reader.

    it's a dirty way to have great job security.

    i'm not sure what would make it harder to sleep at night... knowing that there are outsources ready to take your well maintained project over and remove your source of income, or knowing that you're intentionally putting effort into making a project complex and making a sort of symbiotic leech relationship with your employer.

    if i were a programmer full time, i would like to think that there are other ways i could have 100% job security and keep my geek pride.

  • I can. (Score:5, Interesting)

    by Ungrounded Lightning ( 62228 ) on Monday November 21, 2005 @01:05PM (#14082686) Journal
    I can't think of a single occasion where someone was kept because of fears of maintaining their code, nor where someone was brought back to maintain their 'unmaintainable' code.

    I can.

    My very first programming job - which went on for years and where I did a bunch of stuff - but was quite underpaid. There were two of us programming when the institution in question had a financial crisis and could only keep one. My code was maintainable, the other guy's wasn't. So I got the boot.

    And had a new job at higher pay in a better situation 25 minutes after letting it be known that I was available.

    Before it was a matter of writing code that *I* could maintain. After it was a matter, not just of principle, but of practicality. By making myself NOT indispensible I made myself valuable.

    I went on to a long carreer of mixed consulting and salaried positions, doing software for 35 years, and now hardware and system architecture. (And I once got the layoff because my code was the only stuff that worked, if you can imagine that. From another doomed company.)

    The potential value-added in software and computer hardware has been so extreme that management can be AMAZINGLY pathological and still keep a company afloat for a couple years - and then find another job after it crashes. (Investors prefer someone with management experience crashing companies to someone with talent but no management experience. B-( Meanwhile the ones with management experience NOT crashing companies are too expensive or too busy.)

    I'm now at six figures, stock options, one house paid for and another in progress, three cars, yacht, putting non-working (at the moment) wife with four degrees so far through more school (so she can do something she LIKES professionally), and held on to the current position through the slump, chapter 14, and out into the recovery. A big part of that was achieved by religiously making myself dispensible.
  • Re:not how it works. (Score:2, Interesting)

    by Billosaur ( 927319 ) * <wgrotherNO@SPAMoptonline.net> on Monday November 21, 2005 @01:13PM (#14082764) Journal

    Exactly. I was the indispensible guy, the only person doing my job for 3 1/2 years. You needed it done, I did it. Mind you it was stressful being the only resource, but I was getting paid good money.

    Then one day the head honcho was reviewing the budget and determined that I was being paid way too much for what I was doing, and whacked me out of the budget with his red pen. Result: I lose a good job and am replaced by a Canadian programmer, who works far cheaper than I do. [Note: I am not denigrating Canadians; I am an avid Rush fan. And this guy had skills.]

    So now my code is being maintained by someone else, and he's having a much easier time than I was, because I so thoroughly documented everything I did. This article may be meant to be tongue-in-cheek, but it really points out the state of the inustry right now. Those of us with decent skills are being phased out in turn, replaced by lower-paid and often poorly-skilled labor, simply to save a buck. And if it takes the new guy an extra 6 months to figure out the code, so what? He's getting paid next-to-nothing for it, so it doesn't cost the company much. And who knows? The cheap new guy may do all the documenting for them, just in time to be replaced by the newer, cheaper guy.

  • by digidave ( 259925 ) on Monday November 21, 2005 @01:18PM (#14082815)
    Right now I have to maintain an unmaintainable web app. Let's put it this way...

    - This app was originally written in PHP/FI 2.0 in 1997. There were also some C cgi apps and a few Perl scripts.

    - Due to performance problems the entire dynamic site was changed to a statically rendered site, so after changes were made to a page that page was rendered as an HTML file.

    - In 2000 it was updated to PHP 4 and the app had a core feature bolted on, essentially confusing the difference between a city and a county. This resulted in a worst DB design I've ever seen. I'm talking about splitting up core pieces of data that need to be together, using ambiguous field names (rid means different things in different tables. Some tables relate to each other on field names that seemingly have nothing in common. Some field names have typos, etc).

    - The code was written first by a team of six programmers, then by a smaller team of three other programmers and finally by some weird guy who I was supposed to work with when I got hired, but a few days before I started he decided he didn't like computers anymore and he went into the grow-op business instead. My boss claims that maintaining the horrible code base made him go crazy and I'm inclined to believe that.

    - Two records in the same table of the database may look the same in all ways, but they are actually entirely different things. The only way the app knows which one to use where is because that data's unique id is hard-coded into the app.

    - I am rewriting our site search engine from scratch because touching the old one is dangerous. Altering small harmless-looking bits of code can actually break unrelated pages, but that breakage isn't noticed until that other page is re-rendered into a new HTML page, so I was finding out about problems weeks after I caused them. Arrrg!

    - I have been unable to get the app working on any server I have setup. If the live server goes down we're toast because there is no dev box. The app relies on a horrific web of interconnected scripts, cron jobs, strange directories, and it even uses an older version of itself to perform some mysterious actions. I've got an image of the server's hard drive I can use to recover it from.

    I have finally convinced my boss that this thing needs to be rewritten *now*. It's a house of cards with our business resting on top.
  • by Geek Dash Boy ( 69299 ) on Monday November 21, 2005 @01:19PM (#14082822) Homepage

    Thankfully, the OP provides a link to the original author, Roedy Green.

    Here's another good article he wrote in the same vein called How to Code like a Newbie [mindprod.com].

    I was in stitches the first time I read it several years ago.

  • by rewinn ( 647614 ) on Monday November 21, 2005 @01:28PM (#14082912) Homepage

    ... for enforcing the Corporate Coding Standards.

    In a rational world, Corporate Coding Standards, enforced by code reviews, would have something to do with maintanability. In some organizations, they are ... probably those that live or die by the quality & maintainability of their code.

    But quite the opposite was true in the large insurance company (nearly 1000 programmers alone) where I held my last salaried programming gig. Their Coding Standards were all about Not Rocking The Boat. They included several elements of "How To Write Unmaintainable Code" as Enforcable Standards. Remember when "Structured Programming" was a new idea? I got me bottom kicked for arguing that coding units should not end with a wholly unnecessary "Go To End" ... because the STANDARD was that ALL modules exits were via "Go To End".

    Fortunately, their coding quality algorithm had to do with number of lines of code changed ... again, nothing to do with actual quality. Deleting redundant code merely enabled me and the software to work faster & better, which did not count as quality. When I learned to comment out redundant line, so they counted as "lines changed", my coding quality scores vastly improved!

    Perhaps the insurance industry is so darn profitable that optimizing its software is not nearly as important as maintaining internal discipline. The ideal employee was the scion of two current employees who had met in the cafeteria, and was engaged to another employee who they'd met the same way (I Kid You Not!) If these programming methods imposed excessive costs, they just upped their premiums.

    It was a soul-destroying experience.

  • by advocate_one ( 662832 ) on Monday November 21, 2005 @01:34PM (#14082968)
    The principle is clearly that if you can do absolutely everything in 20 indecipherable characters, your code will never need to be maintained.

    no, you'll just be replaced by a genetic algorythm with a random input for seeding, then let loose to select for the desired behaviour.

  • by LordWill ( 611759 ) on Monday November 21, 2005 @01:59PM (#14083170)
    My niece's boyfriend seemed to think he could get security like this by being the only network guy to know the passwords to the company's routers.

    I had to point out that if he had a boss who would not know why such a situation shouldn't exist would probably also not know why the network guy shouldn't be laid off.
  • by Jboy_24 ( 88864 ) on Monday November 21, 2005 @02:42PM (#14083602) Homepage
    When writing a method that will do_something. Ask yourself, is this really the place to do that? Maybe you're being a little too forceful to do it right there?

    Perhaps you should create an interface (make it an inner interface to a public static inner class, yes its possible).
    Make sure you use a common naming convention so you can look up the class using Reflection.
    Then once you get your class, make sure you use another factory to get the class you feel comfortable to finally do something.

    Finally, put your "do_something" code in the constructor of the class.

    When your code base becomes 1,000,000 lines of this, you'll achieve the final Zen obfustication moment, when a new director of engineering asks you to document this and you can say, with a straight face, and in total honesty, "Its too complex to document"

                     
  • by Flyboy Connor ( 741764 ) on Monday November 21, 2005 @02:43PM (#14083614)
    Such bad code actually exists.

    For five years I worked for a boss who was in the habit of taking jobs that nobody else wanted. The good thing was that he would get paid a lot. The bad thing was that I had to dabble in unmaintainable code. At one time I even had to make changes in a program for which no source code existed anymore. That was not the worst job, though. The worst was a change I had to make to a program that had the simple task of printing a list of articles in stock, with their locations. It printed the articles in two columns: the left column contained articles of types 1 and 2, and the right column contained articles of types 3 to 9. I had to change the program so that it would print three columns: left column the same, but the right column split into types 3 and 4, and 5 to 9. Does not sound too difficult, right? I mean, even without looking at the code, purely knowing the function of this program makes you think "that should been done in no more than 2 hours."

    It took me two weeks. The program was peppered with functions that were copies of other functions with a very small change. The original programmer used ridiculous methods to fill print lines. The general way of printing a line is collecting information through a central function, and when that function has all the information it needs, print the line. In this case at dozens of points in the program the programmer tried to predict whether or not he would have enough information to print a line, and then do it. If I would have a design document, I would have rewritten the program from scratch, but of course no such document existed.

    Every little change I made to the program had unforeseen effects. When I started, I had (of course) made a test-print, which I could use to compare outputs. I made a small change, and suddenly the list contained less articles than the original list. Another small change, and suddenly the list contained more articles than the original list. I tried to assess what reasoning the program would use to include or exclude articles, but there was no way to determine that from the code.

    After two weeks of work the program printed three nice columns, with all the original articles there, and a few, very few, that were not on the original list. I could not understand why these extra articles were there, but if they should not be there, I thought it would be best if I would just implement a condition to exclude them, if I would know what that condition should be. So I called the company who used the programs and asked them about these extra articles. Their answer was, "My God, we have been missing those for YEARS. Now we'll finally be able to find them again."

  • Re:I can. (Score:5, Interesting)

    by TilJ ( 7607 ) on Monday November 21, 2005 @02:50PM (#14083681) Homepage
    Exactly. What many posters don't seem to realize is that if you make your irreplaceable, you've also made it impossible to be promoted. This isn't just internal to your current organization -- doing the same thing for year after year without making career progress looks like hell on a resume.

  • by Gruneun ( 261463 ) on Monday November 21, 2005 @03:19PM (#14083934)
    I can't think of a single occasion where someone was kept because of fears of maintaining their code, nor where someone was brought back to maintain their 'unmaintainable' code.

    I can. In fact, I can think of two people at two different companies.

    One kept the only copy of his source code on a laptop that he carried with him. The code was so horribly unmaintainable that none of us would touch it, though it was hardly an issue since we rarely got more than the pre-compiled libraries from him. The boss was so scared that he would lose the source that he falsified and submitted timecards for almost three months when the guy decided he was "unappreciated" and stopped coming to work. It goes without saying, but this manager was just as incompetent. In fact, I'm convinced the only reason either one survived as long as they did was through their symbiotic, parasitic relationship.

    The other guy put his code through an obfuscator, literally, that removed all the indentation, carriage returns, and comments, meanwhile renaming all of his class, method, and variable names to random strings of the characters n, e, and w. It also added random comments made up of the same random strings sprinkled with semicolons. Yeah, cute. During the unemployment interview, he stated that he had fulfilled his requirements, the code compiled and worked, there was never a formal standard for the format, and he couldn't be held responsible for the additional work of his former co-workers. I think what clinched his unemployment benefits was stating he had no hard feelings and maintaining that he was available for consulting work if the company had acted too quickly.
  • I can, too (Score:5, Interesting)

    by BaudKarma ( 868193 ) on Monday November 21, 2005 @03:42PM (#14084148) Journal
    I worked security at this place while I was going to school. Think mid '80s

    They had won a contract from a major hotel firm to design and run their reservation system. The whole system was written by one guy, who by all accounts did an absolutely superhuman job. Of course, the company had to choose whether they wanted the job documented well, or completed by deadline. You can guess what they chose.

    Our hero stays busy for a few years, maintaining code and writing new modules, but there are still a long row of empty loose-leaf binders where the documentation should be.

    Company gets bought out. After a couple of months, the new owners announce that they're going to rewrite the whole reservation system from scratch, and retire the old system. Our hero comes in next day and demands a large raise. Management declines, hero gives his two weeks, and management cuts him his check and escorts him out the door.

    Management then brings in a team of consultants to keep the old system up and running until the new system is ready. Problem is, the team can't get anywhere. Nothings documented, calling the code "spaghetti" would be a compliment, etc etc etc. Meanwhile, they're getting requests from the customer for changes and updates which they can't process. In addition, system crashes now take hours to solve instead of minutes, which is bad because part of the companies revenue is based on system uptime.

    After a few weeks, management finally throws in the towel, and realizes they'll have to bring the guy back and pay him what he wants. Except... they can't find him. He's moved, and left no forwarding address. Nobody knows where he is.

    Management had to hire a private detective to track the guy down, and they finally found him up in the mountains in Colorado, doing whatever. They convinced him to come back, but I wouldn't want to be managements negotiator in that meeting.
  • by OverflowingBitBucket ( 464177 ) on Monday November 21, 2005 @06:04PM (#14085433) Homepage Journal
    I worked at a company that had let it slip that they were taking metrics on number of lines of code submitted to the revision control system. This was a directive from the higher-ups, so of course against all logic the next line of management down from them (and above me) went along with it blindly. I tried to argue about the uselessness of such metrics to deaf ears. So, being me, I decided to have a little fun with this.

    One section of the code consisted of a number of modules that were basic copies of each other with small local customisations. Think hundreds or thousands of lines in common. No, I didn't write them, but I had to maintain them. So I took these, pulled out some code into common libraries, and wrote a code generator to produce much of the rest from input files. I was also careful to work on non-coding tasks for the remainder of that week; essential stuff but the sort that had been put off for a while. My net code contribution that week: Negative several hundred lines of code. The code also became infinitely more maintainable, and I fixed countless copy/paste bugs in the process.

    No doubt someone fudged my negative figure upwards when it went back up through the management chain to avoid rocking the boat, no doubt to a nice small number of positive line chances to ensure I looked bad. But, if only to myself, I had proved my point.
  • by Midnight Thunder ( 17205 ) on Monday November 21, 2005 @07:59PM (#14086481) Homepage Journal
    Have you ever tried to hire that One Smart Person? Hell, even if s/he existed, they'd never make it past HR.

    Yup, especially since HR adheres to the "check-box" policy off hiring. Do you have such a skill yes/no? This totally eliminates the people who actually can learn the stuff. I was speaking to one headhunter who said that one company wanted someone who could hit the ground running, because they had a tight deadline, and then as the project got closer to the finish date, and they still hadn't found such a person, they became fussier about thre criteria. This is akin is trying to find the ideal girl friend and upping the criteria when you don't find her.

    Okay must admit since taking a sabatical trying to find another job is proving to be a little harder than expected. And the fact that I am in IT doesn't seem to help me find the "beautiful girl, who is smart and funny and I spend my time with" ( match.com didn't help either ;) I will get both one day, but I am not sure how (maybe just a hopeless optimist?)
  • by devnull17 ( 592326 ) * on Monday November 21, 2005 @10:39PM (#14087504) Homepage Journal

    Having worked at a similar mom-and-pop software shop that has outgrown its humble beginnings, I can say with confidence that there is nothing more dangerous to a company (and a programmer's mental health) than a boss who tries to involve himself in the software development process.

    Our flagship product was written (illegibly) in VB6. The codebase hadn't changed since VB3, and it wasn't very well-written to begin with. Our small development team spent about half of our time cleaning up after his architectural mistakes, and the other half trying to keep the creaking mess intact.

    I spent three years there. I never saw a programmer last even half as long as I did. One lost all hope and just decided to ignore his marching orders and develop UI controls all day. Another ended up working hundred-hour weeks and went completely, literally insane. Everyone currently on the tech staff there has needed leaves of absence of at least three months to keep their shit together. I eventually just gave up and quit. Better to be unemployed and sane than keep a job that makes you foam at the mouth.

    The bottom line: In every case I've ever seen, the boss belongs far, far, far away from the code. At all costs.

It is easier to write an incorrect program than understand a correct one.

Working...