Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created April 26, 2016 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/8415ff592cfa6bd707978291bdff68f3 to your computer and use it in GitHub Desktop.
Save tmcw/8415ff592cfa6bd707978291bdff68f3 to your computer and use it in GitHub Desktop.

Naming everything in a variable before using it

Examples

var whetherToReturnTheResult = true;
return whetherToReturnTheResult;

This coding pattern is naming everything to a variable, regardless of whether you need to save it. This is usually rooted in a few magical beliefs:

"I need to declare this variable"

This can be from people who have tinkered in other languages and used to pay a lot of attention to their int and float declarations etc etc: they expect that any value requires maintenance.

try/catch around everything

Examples

for (var i = 0; i < 10; i++) {
  try {
    // all of the application code here
  } catch(e) {
    console.log('I have no idea what went wrong');
  }
}

This is rooted in a few magical beliefs:

  • A caught error is better than an uncaught one
  • Failing silently is better than failing loudly
  • I don't know what kinds of errors my code will produce

Everything has to be a member of some object

Examples

function MyProgram() {
  this.someTemporaryVariable = 5;
  if (this.someTemporaryVariable) {
    // ugh
  }
}

This is rooted in an "Object-Oriented Education", usually in Java or something like that: it avoids the use of scope for any value and instead assigns every value, even temporary results, to an object.

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