Writing bad code is something every programming does in some point in time. This guide will teach you how to write worse code.
- Introduction
- Why?
- Bad naming
- Chain stuff
- Bad tabing and spacing
- Use short hand syntax
- To annoy people because it is fun
- So no one will copy your code, because they cannot, and even if they do they learn nothing
- Sometimes type less and use less time
- Looks cool :)
- If you are a good person, then do the opposite and write good code
The first way I want to introduce is to name variables terribly. There is a few way to do this.
- Use first letter of word (acronym)
Examples:
Do:
let c = 0;
let t = 1;
Don't:
let counter = 0;
let temporary = 1;
You can also use numbers for repeated names:
let c1 = 0;
let c2 = 1;
let c3 = 2;
Use all lowercase letters to connect different words:
let thisisalongvariablenamemeshedtogetherbecausewhynot = 1;
Use x, y, z for loop variables, and never use something that makes sense:
let a = [1,2,3];
a.forEach(x=>{
for (let y=0; y<x; y++) {
console.log(x+y)
}
})
- Chain functions
Examples:
Do:
let a = [1,2,3]
let t = a.filter(x=>x%2==1).map(x=>x*2).slice(0,1)
Don't:
let a = [1,2,3]
let t = a.filter(x=>x%2==1)
t = t.map(x=>x*2)
t = t.slice(0,1)
- Chain variable declaration
Examples:
let c1 = 0, c2 = 0, c3 = 0;
Do it as bizarrely and weirdly as you want.
Example:
function mf(a1 , a2 ) {
console.log(a1 + a2 ) ;
}
- Ternary operator
Do:
let v = a>b?c:d
Don't:
if (apple>bear) {
val = counter;
}
else {
val = dogCount;
}
You can also chain it as confusing and long as you want (the more the better)
Following these steps can make your code worse. Good luck in annoying everyone.
by cleverdumb for JSM community, WIP