Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^4: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20

by tobyink (Canon)
on Nov 23, 2013 at 16:32 UTC ( [id://1064041]=note: print w/replies, xml ) Need Help??


in reply to Re^3: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20
in thread use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20

Indeed. And if postfix dereferencing was deemed so necessary, I think there are better ways it could have been accomplished. In particular, if autoboxing were made a core feature (and there are widely used autoboxing extensions on CPAN already as proof of concept) then we could just define methods:

sub SCALAR::SCALAR { ${+shift} } sub ARRAY::ARRAY { @{+shift} } sub HASH::HASH { %{+shift} }

And hey presto! Postfix dereferencing!

my $scalar = $sref->SCALAR; my @array = $aref->ARRAY; my %hash = $href->HASH;
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^5: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20
by BrowserUk (Patriarch) on Nov 23, 2013 at 18:00 UTC
    In particular, if autoboxing were made a core feature ...

    I see no purpose or benefit in autoboxing either. Pseud-OO doesn't float my boat in any way whatsoever.

    See Re: What are the drawbacks of autobox? and Re^3: What are the drawbacks of autobox? and Re^5: What are the drawbacks of autobox? if you are interested in details, but in a nutshell, I see not just zero value, but negative value in wrapping over simple, obvious & well understood data abstractions like arrays and hashes in syntactic sugar to make them look like objects.

    Some concepts and paradigms neatly lend themselves to object->action(args) notation, but for others it's a clunky, unhelpful force-fit that serves only to dumb-down the language, as if programmers are only capable of handling a single syntactic form.

    Authors could reduce every sentence to the iconic 'The cat sat on the mat' form, rather than use forms like 'Upon 400 knot Persian silk rug, the feline reposed contently'; but damn literature would be boring.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.

      The advantage of autoboxing, is not to make this easier:

      my $error = 3.1415927->minus( 22->divide( 7 ) )->abs();

      But rather, if I write a function that deals with $href entirely though method calls rather than the built-in keywords, and document that I have done so, then somebody calling that function is now able to pass it, instead of a hashref, a blessed object providing the same interface; i.e. polymorphism.

      This can be achieved somewhat using tied variables, but the interface is very low-level - it's not easy to, say, quickly override the order a foreach loop will traverse an array.

      Besides which, in the former example you are hideously breaking encapsulation by using the assignment operator! ;-)

      (my $error)->set_value( 3.1415927->minus( 22->divide( 7 ) )->abs() );
      use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
        then somebody calling that function is now able to pass it, instead of a hashref, a blessed object providing the same interface; i.e. polymorphism.

        This is an interesting argument. Particularly this bit:

        it's not easy to, say, quickly override the order a foreach loop will traverse an array.

        Any chance of you knocking up an example for this?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        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.

      Authors could reduce every sentence to the iconic 'The cat sat on the mat' form, rather than use forms like 'Upon 400 knot Persian silk rug, the feline reposed contently'; but damn literature would be boring.

      I’d have boring code over unreadable code any time. Code isn’t supposed to have literary merit; it’s supposed to be consistent.
        Code isn’t supposed to have literary merit;

        Don't be so literal. Think. Interpret. Apply a little imagination.

        If someone says it is raining cats and dogs, do you look up expecting to see falling tabbies and chihuahuas?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        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.
Re^5: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20
by LanX (Saint) on Nov 23, 2013 at 17:04 UTC
    Agreed!

    Autoboxing on compiler-level would be such a bless...

    ATM we need weird hacks to achieve this in the proof of concepts you are mentioning. (manipulating UNIVERSAL, overloading operators,...)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re^5: use feature 'postderef'; # Postfix Dereference Syntax is coming in 5.20
by Rhandom (Curate) on Nov 25, 2013 at 14:48 UTC
    I agree. Correct autoboxing is the correct solution, not throwing arbitrary symbol characters at it. I know that there is no support anywhere in the mechanics of perl to have correct autoboxing. However, this current solution is the wrong solution and will not help promote perl, and likely will help detractors continue to detract. Features should be evolving in the direction of Perl 6 where possible, not wander tangentially in odd directions.

    I know this was discussed extensively by rjbs on the list. I think in this case this was promoted because of too much echo on p5p.

    my @a=qw(random brilliant braindead); print $a[rand(@a)];

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-23 20:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found