Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: What are the drawbacks of autobox?

by dsheroh (Monsignor)
on Mar 01, 2010 at 11:22 UTC ( [id://825871]=note: print w/replies, xml ) Need Help??


in reply to Re^2: What are the drawbacks of autobox?
in thread What are the drawbacks of autobox?

There's flexibility and there's following fads.

Show me a valid, real-world use case in which there is a significant advantage to treating the number 3 as an object rather than as a simple integer and I'm happy to be flexible and consider whether I would find a benefit in doing things that way. Until then, the idea that everything must be an object and all action should be expressible as method calls looks an awful lot like a fad to me.

Replies are listed 'Best First'.
Re^4: What are the drawbacks of autobox?
by LanX (Saint) on Mar 01, 2010 at 11:54 UTC
    Show me a valid, real-world use case...

    OK one more try:

    This is valid JS Code: ¹

    var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write(fruits.push("Kiwi") + "<br />"); document.write(fruits.push("Lemon","Pineapple") + "<br />"); document.write(fruits);

    this is still valid JS-Code

    var $fruits = ["Banana", "Orange", "Apple", "Mango"]; document.write($fruits.push("Kiwi") + "<br />"); document.write($fruits.push("Lemon","Pineapple") + "<br />"); document.write($fruits);

    with the help of autobox this could become valid perl code:

    my $fruits = ["Banana", "Orange", "Apple", "Mango"]; document->write($fruits->push("Kiwi") + "<br />"); document->write($fruits->push("Lemon","Pineapple") + "<br />"); document->write($fruits);

    or maybe better without overloading +

    my $fruits = ["Banana", "Orange", "Apple", "Mango"]; document->write($fruits->push("Kiwi") . "<br />"); document->write($fruits->push("Lemon","Pineapple") . "<br />"); document->write($fruits);

    Real world enough for you???

    Cheers Rolf

    ¹) from my first google hit on "javascript push" http://www.w3schools.com/jsref/jsref_push.asp

    UPDATE: corrected . to ->

Re^4: What are the drawbacks of autobox?
by LanX (Saint) on Mar 01, 2010 at 11:31 UTC
    Show me a valid, real-world use case in which there is a significant advantage to treating the number 3 as an object rather than as a simple integer

    Your reducing the possibilities of autobox to a little feature.

    And did I ever say I want to call a method on 3?

    I'm really surprised by the emotions caused by this little question about the technical side-effects of a cpan module, I didn't expect the Spanish inquisition...

    Cheers Rolf

      Fair enough. On further reflection, this thread is suffering from a bad case of excluded-middle: The anti-autobox folks (myself among them) are trying to push you into defending the position that everything should be objects, when you've not stated that this should be the case.

      I do see potential benefit to making at least some array/list/hash operations available as methods. I don't see it as a strong benefit in general, but reasonable people can differ on that. In the particular case of your javascript fruit basket, it reads more naturally to me in the standard Perl syntax than the js/autobox version, but that may just be a matter of acclimation; what would read most naturally to me would be "push 'kiwi', @fruits", to mirror English "push kiwi onto fruits", but I've not seen a language which allows that ordering.

        Try Common Lisp, it has (pushobj place)
        Hi

        > The anti-autobox folks (myself among them) are trying to push you into defending the position that everything should be objects, when you've not stated that this should be the case.

        Thx finally my message got thru. :)

        To be clear: After use autobox you are still free to write push @fruits, 'kiwi', that's perfect TIMTOWTDI! (UPDATE: And it's not turning the primitives into objects!)

        > what would read most naturally to me would be "push 'kiwi', @fruits", to mirror English "push kiwi onto fruits"

        Thx again, you brought an example I had in mind about how absurd this argument about Perl reflecting natural language is.

        For technical reasons the direct object is NOT in first position in Perl's push()¹

        BUT with method chaining  $fruits_ref->push('kiwi')->push('banana') reflects naturally:

        "Take fruitbasket! Push kiwi! Push banana! ..."

        In natural grammar: The indirect object becomes a matter of context!

        (Nota bene: I'm not saying this example is better than  push @fruits,'kiwi','banana', it's just a fucking example about the analogies of natural and computer languages)

        > I don't see it as a strong benefit in general,

      • One of my vision is to code in Perl and to run it on JS Engines. Contrary to other languages Perl has the flexibility to allow this. And JS is very flexible in extending the core functionality.

        (My example should show a way to achieve this.)

        And JS Engines are universally available in Browsers , in Flash (Action Script) in .NET and Java (Rhino) and the JIT compiler of Chrome and and ...

        OTOH Perl has nothing to cope with IronPython or JRuby, which ARE important in marketing these languages. Code-reuse is alway an issue!

        "Then there's JavaScript, a nice clean design. It has some issues, but in the long run JavaScript might actually turn out to be a decent platform for running Perl 6 on." -- Larry Wall

      • Another vision is to show to the hype folks running to Ruby that all there OO concepts from Smalltalk can be easily backported one-by-one to Perl.

        Cheers Rolf

        ¹) you can't turn the prototype push(\@;@) around, without limiting the list of pushed elements!

        UPDATE: added links.

Log In?
Username:
Password:

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

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

    No recent polls found