How To Write Unmaintainable Code
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. '"
Our company's main system is written in FoxPro for DOS 2.6. The FP programmers here seem to have guaranteed lifetime employment :-)
Ummmm, where's the foot icon? It's good to know that the author considers this a joke, but I'm afraid that Hemos might not be in on it...
Be a real patriot: Question authority. Think for yourself. Formulate your own conclusions.
#!/usr/bin/perl
:(
&!@&/*!QW(*()@!@(I!@()!@)(!@*/\()!@&*(@!/*(&
Ok, I admit it. I just banged on the keyboard
Assuming this is tongue-in-cheek. My experience has been no matter how poorly written or unmaintainable something is, it offers little insurance to the author for keeping a job. I've been handed the reins to maintain countless "gone" employees' code. And, if the code isn't maintainable and the program is important or desirable enough, companies just limp along with the deficiencies. 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.
(+/- 2 sigma complainers -- reply here)
Yes of course this is a joke. Turn your humor sensors on NOW!
Wow, I couldn't disagree with you more. This is an excellent....joke! Lighten up!
Sheesh! Irony, it's lost on Americans!!
:-)
I think we're supposed to take this with a certain amount of salt.
OOps, I see you're Canadian. Well, nobody's perfect
return 0; }
How to really write unmaintainable code:
Apply equal parts of Perl and Guinness
What are you eating? isItVeg?.
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
In skimming the article, I realized that an obfuscator does exactly what hes describing. I know its a joke article, but if you really wanted to have unmaintainable code in .net for example... just compile, obfuscate, disassemble, check in viola!.
Top 10 Reasons To Procrastinate
10.
A co-worker sent me these unmaintainable code essays back in August 2005. Taken from AQFL.
Ant(Dude) @ Quality Foraged Links (AQFL.net) & The Ant Farm (antfarm.ma.cx / antfarm.home.dhs.org).
...it generates a root exploit.
I used to employ similar tactics on large non-residnetial contracts, not for myself but for our company, I leared this from my Grandfather and Uncle who did the same, 40 years after the construction a hospital my Uncle was called out of retirment (as a consultant to the firm that got the expansion) To show them "the lay" his price tag $250,000 for 1 year at 35 hrs/wk. He is in the process of building a new home with the proceeds.
On the code side, things I wrote 10 years ago I look at and think who the F*** wrote this, but back to my plumbing, that was the first lesson I was "Taught" NEVER EVER Say something like who the hell did this this way and why, more often than not after being in the business IT WAS YOU !, sure enough about 6 major jobs I went on to think to MYSELF , who did this holy shit is this complex, well after a day on the job I realized it was ME!!!
Never say "Who the Hell wrote this" out loud...a sure way to hang yourself when you practice this method of job security.
I have had way too many times in my contract work that I was assigned to upgrade unmaintainable code.
In fact, I earned a reputation as a saving grace and the original coder was never called back and he earned a black eye as a poor coder.
Now who do you think stayed on the job longer?
Eternity: will that be smoking, or non-smoking? I Corinthians 6:9-10
If you need a daily reminder of "what not to do", I highly suggest bookmarking TheDailyWTF.com.
Str8Dog
using System.Darkside; public
Roedy started this back in the 90's, you could at least have the decency to link to the latest version.
And what's more, why would you want to be bound to program for the rest of your useful life?!
Who said he or she was an American? I've seen plenty of posts on Slasdhot writen in English from people who were not American. Biased, much?
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.
Get paid to code OSS
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.
Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
The kind of coder who deliberately writes bad code just to maintain their employment is always the first coder shown the door. Always. It is a complete urban myth that not commenting spaghetti code will keep you in a job. There is always someone else willing to do your job, no matter how specialized you think you may be.
I am amazed that so many people don't realize that this was a joke. It's a joke people. Are all of these people replying seriously 16? I have to suspect so, because this was immediately identifiable as the same sort of joke that has been repeating for years and years - if you've been in the industry more than a year, if anything it sounded cliched.
Having said that - there is some truth to the claims. The reality is that most programmers out there are terribly, terribly lazy, and they'll immediately declare as undecipherable any code that isn't written for a mentally handicapped pigeon. If you've ever developed code to solve a problem of any complexity at all (e.g. more than some sub-100 IQ CRUD type data forms), you've had it declared "spaghetti code" by someone else, and they've probably thrown up their hands and declared that the only solution is to rewrite it (I'm proud to say that I've had this said about some of my historical code. Not because it was written poorly, but rather because it wasn't just a lightweight, superficial wrapper around calls to library functions. Per the prior point, every lazy programmer would rather just write something new themselves than expend the effort understanding existing code). I've seen this in shops where the lazy, lazy, lazy developers always defer all decisions and judgements to the original programmer (and that original programmer is probably wishing they never had anything to do with it, wishing they stuck to implementing high-level scripts).
The joke's on you! Slashdot beat digg by 6 YEARS: How To Write Unmaintainable Code Posted by Hemos on Thu Nov 18, '99 10:32 PM
Yeah... still a dupe.
I don't need no instructions to know how to rock.
crazy dynamite monkey
Build it, and they will come^Hplain.
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.
The global economy is a great thing until you feel it locally.
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.
I was in stitches the first time I read it several years ago.
I say we take off and nuke the entire site from orbit. It's the only way to be sure.
Roedy Green's fine How To Write Unmaintainable Code has been widely cited all over the web since its original publication in 1997. Surely at least a mention of the author and date of the article could have made the front page, so that those of us who've already seen it multiple times could know to skip it?
[l:l;s<s=0l>x]s"[1+l<dd*l=d*-l;+ds<rl=2**l:+ds=d
*rd*+4<-d15>>]s>[q]s-[d77/3*2-s;47l"x-P1+d78>`]9
ks`0[d23/.5-3*s:0l`xr10P1+d24>$]ds$x
... 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.
--- Attorneys Assisting Citizen-Soldiers & Families -
I know this article is somewhat tongue-in-cheek but it's actually a prevelant mentality. As someone who have watched people write unmaintainable code to ensure their own job security...
If the code is unmaintainable, the end product is probably bad. If the end product is bad, you're not protecting your job but making a case for your worthlessness. Even if the end product is good, most companies would favor a fresh, new person who can differentiate themselves from you by writing a more friendly, maintainable version of the same. When I have come in (back in my indie days) to update or maintain a system that is unmaintainable, I have always made a good case for a more ambitious bid (and more money) to recreate the system from scratch (or recreate as much of it as is necessary) in a more standard, maintainable format.
Besides, as all you open source geeks know, this is (job) security by obscurity, and while it may cause a major inconvienence for your employer, it's not going to force them to keep someone they want to can. IT kids are in for a rude awakening (or have already gotten one) if they think we're still in the era where you're irreplacable, where some other code monkey couldn't come in and do the same or better of a job of what you're doing for less money in a heartbeat.
Here's a hint, find a place that you actually ENJOY working for, that treats their employees well and isn't looking to pull the plug on them at the most convienent time.. And then give them the best work you can offer. Be willing to take the lumps as a line employee for a while and actually earn a career in that company.
You must've been the plumber for the house I just bought.
Bastard.
The next day we had a meeting to examine a legacy application that we were going to be re-writing. Another dev was discussing the DataLoad method. Which loaded a flat CSV file.
And validated the data
And stored the result in a database.
It is very hard to look professional in a meeting when your face is beet red and your eyes are screwed up tight to keep from breaking out it gales of laughter.
Make sure you're irreplaceable
First rule of business: Don't be irreplaceable. If you can't be replaced, you can't be promoted!
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.
Our company's main system is written in FoxPro for DOS 2.6. The FP programmers here seem to have guaranteed lifetime employment :-)
I worked for a rather large ISP who in the process up and switched from a rather large home grown custom database program it had used for years to the corporate Vantive which cost them millions at the time.
I asked my manager why would they bother doing such a thing when the old program worked just fine. He said "The guy who made the program died and know one knows how to code for it."
I laughed for a moment and then by his blank face realized he wasn't joking...
"I am the king of the Romans, and am superior to rules of grammar!"
-Sigismund, Holy Roman Emperor (1368-1437)
And as for the maintainer interpretting it, you're absolutely right that most people just throw up their hands. It's hard to interpret someone else's code for anything past the trivial. Doable, but hard enough that rewriting it often is a good way. Heh, besides which, it's amazing how many times I've thrown up my hands, rewritten the code, and by the experience found that I understood the original code.
This sig has absolutely no significance and serves only to take up screen space and waste the time of the reader.
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."
Programming is like sex: One mistake and you have to maintain it for the rest of your life.
Fly me to the moon Let me sing among those stars Let me see what spring is like On jupiter and mars
I find it really disturbing that programmers are so insecure they need to deliberately make their code difficult to understand. That's just stupid. If you're a good programmer, you will have job security. If you're a crappy programmer, all the obfusification in the world won't give you job security.
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 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.
It's the land of the brave, and the home of the free
Where the less you know, the better off you'll be.
All of the rest will write a Perl program.
Why is this so difficult for employers to comprehend?
If you're paying someone to do a complex job (hint: if it costs $1 million to replace them, it's a complex job), and they die/quit/retire, find a smart person to replace them. Don't find two dipshits to replace them. Don't give Suzy the secretary a $2 raise to do their job (unless Suzy the secretary really is a smart person, in which case, why weren't you paying Suzy more to begin with?)
I've seen it happen over and over again. Smart person runs entire company single-handedly. Smart person quits/dies. Company panics. Company spends ungodly sum of money to completely redesign whatever it is the smart person was doing. New system ends up missing functionality and costing the company loss of productivity.
Every time, something tells me that if this person was smart enough to do everything they were doing, there was probably a reason for it. That's not to say they can't be replaced, just that they probably can't be replaced with any random dipshit, or any random piece of off-the-shelf software.
So, if you're a manager/owner, and you find yourself in this situation: when smart person quits, put an ad in the paper, hire a headhunter, find someone with an IQ of 130 to replace them. Pay them 20% more than you were paying the previous person. Don't worry about whether the new person has experience doing exactly what the previous person did. Don't worry about redesigning anything. If something needs to be changed, the new smart person will be perfectly capable of changing it.
"I assumed blithely that there were no elves out there in the darkness"
They would say "we never really planned on keeping that peice of software [dead guys name here] wrote, but we never decided on a package or got funding for a package to replace and we had so many things going on ..."
members are seeing something, your seeing an ad
Have you ever tried to hire that One Smart Person? Hell, even if s/he existed, they'd never make it past HR.
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.
Have you ever tried to hire that One Smart Person? Hell, even if s/he existed, they'd never make it past HR.
;) I will get both one day, but I am not sure how (maybe just a hopeless optimist?)
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
Jumpstart the tartan drive.