Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: It's the little things...

by Lady_Aleena (Curate)
on Apr 16, 2012 at 05:22 UTC ( #965240=note: print w/replies, xml ) Need Help??

in reply to It's the little things...

Last Saturday I was rewriting a script and was getting sick of all of the ifs I was using. My code was to the point that I was 12 tabs down. Someone once said that about 4 was the maximum, so 12 was a bit much. Since I was in a for loop, I decided to finally see if I could get the hang of using next. OMG! The depth of my code got shallow rather quickly. I went from a depth of 12 tabs to 7. I felt a bit of joy at that point. I just wanted it share with you all how happy that little insight finally saved me from plunging too deep and having fewer brackets made it easier to find where I am when writing my script. Now I'm wondering how much unnecessary depth I have elsewhere. I think I will go spelunking.

Have a cookie and a very nice day!
Lady Aleena

Replies are listed 'Best First'.
Re^2: It's the little things...
by Jenda (Abbot) on Apr 17, 2012 at 08:59 UTC

    Maybe you should consider moving some of the code into separate subroutines. If you are 7 tabs deep, your code is most likely also rather long. Extracting and naming bits of it might make things more maintainable.

    Enoch was right!
    Enjoy the last years of Rome.

Re^2: It's the little things...
by jdporter (Canon) on Apr 16, 2012 at 14:33 UTC

    Here's the next secret. You can get rid of just about all your nesting depth by replacing control structures (subroutines, for loops, etc.) with gotos. It's what you might call a higher level of wizardry, but it sounds like your nearly ready for it.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://965240]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2018-02-19 05:01 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (258 votes). Check out past polls.