Showing posts with label coding-style. Show all posts
Showing posts with label coding-style. Show all posts

Wednesday, May 30, 2012

Is there a better way of writing v = (v == 0 ? 1 : 0);


I want to toggle a variable between 0 and 1. If it's 0 I want to set it to 1, else if it's 1 I want to set it to 0.

Friday, April 6, 2012

"AND" vs "&&" as operator


Actually, I am facing a codebase where developpers decided to use ' AND ' and ' OR ' instead of ' && ' and ' || '. I know that there is difference in operators precedence ( && goes before ' and '), but with given framework (prestashop to be precise) is clearly not a reason. So, my question: which version are you using? Is ' and ' more readable than ' && '? || there is ~ difference?

PHP return(value); vs return value;


Is there any difference between return($var); and return $var; other then wrapping it in parentheses?

Thursday, March 8, 2012

Prefixing property names with an underscore in Objective C


I've always avoided underscores in my variable names, perhaps because its just not what was done back in my learning Java in college days. So when I define a property in Objective C this is what I naturally do.

Sunday, January 29, 2012

PHP if else - proper use of "else”


A professor told me long ago to use else when "chaining" multiple conditions in a series (I was still learning). Now that I've been tinkering with several frameworks and CMS years later, I find it quite amusing that what I was taught to do isn't necessarily so.