Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Re (tilly) 1: When do you function?

by puck (Scribe)
on Dec 28, 2000 at 02:33 UTC ( #48546=note: print w/replies, xml ) Need Help??

in reply to Re (tilly) 1: When do you function?
in thread When do you function?

As in a's comment, I also tend to write top down using wishful programming. (Where wishful programming is using names of functions I haven't written yet.) This has the benefit of not having to think about everything at once, and if you create stub functions it will actually run and you can slowly build it up. Ah ha, starting to use some XP techniques! (Except I learnt to do this before XP was around...)

When it comes to breaking functions up, if I have a function which is trying to do several different things, it is usually time to break it up. Likewise, a function which is more than a couple of screens long is about due for a break up. Although the screens one is very relative... Especially when I'm writing CGI scripts which are generating forms, they can get rather lengthy.

Over the last couple of weeks I've been writing a interface for managing Spong - using Perl OO. In an object, if I realise that I need to use some code again (for example: sucking details out of the database about a host), it get's broken out to a new function in the object.

So, there's some of my approaches. Of course, if I sat down and did some decent design before hand I'd only need to use the first one - wishful programming - as the functions would already be broken up logically.


Updated: Right, that link to Spong now works as it should. My bad. (Thanks a for pointing it out!)

  • Comment on Re: Re (tilly) 1: When do you function?

Replies are listed 'Best First'.
(bbq) Re: Re: Re (tilly) 1: When do you function?
by BBQ (Deacon) on Dec 28, 2000 at 08:25 UTC
    Oh, you are so on the nail on this... I've gotten into a habit of doing this instead of writting pseudo-code:
    # authenticate user AuthenticateUser($foo,$bar) or die('Could not authenticate user'); # a while later... # do some stuff SomeStuff($more,@params) or die('Could not do more stuff cause reason'); # subs from here down ######################## sub AuthenticateUser { return(1); } sub SomeStuff { return(1); }
    I tend to code this way especially when I'm discussing the program with colleages. Then we all get a copy and each one goes out to fill in his/her respective blanks. In the end, I believe the result is usually very clear and quite maintainable!

    # Trust no1!

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2017-03-26 22:17 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (315 votes). Check out past polls.