Click here to Skip to main content
15,889,853 members
Articles / All Topics

An Idiots Guide to Really Really Bad Programming

Rate me:
Please Sign up or sign in to vote.
4.89/5 (127 votes)
1 Feb 2010CPOL4 min read 167K   55   115
A satirical look at bad programming techniques

Introduction

I have noticed that certain individuals persist in writing good clear code that is well documented and easy to understand. So I thought it was about time to draw the main techniques of really really bad programming together into a single reference document. Remember the most important two things when writing truly awful software are to include as many subtle bugs as possible and to make the code really confusing so that it is hard to track those devious little bugs down. That way you can annoy both users and programmers to the maximum extent.

If you follow these simple rules, I promise you that you will never be far from users’ and other programmers’ thoughts.

1. Turn Off All Compiler Warnings

If you want to write really awful code, this is a great place to start. After all, you do not want that pesky compiler nagging you all day. All real programmers turn the warnings off completely.

2. Variables

Beginners should ensure that all variables are global. It is much easier to keep them all together in one place. As you become more advanced, add local variables with the same names as the globals, this will allow you to create subtle bugs with ease.

3. Functions

Avoid using functions wherever possible. It is much easier to write one single enormous long passage of code than going through the tiresome process of trying to divide it into separate functions and having the tedious job of passing parameters to them.

4. Cut and Paste is your Friend

Avoid using loops at all costs, it might take longer to cut and paste a section of code over and over, but it is well worth it when you consider the hours of fun for anyone checking each and every repeat of that code for subtle variations.

5. Variable Names for Beginners

You can have so much fun with variable names, try using the most meaningless name that you can think of, Fred is one of my personal favourites. But always include a smattering of semi meaningful names to keep other programmers guessing.

6. Advanced Variable Name Techniques

Ideally try to think of names that are very similar for as many entirely different variables as you can. Another great idea is to create two variables with the same name, but one ending in ‘1’ and the other in ‘l’, these are very easy to confuse at a glance and should get other programmers really guessing. Example: Slopel and Slope1. However, you can achieve the best results by occasionally using a label to mean the exact opposite of what people would assume, a classic example is to use the label Horizontal to mean Vertical and vice versa, that will really please any reader of your code, causing hours of amusement and pleasure as they try to unravel it.

7. Initialising

Play programmers bingo by allowing all of your variables to start with whatever value the memory had in from the last application. Great fun!

8. Bounds Checking

Allow the user to enter whatever values they want, if they enter a stupid value the program may crash. So? What do they expect?

9. Comments

It is best for beginners to avoid comments at all times, they waste valuable space and take ages to type. As you become more advanced, you can begin by adding comments which are entirely useless, because they state the obvious such as:

C#
i++; // increment i

However, the most advanced comments will be as cryptic as possible, such as:

C#
i++; 	//check inside the chicken string

10. Layout

It takes real dedication to make your software layout truly bad. The most important thing is NEVER EVER be consistent. Whatever layout philosophy you choose, be sure to change it regularly. Advanced programmers should remember to use the same layout for long enough for any other programmer to become accustomed to it before changing to something entirely different.

11. Hungarian Notation

