Skip to content

Instantly share code, notes, and snippets.

@cleverdumb
Last active January 1, 2023 13:44
Show Gist options
  • Save cleverdumb/2b068cb2ae56528cfce0255ff6b98d43 to your computer and use it in GitHub Desktop.
Save cleverdumb/2b068cb2ae56528cfce0255ff6b98d43 to your computer and use it in GitHub Desktop.
Guide to writing bad code.

Introduction

Writing bad code is something every programming does in some point in time. This guide will teach you how to write worse code.

Table of content

  • Introduction
  • Why?
  • Bad naming
  • Chain stuff
  • Bad tabing and spacing
  • Use short hand syntax

Why?

  • 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

Bad naming

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 stuff

  • 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;

Bad tabing and spacing

Do it as bizarrely and weirdly as you want.
Example:

function       mf(a1       , a2      )      {
                  console.log(a1       + a2    )       ;
              }

Use short hand syntax

  • 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)

Conclusion

Following these steps can make your code worse. Good luck in annoying everyone.

by cleverdumb for JSM community, WIP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment