Which way is better?

You can Leave a comment here!

Comments

  1. Nev 6/6/2007 8:12 PM
    Gravatar
    Well....

    This is a bit of a religious debate. Some say "a method shall have a single exit point, for having more than one exit point will cause bugs". Consider your example above, but imagine you want to log what you returned - you'd have to dot logging statements all over the show. They would argue that you should introduce a local variable, and modify that in the logic statements, then return that.

    If you're asking "is else after if good", then mostly the answer is yes. It makes the code read the way it executes - "if this, then that, else the other". It makes it easier to add logic to the "else" clause without introducing silly bugs.

  2. Dave 6/12/2007 11:41 PM
    Gravatar
    Whats wrong with:

    return (Element.GetAccessRights() == AccessRights.PRIVATE)

    ?
  3. Muntedhar 6/25/2007 11:59 AM
    Gravatar
    Dave, I prefer to have a nice block where you can see where it returns true or false, so it would be fairly easy to add more code to that block.

Leave a comment

Please be polite and on topic. Your e-mail will never be published.

Please add 1 and 2 and type the answer here: