Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^6: When every microsecond counts: Parsing subroutine parameters

by blazar (Canon)
on May 18, 2008 at 15:56 UTC ( [id://687218]=note: print w/replies, xml ) Need Help??


in reply to Re^5: When every microsecond counts: Parsing subroutine parameters
in thread When every microsecond counts: Parsing subroutine parameters

Named parameters means I don't have to pass a string of undefs because one particular call doesn't use those parameters. APIs using positional parameters have a way of requiring difficult upgrade path.

I personally believe that named parameters can indeed be very useful. In this sense Perl 6 with its extremely complete and flexible sub signatures is fantastic. Perl 5 is also charming for the far reaching semantics it can get out of its very simple mechanism of parameter passing, allowing one to emulate named parameters.

However, as far as your remark about "a string of undefs" (I presume you really mean "list") is concerned, I would like to point out that while the fact that several commas "collapse" into one fits perfectly well into Perl's semantics, I have occasionally desired say $x,,,,$y to be a shortcut for $x,undef,undef,undef,$y.

--
If you can't understand the incipit, then please check the IPB Campaign.

Replies are listed 'Best First'.
Re^7: When every microsecond counts: Parsing subroutine parameters
by CountZero (Bishop) on May 18, 2008 at 17:36 UTC
    I have occasionally desired say $x,,,,$y to be a shortcut for $x,undef,undef,undef,$y.
    Be happy that you need the undef! Counting the nothings between the commas must be one of the most frustrating exercises ever devised.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      I personally believe that's why I occasionally desire it, as opposed to constantly.

      Having stared at csv files with empty fields, I know what you mean, except that in that case the task can even be facilitated by the formatting of some fields. However there's a difference between say, fifteen adjacent commas and two or three. Anyway that's not something to be changed, so it's not worth discussing either. OTOH I often feel the need for some syntactical sugar to indicate a "missing something," whereas undef, however short, is somewhat obtrusive: Perl is already a hell to parse, but how 'bout a lonely minus sign?

      my $x = foo(42,-,-,'cool');
      --
      If you can't understand the incipit, then please check the IPB Campaign.
Re^7: When every microsecond counts: Parsing subroutine parameters
by talexb (Chancellor) on May 18, 2008 at 16:52 UTC

    Brilliant. Yet another clever way that Perl takes care of things automagically.

    I hadn't realized that, because I wasn't thinking Perlishly enough. Thank you.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      I personally believe there's been some misunderstanding. Granted, I'm glad to receive your thanks, but I can't remember having pointed out any "clever way that Perl takes care of things automagically" in the post you're replying to. Did I?

      --
      If you can't understand the incipit, then please check the IPB Campaign.

        Yes, you did. I was complaining about having to call a sub as follows

        foo(100,undef,undef,undef,"bar");
        when in fact this can be shortened to
        foo(100,,,,"bar");
        However, as was pointed out by some kind monk, you're left to worry about counting commas, since ,,,, looks a lot like ,,,,, from a distance.

        Alex / talexb / Toronto

        "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-25 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found