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

Re^2: Recap: The Future of Perl 5

by Ovid (Cardinal)
on Aug 23, 2018 at 23:46 UTC ( [id://1220972]=note: print w/replies, xml ) Need Help??


in reply to Re: Recap: The Future of Perl 5
in thread Recap: The Future of Perl 5

Agreed, but it's not core Perl, it's not well-known, and it's not nearly as useful as the proposed syntax.

Replies are listed 'Best First'.
Re^3: Recap: The Future of Perl 5
by hippo (Archbishop) on Aug 24, 2018 at 08:23 UTC
    Agreed, but it's not core Perl

    I think it would aid clarity to your arguments immensely if you could choose a different word for what you want. The Perl community has been using "core" to mean precisely modules which are bundled with the perl distro since last millennium (and I know you know this too). It's confusing if you start to use it to mean something else.

      In fairness, the built-in Perl functions are associated with the package CORE:: too, so his terminology makes sense in that respect.

Re^3: Recap: The Future of Perl 5
by RonW (Parson) on Aug 27, 2018 at 20:05 UTC

    I agree, your proposed syntax is much nicer.

    I did see somethings surprising.

    In:

    class Point { has Num ($x, $y); method inverted () { return Point->new( x => $y, y => $x ); } }

    you have $x instead of $self->x (likewise for $y).

    I found this surprising, and had to pause to think for a second or 2. How common is it in other OO languages to not need "self" to reference instance variables in instance methods? Personally, I don't recall ever seeing it done without "self". (Been so long since I last used C++ that I had forgotten.)

    More surprising was:

    class Cache::LRU { use Hash::Ordered; our $num_caches = 0; # class data (unused +in this example) my $x = Hash::Ordered->new; # private instance da +ta has UInt $max_size = 20; # public instance dat +a method set ( Str $key, $value ) { if ( $x->exists($key) ) { $x->delete($key);

    where $x is also an instance variable.

    (Just some additional thoughts.)

      I found this surprising, and had to pause to think for a second or 2. How common is it in other OO languages to not need "self" to reference instance variables in instance methods? Personally, I don't recall ever seeing it done without "self". (Been so long since I last used C++ that I had forgotten.)

      Java does this too. You can disambiguate (if you have a local variable of the same name), with this. For example, this.x.

      IIRC is Ruby using sigils for @instance and @@class variables..

      Python has self, JS has this.

      But JS is setting this implicitly, i.e. it's not the first argument like self in Python and Perl.

      You could mimic the semantics of JS and Ruby with closure variables holding references...

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      update
      added references

      update

      PHP seems to have an implicit $this.

        Yep, PHP has an implicit $this, and also has self which refers to the current class (not object).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-11-05 06:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    chatterbot is...






    Results (27 votes). Check out past polls.