Click here to Skip to main content
15,891,136 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Trippin' Friday Pin
Mark_Wallace15-Feb-19 13:22
Mark_Wallace15-Feb-19 13:22 
GeneralRe: Trippin' Friday Pin
Ron Anders15-Feb-19 14:44
Ron Anders15-Feb-19 14:44 
GeneralRe: Trippin' Friday Pin
Sander Rossel16-Feb-19 2:32
professionalSander Rossel16-Feb-19 2:32 
QuestionAny Success with MSIX? Pin
KEastman15-Feb-19 9:20
KEastman15-Feb-19 9:20 
AnswerRe: Any Success with MSIX? Pin
Mark_Wallace15-Feb-19 13:26
Mark_Wallace15-Feb-19 13:26 
AnswerRe: Any Success with MSIX? Pin
abmv15-Feb-19 18:48
professionalabmv15-Feb-19 18:48 
AnswerRe: Any Success with MSIX? Pin
dandy7216-Feb-19 6:03
dandy7216-Feb-19 6:03 
QuestionMultiple returns from methods or clean code flow Pin
  Forogar  15-Feb-19 5:11
professional  Forogar  15-Feb-19 5:11 
I have just had a heated argument cage fight lively discussion with some of my team members about ReSharper's suggestion of refactoring code to replace nested ifs with a series of multiple early return statements. This caused horribly messy code that ReSharper actually described in it's help as "more readable"!

Using a version of their example code (which is a lot simpler than the actual code in question):
void SomeFunction(SomeThing s)
{
  if (s != null)
  {
    if (s.Thing != null)
    {
      // Do Some Process with s.Thing
      .
      .
      .
    }
  }
}
becomes:
void SomeFunction(SomeThing s)
{
  if (s == null) return
  if (s.Thing == null) return;
  // Do Some Process with s.Thing
  .
  .
  .
}
This makes a complete hash of the natural flow of the code and introduces an execution statement (return) on the same line as the "if" which is bad coding practice, and then does it again, and then drops though to do some actual processing.

If I was to refactor the code it would do this:
void SomeFunction(SomeThing s)
{
  if (s != null && s.Thing != null)
  {
    // Do Some Process with s.Thing
    .
    .
    .
  }
}
or possibly:
void SomeFunction(SomeThing s)
{
  if (s?.Thing != null)
  {
    // Do Some Process with s.Thing
    .
    .
    .
  }
}
Which is a lot cleaner!
...and this isn't even considering a method that returns a value of some sort.

Opinions?
- I would love to change the world, but they won’t give me the source code.

AnswerRe: Multiple returns from methods or clean code flow Pin
PIEBALDconsult15-Feb-19 5:28
mvePIEBALDconsult15-Feb-19 5:28 
AnswerRe: Multiple returns from methods or clean code flow Pin
User 483504715-Feb-19 5:37
User 483504715-Feb-19 5:37 
GeneralRe: Multiple returns from methods or clean code flow Pin
CodeWraith15-Feb-19 8:03
CodeWraith15-Feb-19 8:03 
GeneralRe: Multiple returns from methods or clean code flow Pin
User 483504715-Feb-19 8:17
User 483504715-Feb-19 8:17 
GeneralRe: Multiple returns from methods or clean code flow Pin
CodeWraith15-Feb-19 8:25
CodeWraith15-Feb-19 8:25 
GeneralRe: Multiple returns from methods or clean code flow Pin
sasadler18-Feb-19 5:43
sasadler18-Feb-19 5:43 
GeneralRe: Multiple returns from methods or clean code flow Pin
CodeWraith18-Feb-19 6:05
CodeWraith18-Feb-19 6:05 
GeneralRe: Multiple returns from methods or clean code flow Pin
sasadler18-Feb-19 9:42
sasadler18-Feb-19 9:42 
GeneralRe: Multiple returns from methods or clean code flow Pin
CodeWraith18-Feb-19 13:18
CodeWraith18-Feb-19 13:18 
GeneralRe: Multiple returns from methods or clean code flow Pin
sasadler19-Feb-19 5:32
sasadler19-Feb-19 5:32 
GeneralRe: Multiple returns from methods or clean code flow Pin
CodeWraith19-Feb-19 5:50
CodeWraith19-Feb-19 5:50 
GeneralRe: Multiple returns from methods or clean code flow Pin
sasadler19-Feb-19 6:16
sasadler19-Feb-19 6:16 
AnswerRe: Multiple returns from methods or clean code flow Pin
Simon_Whale15-Feb-19 6:00
Simon_Whale15-Feb-19 6:00 
GeneralRe: Multiple returns from methods or clean code flow Pin
  Forogar  15-Feb-19 6:02
professional  Forogar  15-Feb-19 6:02 
GeneralRe: Multiple returns from methods or clean code flow Pin
CodeWraith15-Feb-19 8:06
CodeWraith15-Feb-19 8:06 
GeneralRe: Multiple returns from methods or clean code flow Pin
charlieg15-Feb-19 17:13
charlieg15-Feb-19 17:13 
AnswerRe: Multiple returns from methods or clean code flow Pin
User 483504715-Feb-19 6:09
User 483504715-Feb-19 6:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.