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.
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
| [reply] [d/l] |
|
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');
| [reply] [d/l] [select] |
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
| [reply] |
|
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?
| [reply] [d/l] |
|
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
| [reply] [d/l] [select] |
|
|
|
|