Dec 12, 2016
There's lots of guides on the web that'll help you to write better code. I could find hundreds of tips that'll help you to write great code in an hour. Code that gets the job done, is easily maintained and proves hard to exploit... All in less than O(2n). But who wants that?
In today's post I share a ten step guide to writing truly awful code.
1. Forget About Design
The design stage is a waste of time anyway, right? Just jump in and start writing your code. The structure will come naturally. Naming conventions, language choices and design patterns are pointless. Jump in and get started, today. The sooner you start writing code, the worse it will be.
2. Start Afresh, Who Needs a Framework?
Forget about using frameworks or pre-existing functions and modules. You can write them again yourself, anyway, right? Especially those pesky encryption functions.
3. Use Arbitrary Variable Names
A great source for variable names is babynames.com. You'll find that trying to explain your code to other developers becomes a lot more fun when they ask you why Tobias keeps reaching zero and throwing a divide by zero exception, or why Agnes is a float, not an integer.
4. Misspell Function Names, Deliberately
Keep the rest of your team on their toes. Throw in a few misspelt function names. Great function names are things like: StartThng() or Stpothat(). No terrible code is complete without a few deliberate typos.
5. Lie In The Comments
There's only one thing better than leaving no comments at all when it comes to terrible code, and that's making an active effort to lie in them. There's all sorts you can try, from making up how something works to swapping function documentation. Don't tread too far from the believable though, and mix in a few real ones, or your fellow developers may just start ignoring them.
6. Don't Validate User Inputs
Users are your friends. They can be trusted. Data validation takes time, and will only serve to annoy your users. If you're writing bad code, it's just not necessary.
7. Avoid Encapsulation At All Costs
Other developers want to know what a function does every time they come across it in your code. Don't make them go hunting for it in other files. Re-define that function you need every time you use it.
8. Forget About Exception Handling
Exceptions are just that. Exceptions. They're rare, and only happen when someone's doing something they shouldn't be in the first place, right? So don't worry about writing code to handle them. Quite frankly, it's not your fault, and the user should have known that the web address bar was for URLs, not wing dings.
9. Leave The Testing For Someone Else
If you're writing terrible code, don't worry about testing it. Whether that means testing as you code, unit tests, or some basic user testing at the end of the day. Leave all your testing to someone else, I mean isn't that the QA's job anyway?
10. Remember It's The Size That Counts
In terrible code, size matters. The bigger your functions and codebase, the better. Fact. If you want to write truly terrible code, always be on the lookout for ways to make your code longer and more confusing. If something that can be done in 10 lines can be done in 100, go all out. I mean, Haskell isn't all that popular for a reason, right?
So there we have it. 10 quick steps to writing truly awful code. If you can follow them, you'll be out of the office and back to the job centre in no time. However, if you're a developer that wants to keep hold of his job and write better, more secure code, you might want to check out these five tips instead.