Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: What would you change?

by BrowserUk (Patriarch)
on May 19, 2008 at 02:43 UTC ( [id://687274]=note: print w/replies, xml ) Need Help??


in reply to Re^3: What would you change?
in thread What would you change?

I just sat and starred at the prototype of vec and tried to understand how it is a limitation?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^5: What would you change?
by dragonchild (Archbishop) on May 19, 2008 at 13:36 UTC
    my $thing = 'a' x 10; my @params = ( 2, 3 ); vec( $thing, @params ) = 0;
    That results with "Not enough arguments for vec()." And, illustrates in brilliant colors the stupidity of compile-time checking in a dynamic language.

    Frankly, if we wanted to have compile-time checks, we should be telling the compiler what we expect to happen. So, for example, if @params should have 2 and only 2 things, we should be able to say that. Then, vec() knows that if @params makes it to him, it's got two things. But, even that sucks because you'd have to assign two things to @params - you wouldn't be be able to build it up using push.

    So, compile-time checks suck.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      That results with "Not enough arguments for vec()." And, illustrates in brilliant colors the stupidity of compile-time checking in a dynamic language.

      I see what you mean. And boy, do I ever agree with you regarding attempts to force static language semantics upon dynamic languages.

      Playing with this, my first thought was to disable the prototype checking:

      &vec( $thing, @params ) = 1;

      but that resulted in: Can't modify non-lvalue subroutine call which came as a complete surprise.

      I never knew that the l-valueness of a subroutine was allied to its prototype. The best alternative I came up with is:

      sub myvec :lvalue { CORE::vec( $_[ 0 ], $_[ 1 ], $_[ 2 ] ) }

      which once you get past the deliberate error ;) in the example:

      my $thing = 'a' x 10; my @params = ( 2, 3 ); myvec( $thing, @p ) = 1;; Illegal number of bits in vec

      seems to work fine. Of course, you pay a performance penalty for the indirection, but hey. CPU cycles don't matter :)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        never knew that the l-valueness of a subroutine was allied to its prototype

        It's not. &vec calls vec of the package in which you happen to be, not the core function.

        >perl -e"&vec()" Undefined subroutine &main::vec called at -e line 1.

        The (presumably non-existant) vec in your current package is not an l-value sub, thus the error messag. You can't use & on core functions.

        The more I think about this vs. Haskell/Scala, the more I come to the conclusion that compile-time checking can actually work in a dynamic language. We just have to be smart about what we're checking. I mean, Haskell has compile-time checking all over the place and it's dynamic.

        I think the point here is that the more side-effect free you can be, the more comprehensive your checking can be. I'm not sure where this meander is going, though.


        My criteria for good software:
        1. Does it work?
        2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (8)
As of 2024-04-25 11:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found