Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: keywords versus variables

by mr_mischief (Prior)
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 );
vs.
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.


Comment on Re: keywords versus variables
Select or Download Code
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
    $blah->{something}->{and_deeper}->[12]
    you'll be pretty bug prone and so you might consider refactoring into something like
    $deeper->item(12)
    ...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 (Cardinal) on Aug 30, 2007 at 21:36 UTC

    perhaps even better:

    $employee->figure_pay ();

    or:

    $employer->figure_pay ($employee);

    DWIM is Perl's answer to Gödel
      definitely even better:
      $employee->figure_raise();
      or:
      $employer->figure_really_sweet_bonus($employee);
      Especially if you're a company like ADC that runs payrolls for a living.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (16)
As of 2014-07-30 15:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (235 votes), past polls