in reply to Re: passing subroutine args as a hash: why not?
in thread passing subroutine args as a hash: why not?

The 61-headed 350+ line monster sub is taking all the registration information from a huge web form, and storing it in several tables in a database. I think it's all lumped together so the db can be rolled back if something goes wrong.

I wouldn't have done it that way had it been my code. But I'm just the maintainer, and I have to keep my new named-parameter routine in line with the old one until we're sure everything works.

--
bowling trophy thieves, die!

  • Comment on Re: Re: passing subroutine args as a hash: why not?

Replies are listed 'Best First'.
Re: Re: Re: passing subroutine args as a hash: why not?
by sauoq (Abbot) on Jun 05, 2003 at 20:12 UTC

    Why aren't those 61 arguments encapsulated in an easy to use data structure? If they were, your question would be moot. Consider how much improved your life would be if you changed the code so that it things looked like this:

    my $query = CGI->new; my %reg_info = parse_registration_info($query); my $success = store_registration_info(\%reg_info, $database_handle);
    or, alternatively, like this:
    my $query = CGI->new; my $registration = OurWebsite::User::Registration->new($query); my $success = $registration->store($database_handle);
    Sure, that's contrived. But the point is that passing around dozens of arguments is ridiculous. If you changed the function to take named arguments, you'd be passing twice as many arguments total (the args and their names.) Working with that much cruft is neither easy nor necessary. Build a data structure that holds that information once, as you parse it, and then pass around a single reference to that structure.

    -sauoq
    "My two cents aren't worth a dime.";
    
      They're not wrapped in a data structure, 'cos that's the way the code is, and modifications are needed by tomorrow.

      --
      bowling trophy thieves, die!