This is entirely optional, but for best results use a smattering of Hungarian Notation, thus annoying everyone (those who like it AND those who don't) and of course include a few incorrect uses just to make things more interesting.

12. Lastly Never Ever Test

Don't bother to test your code, just wait for people to complain, that way you will find out which are the most commonly occurring bugs first! Brilliant!

I have tried to cover most aspects of Really Really Bad Programming, but I am sure many of you can think of a few more. And don't be down hearted if after a while you start to slip into good habits, it doesn't take much effort to get back to those bad bad ways.

Disclaimer

I am not in any way suggesting that I never write bad code, nor am I suggesting that anyone else at CodeProject does. Just having a little fun!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: TryCatch... Pin
LittleYellowBird15-Feb-10 0:29
LittleYellowBird15-Feb-10 0:29 
General4. Cut and Paste is your Friend Pin
Ray Machale12-Feb-10 7:41
Ray Machale12-Feb-10 7:41 
GeneralRe: 4. Cut and Paste is your Friend Pin
LittleYellowBird15-Feb-10 0:22
LittleYellowBird15-Feb-10 0:22 
JokeThanks!! Pin
Dr.Luiji12-Feb-10 1:02
professionalDr.Luiji12-Feb-10 1:02 
GeneralRe: Thanks!! Pin
LittleYellowBird15-Feb-10 0:28
LittleYellowBird15-Feb-10 0:28 
GeneralNeedless repetition Pin
BarrRobot9-Feb-10 23:48
BarrRobot9-Feb-10 23:48 
GeneralRe: Needless repetition Pin
LittleYellowBird10-Feb-10 4:43
LittleYellowBird10-Feb-10 4:43 
GeneralStephen Brooks response Pin
unquietwiki9-Feb-10 5:30
unquietwiki9-Feb-10 5:30 
From Stephen Brooks, a friend of mine... @ http://www.stephenbrooks.org/[^]....


There are rather more I can think of (mainly because I've done some of
them):

- [me] Use characters outside the standard ASCII set like degree or square
(superscript 2)

- [Something I've seen others do] don't use the memory manager when you can
just make a fixed array with 10000*10000 entries, that should be big enough
for anything!

- [me] Handle exceptions like this

if (11==sscanf(str," %d %d %g %g %g %g %g %g %g %g %g",
&pn,&pid,&ke,&wt,&x,&y,&z,&vx,&vy,&vz,&t))
{
...
}
else {printf("Error bad mallards\n"); getchar();}

- [me] Make comments only decipherable if you know specific people by name,
e.g.

for (sign=0;sign<2;sign++) for (useful=0;useful<2;useful++) for
(i=0;i<=20;i++)
{ // Double-binned stuff that Roger was going on about
for (j=0;j<=20;j++) pizp[sign][useful][i][j]=0;
for (j=0;j<36;j++) pizth[sign][useful][i][j]=0;
}

- [me] Use the conditional ternary operator on Lvalues, e.g.

*(sign?&gminus:&gplus)+=gwt; *(sign?&gminusvar:&gplusvar)+=gwt*gwt;

- [others] Limit all function names to 6 characters or less, in all-caps.
Then make a handy paper index where you can look up what PR09CF does

- [me, now corrected] Make variable assignments inside short-circuited logic
statements, so you don't know whether they have been initialised or not

float x,y;
if (fabs(x=ax-bx)<50 && fabs(y=ay-by)<50) {...}
// Now try to use y!

- Make a global but then pass it as an argument to a function *anyway*

- Write code that relies on the fact "int a,b;" puts a and b in adjacent
memory slots, e.g. memset(&a,0x00,8);

- [me] Create a really long structure containing multiple types and then
initialise it all in-line, e.g.

} ops={"config.txt", 0,180,-1, 0, 1,0, COMMANDLINE, -1, 0, 1,100,
"auto.sav", 0,0,0,0, 0,
"results.dat","results.txt", {3,6,1,"Mpts"}, {"queue.txt",NULL,0,0,5,0},
100000,50,10000,10,
1,24,12,NULL,'L', 0,0,0,0,0, NULL,-1, "ftp -s:script.ftp",0,0,
NULL,"Unknown","",
NULL,0, 0, "none", 0,100, NORMAL_PRIORITY_CLASS,THREAD_PRIORITY_NORMAL,
50<<20,0.5,NULL,'B'};

Very readable!

- On Hungarian notation,
double *dwString;
GeneralRe: Stephen Brooks response Pin
LittleYellowBird10-Feb-10 4:40
LittleYellowBird10-Feb-10 4:40 
GeneralRe: Stephen Brooks response Pin
unquietwiki10-Feb-10 4:56
unquietwiki10-Feb-10 4:56 
GeneralStudents Pin
edmurphy999-Feb-10 2:38
edmurphy999-Feb-10 2:38 
GeneralRe: Students Pin
LittleYellowBird10-Feb-10 4:42
LittleYellowBird10-Feb-10 4:42 
GeneralAnd... Pin
KEL39-Feb-10 0:31
KEL39-Feb-10 0:31 
GeneralRe: And... Pin
LittleYellowBird10-Feb-10 4:36
LittleYellowBird10-Feb-10 4:36 
GeneralMade me chuckle and Reddit it Pin
unquietwiki8-Feb-10 22:05
unquietwiki8-Feb-10 22:05 
GeneralRe: Made me chuckle and Reddit it Pin
LittleYellowBird10-Feb-10 4:35
LittleYellowBird10-Feb-10 4:35 
GeneralGreat! Pin
Cape Town Developer8-Feb-10 21:07
Cape Town Developer8-Feb-10 21:07 
GeneralRe: Great! Pin
LittleYellowBird8-Feb-10 21:38
LittleYellowBird8-Feb-10 21:38 
QuestionWhat the!! Pin
Muammar©8-Feb-10 19:48
Muammar©8-Feb-10 19:48 
AnswerRe: What the!! [modified] Pin
LittleYellowBird8-Feb-10 21:38
LittleYellowBird8-Feb-10 21:38 
GeneralBelieve or not these are trutly stories of ghost Pin
Yves8-Feb-10 15:48
Yves8-Feb-10 15:48 
GeneralRe: Believe or not these are trutly stories of ghost Pin
LittleYellowBird8-Feb-10 21:39
LittleYellowBird8-Feb-10 21:39 
GeneralProgrammers Lament Pin
Tom Corbett Space Cadet8-Feb-10 12:38
professionalTom Corbett Space Cadet8-Feb-10 12:38 
GeneralExcellent Pin
vvitvitskiy8-Feb-10 11:22
vvitvitskiy8-Feb-10 11:22 
GeneralRe: Excellent Pin
LittleYellowBird15-Feb-10 3:32
LittleYellowBird15-Feb-10 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.