Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: What's so bad about &function(...)?

by Ovid (Cardinal)
on Dec 07, 2005 at 18:57 UTC ( [id://514978]=note: print w/replies, xml ) Need Help??


in reply to Re^2: What's so bad about &function(...)?
in thread What's so bad about &function(...)?

Yes, but not everyone programs in a vacuum. Sooner or later they'll start using code which does have prototypes. Imagine, for example, that they start using Test::More. Those functions all have prototypes and using the leading ampersand is sure to bring them woe. Imagine, for example, typing "is" instead of "ok":

&is(some_func(3,4));

The prototype is now disabled so they don't get the compile-time failure telling them that the test function has been called incorrectly. If you're new to testing or that's buried in bunch of other tests, it can be quite difficult to figure out.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re^4: What's so bad about &function(...)?
by merlyn (Sage) on Dec 07, 2005 at 19:47 UTC
    Sooner or later they'll start using code which does have prototypes.
    Not if I can help it. Unless it's a specialized function that is trying to imitate a built-in, prototypes are forbidden in the code that I control.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re^4: What's so bad about &function(...)?
by sauoq (Abbot) on Dec 07, 2005 at 23:13 UTC

    Okay... so... uh... why the heck does Test::More use prototypes anyway?

    -sauoq
    "My two cents aren't worth a dime.";
    

      To catch bad tests by being very specific about functions such as is() and like() taking two, optionally three, arguments.

      Didn't write it. You'll have to ask the authors.

      However, I don't mind it. More than once it's caught me writing a bad test and I can't recall any time I've been bitten by it.

      Cheers,
      Ovid

      New address of my CGI Course.

Re^4: What's so bad about &function(...)?
by Perl Mouse (Chaplain) on Dec 08, 2005 at 17:23 UTC
    OTOH, if they write something like:
    $a[0] = some_func(2, 3); $a[1] = 17; # Expected outcome. &is(@a);
    their code runs fine, and it isn't getting generating errors about a mismatch of the number of arguments. I'd say that '&' disables mysterious side-effects.
    Perl --((8:>*

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-24 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found