Weekend project: A place to post crappy code. HatePaste
hatepaste.com
hatepaste.com
if (someBoolean == true) {
doSomething();
}
I got into the habit of doing this since it's immediately obvious that the value you're comparing is expected to be a boolean and not something like an integer, which could cause subtle bugs later on if what you thought was a boolean gets negated. More commonly, it's of the form: if (someValue == false) ...
rather than: if (!someValue) ...
to distinguish this from: if (someValue == 0) ...
It only takes an extra fraction of a second of typing and increases clarity for the next developer, or for you six months later. Anyone else do this too? if (someBoolean)
Are unambiguous.Ofcourse, your example probably applies to JavaScript since anything and everything can be a boolean, or not depending on the phase of the moon. In Java at least if not someBoolean is nice to read, and if (isGood) is nicer than if (isGood == true).
Some people prefer verbosity over brevity, just like some people prefer K&R braces to Allman, or CamelCase to underscoring.
if (true == someBoolean) {
// code
}It's probably not the best idea to be doing that, but it's not tripped me up yet ;-)
if (someBoolean){
return true;
} else {
return false;
}#ActiveRecord::Base.send(:attr_accessible, nil)#comment this line out to let GitHub get hacked
Although, given the nature of the site, you might as well leave it as is.