Click here to Skip to main content
14,329,489 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: when algorithms attack Pin
honey the codewitch16-Aug-19 9:34
memberhoney the codewitch16-Aug-19 9:34 
GeneralRe: when algorithms attack Pin
Sander Rossel16-Aug-19 9:52
professionalSander Rossel16-Aug-19 9:52 
GeneralRe: when algorithms attack Pin
Jon McKee16-Aug-19 10:29
professionalJon McKee16-Aug-19 10:29 
GeneralRe: when algorithms attack Pin
Sander Rossel16-Aug-19 10:52
professionalSander Rossel16-Aug-19 10:52 
GeneralRe: when algorithms attack Pin
Jon McKee17-Aug-19 10:19
professionalJon McKee17-Aug-19 10:19 
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 10:34
professionalSander Rossel17-Aug-19 10:34 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 10:30
memberhoney the codewitch16-Aug-19 10:30 
GeneralRe: when algorithms attack Pin
Sander Rossel16-Aug-19 10:59
professionalSander Rossel16-Aug-19 10:59 
Your code shouldn't be so nested in the first place.
I get it, it happens.

How I solve such code is as follows:
void ProcessThing(Thing thingy)
{
   try
   {
      ProcessFoos(thingy.Foos);
   }
   catch (Exception ex)
   {
      // Handle error.
   }
}

void ProcessFoos(List<Foo> foos)
{
   foreach (var foo in foos)
   {
      ProcessBars(foo.Bars);
   }
}

void ProcessBars(List<Bar> bars)
{
   foreach (var bar in bars)
   {
      ProcessStuff(bar.Stuff);
   }
}

// ...
You get the idea, same for if statements and switches.
It's not even that bad, it's quite readable, it's maintainable (you'll always know where the bars are processed) and it saves you from nesting so many levels in one code block.

GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 11:02
memberhoney the codewitch16-Aug-19 11:02 
GeneralRe: when algorithms attack Pin
Sander Rossel16-Aug-19 11:09
professionalSander Rossel16-Aug-19 11:09 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 11:16
memberhoney the codewitch16-Aug-19 11:16 
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 1:35
professionalSander Rossel17-Aug-19 1:35 
GeneralRe: when algorithms attack Pin
honey the codewitch17-Aug-19 3:16
memberhoney the codewitch17-Aug-19 3:16 
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 4:08
professionalSander Rossel17-Aug-19 4:08 
GeneralRe: when algorithms attack Pin
honey the codewitch17-Aug-19 4:14
memberhoney the codewitch17-Aug-19 4:14 
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 4:27
professionalSander Rossel17-Aug-19 4:27 
GeneralRe: when algorithms attack Pin
honey the codewitch17-Aug-19 4:30
memberhoney the codewitch17-Aug-19 4:30 
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 4:32
professionalSander Rossel17-Aug-19 4:32 
GeneralRe: when algorithms attack Pin
honey the codewitch17-Aug-19 4:41
memberhoney the codewitch17-Aug-19 4:41 
GeneralRe: when algorithms attack Pin
dandy7216-Aug-19 5:06
memberdandy7216-Aug-19 5:06 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 5:08
memberhoney the codewitch16-Aug-19 5:08 
GeneralRe: when algorithms attack Pin
dandy7216-Aug-19 5:11
memberdandy7216-Aug-19 5:11 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 5:12
memberhoney the codewitch16-Aug-19 5:12 
GeneralRe: when algorithms attack Pin
dandy7216-Aug-19 5:16
memberdandy7216-Aug-19 5:16 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 5:20
memberhoney the codewitch16-Aug-19 5:20 

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.