Friday, September 02, 2011

Programming verbiage

Which is a better style?

 Style 1:

boolean checkNum(int x) {
   if (x > 10) {
       return true;
   }
   else {    // actually else {} is unnecessary
       return false;
    }
}


Style 2:


boolean checkNum(int x) {

       return (x > 10);
}


Though I find style 1 more often, specially in the code written by rookies, I prefer style 2. It is short and crisp.

No comments: