Friday, April 27, 2012

Good practice when naming a Boolean variable/Property


When defining a Boolean (true/false) variable or property

  1. Prefix the name with "Is" or "Has"
  2. Do not negate in your variable name.

Bad Boolean variables names:

  • Allowed (No prefix)
  • IsNonUser (Negated Name)
  • IsNotAllowed (Negated Name)
  • Permission (No prefix)

Good boolean variable names:

  • IsAllowed
  • IsUser
  • IsAllowed
  • HasPermission


Because if statements with negation become easier to read.

I think this if statement is harder to read

   1: if(!IsNotAllowed) 
   2: { 
   3:     ShareCandy(); // "If not is not allowed then share candy"
   4: } 

Then this if statement

   1: if(IsAllowed) 
   2: { 
   3:     ShareCandy(); // "If is allowed then share candy"
   4: } 


Friday, April 6, 2012

A quote from modernizr

I read this in the modernizr documentation on polyfills and I thought I would repeat it:

And remember, none of your users view your site in more than one browser; It’s okay if it looks and acts differently.

So true. All too often people want their websites to work exactly the same on all browsers. But in reality, users don’t know if there are slight differences because they have nothing to compare it to. As long as the user can get the same information and actions they get on other browsers. It’s ok if it’s off by a few pixels.