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

Re: keywords versus variables

by mr_mischief (Monsignor)
on Aug 30, 2007 at 17:00 UTC ( #636138=note: print w/replies, xml ) Need Help??

in reply to keywords versus variables

It makes great sense that a program with fewer values to consider would have fewer bugs. Are you talking about two different programs where one has fewer variables by its nature, or are you talking about removing variables consciously from existing programs?

The complicated data structures you mention I've always found handy for decreasing the overall number of variables, BTW. Instead of having a lot of related but disconnected variables that need to be passed around, I can have one data structure that describes a bunch of details about the current topic. I can then delete, alter, pass, and return the one data structure.

Let's look at a typical first-year programming class assignment. I think most of us have done a very simple payroll program. Just the function call illustrates the point:

figure_pay ( $name, $emp_id, $rate, $hours, $gets_overtime, $hours_without_ot, $ot_multi );
figure_pay ( \%employee );
So all other things being equal, I'd say you're definitely on to something. I think perhaps it's balanced against other issues, though, and shouldn't necessarily be a singular goal.

Replies are listed 'Best First'.
Re^2: keywords versus variables
by rvosa (Curate) on Aug 30, 2007 at 18:00 UTC
    I think perhaps it's balanced against other issues, though, and shouldn't necessarily be a singular goal.
    Oh, definitely. It's a bit of a silly "metric", of course. My point about the complex data structures was that, if you have to do
    you'll be pretty bug prone and so you might consider refactoring into something like
    ...which is why I put method calls on one lower level of egregiousness :)
      Good point. Even if you are doing the former on some level, hiding it behind the latter for most code should still help cut down on bugs. Doing the complex one in one place and the simple one in lots of other places could be quite a maintenance win.
Re^2: keywords versus variables
by GrandFather (Saint) on Aug 30, 2007 at 21:36 UTC

    perhaps even better:

    $employee->figure_pay ();


    $employer->figure_pay ($employee);

    DWIM is Perl's answer to Gödel
      definitely even better:
      Especially if you're a company like ADC that runs payrolls for a living.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-05-22 02:05 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (78 votes). Check out past polls.