Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: efficient use of subroutines

by perloHolic() (Beadle)
on Feb 05, 2015 at 12:12 UTC ( [id://1115645]=note: print w/replies, xml ) Need Help??


in reply to efficient use of subroutines

I just stick to what my Uni professors used to tell me about subs/functions - "Functions should do one thing, and do it well."

When it comes to clarity/readability/maintainablity, I stick to my 'C' roots and make everything possible a sub/function - that way when you have a list of calls to subs/functions, and any parameters passed to them, you can see clearly in what order things are working. IMHO anyway ;)

EDIT: And of course, appropriate naming conventions of subs/functions never hurt anybody! IMHO Try and avoid lengthy names, even as a relatively new professional programmer, all too often do I come across somebody elses subs like this this -> thisSubRoutineWorksOutThisNumberFromThatNumber - and I just think that becomes more of a hinderance then a help!

Replies are listed 'Best First'.
Re^2: efficient use of subroutines
by jeri_rl (Initiate) on Feb 05, 2015 at 18:54 UTC

    Thanks to everyone for all your comments. Seems like I had it backwards in terms of readability vs efficiency. I will take the advice of the majority and make more subroutines.

      In my own view. Subroutines i create for my programs do one thing and do it well. Let the names of your subroutine tell you more about what lies within it and its ultimate function. e.g sub display_data().

      Learn to reduce the length of you subroutines try to make them compact and straight to the point. things like first naming your variables before assigning values to them are way too long and repetitive. e.g my $name = undef; $name = qq{liray}
      could be reduced to my $name = qq{liray};

      Finally clarity, maintenance should be kept in mind, because you could visit this subroutine 6 months down the line and begin to wonder what you created it to do and why. Also learn to express your self in the best possible way that suits your style of programming.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1115645]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-19 20:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found