Skip to content

Instantly share code, notes, and snippets.

@douglas-mason
Last active August 29, 2015 13:55
Show Gist options
  • Save douglas-mason/8757721 to your computer and use it in GitHub Desktop.
Save douglas-mason/8757721 to your computer and use it in GitHub Desktop.
Readability Tip #1
var myCar = new Car({color: 'black', style: 'Police Car'});
var theirCar = new Car({color: 'red', style: 'Sports Car'});
var isRedSportsCar = theirCar.color === 'red' && theirCar.style === 'Sports Car';
if(isRedSportsCar){
myCar.chase(theirCar);
}
var myCar = new Car({color: 'black', style: 'Police Car'});
var theirCar = new Car({color: 'red', style: 'Sports Car'});
if(theirCar.color === 'red' && theirCar.style === 'Sports Car'){
myCar.chase(theirCar);
}
@douglas-mason
Copy link
Author

Abstracting out the conditional logic into a well named variable will greatly increase readability of your code for other programmers or your future self.

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