Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
lxmcf204105yAnd I'm sitting here with some old code that literally had 6 seperate for loops nested in another for loop .-.
-
hjk10157315y@kleopi good luck creating an early exit condition.
Sure in some languages you can throw an exception and have that handles in a very convoluted way but for good sake stop obsessing over this. Clarity trumps the nesting argument!
If it seems one coherent task it's fine to have a nested loop and a few conditions especially if the deeper loop needs a lot of data.
Splitting things up with hard to define method names and a lot of argument passing is not helpful.
Please understand that I hates long methods/functions/subroutines and overly complex flow control in them. These days I come across more and more of the stuff in previous paragraph because of nesting fear. -
kleopi8735y@hjk101 I totally agree that nesting isn't strictly bad. But if your loop has 200 lines 3 loops deep, it might be worth to think about simplifying, or to use streams, or well to extract it in a method.
If it's nested but easily understandable or caused by Dataobject nesting, extracting can indeed make it harder to work with. All depends on the situation. -
hjk10157315y@kleopi if you're loop has 200 lines it's safe to assume it is not doing one coherent task and is not clear at all.
That root is the problem; not the nesting. Nesting is just a side effect.
Nesting itself becomes a problem when you have to scroll east or having to read it 5 times just to follow the flow. -
@kleopi... and all that does in many cases is:
1. prevent you from doing early exit in many cases
2. complicates how you actually modify the data (byref one dimension of the array to the procedure? have the array as global "temporary" variable? have the modified dimension as a return value from the function, meaning you need to duplicate it needlessly?)
3. (and this is worst, imo) : HIDES AWAY A LAYER OF TIME COMPLEXITY OF THE CODE, inviting careless use, which will inevitably come back at some point and bite you in the ass by tanking your performance.
any questions?
I've seen people do more than 4 as well though
joke/meme
nested loops
loops