9

Was just watching a video of a rather great Microsoft instructor, Mike Taulty. In his videos he consistently surrounded his return values with parentheses, even single values:

return (null);

Is there some hidden benefit with IntelliSense, or maybe something with the compiler, that this provides?

Code below:

public ObservableCollection<MailViewModel> Emails
{
  get
  {  
    return (emails);
  }
  set
  {
    emails = value;
  }
}
George Stocker
  • 57,289
  • 29
  • 176
  • 237
Fred Lackey
  • 2,351
  • 21
  • 34
  • Style and consistency. For example sometimes he might want `return x + 1 * y` but it looks more clear as `return (x * 5 + y)` – EkoostikMartin Dec 02 '13 at 16:25
  • 9
    Voting to reopen because although trivial, the question is IMHO not opinion-based. "Is there some hidden benefit with IntelliSense/the compiler" is a question which can answered objectively, even if the answer is simply no. – Jon Dec 02 '13 at 16:29
  • @Jon - agree totally, this is not really opinion based at all. I've favorited this already waiting for a response from some of the framework experts. If there is some tangible benefit I'd like to use it myself. – EkoostikMartin Dec 02 '13 at 16:31
  • 2
    @Jon Well it wasn't closed ;) But you've convinced me not to vote to close :) I doubt anything interesting will come up though. – BartoszKP Dec 02 '13 at 16:40

2 Answers2

7

There is certainly no performance difference because both forms translate to the same IL. The runtime couldn't tell even if it wanted. You can use Reflector or ILdasm or any other decompiler to look at the generated IL.

There is no intellisense benefit or detriment.

The semantics are also exactly identical.

I will not discuss whether it is better style or not because that discussion does not belong on Stack Overflow. It is also a matter of personal taste.

usr
  • 168,620
  • 35
  • 240
  • 369
2

There's no benefit wrt the code generated. You can verify this by looking at the IL generated. As for whether it improves readability or not, that is subjective.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317