title: Should functions return null or an empty object?
body: <p>What is the <em>best practice</em> when returning data from functions.  Is it better to return a Null or an empty object?  And why should one do one over the other?</p>
  
  <p>Consider this:</p>
  
  <pre><code>public UserEntity GetUserById(Guid userId)
  {
       //Imagine some code here to access database.....
  
       //Check if data was returned and return a null if none found
       if (!DataExists)
          return null; 
          //Should I be doing this here instead? 
          //return new UserEntity();  
       else
          return existingUserEntity;
  }
  </code></pre>
  
  <p>Lets pretend that there would be valid cases in this program that there would be no user information in the database with that GUID.  I Would imagine that it would not be appropriate to throw an exception in this case??  Also I am under the impression that exception handling can hurt performance.</p>