Skip to content

Instantly share code, notes, and snippets.

@Atrus7
Last active August 29, 2015 14:05
Show Gist options
  • Save Atrus7/2395df9fb398e34a14e8 to your computer and use it in GitHub Desktop.
Save Atrus7/2395df9fb398e34a14e8 to your computer and use it in GitHub Desktop.
to live by and aspire to

Coding Rules

Based upon Robert C. Martin's book Clean Code.

Basics

Avoid being clever and implicit whenever possible.

Don't forget to refactor. You aren't done coding if your code isn't clean.

Naming

Naming things is cheap--have DESCRIPTIVE NAMES. It should read as close to natural language as possible, avoiding abbrev. and in-house language when possible.

GLOBAL_CONSTANT_NAME
variable_name
ClassName
functionName

Functions

Functions should have ONE(1) thing they do. Reread that.

Endeavor to have pure functions, so that they do not have side effects.

Functions should be have a maximum of three arguments. Good functions have one or two.

Comments

Like this sentence //Comment when it's not clear what you're talking about

Use your code to do most of the talking, but sometimes a concise comment can

Projects

Don't rebuild the wheel unless the wheel is a box made of rubber.

Classes can be simple. Don't build a monolith if three tiny types will do.

Git commits are like bookmarks. Great to find stuff, but too many, too often, makes them less useful.

Build first, then re-factor, but DON'T FORGET TO REFACTOR.

Flags

flags_suck = true
if(flags_suck) { 
avoidWhenPossible()
}

Bracket spacing

functions, loops, and classes() {
//Stuff
}
if(no_of_lines ==1)
  no_brackets == true;

Formatting

Files should typically be between 100 and 500 lines of code. Concepts that are related should be kept vertically close to each other.

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