Dear monastery!

In continuation to

I tried to hack a proof of concept for a concise OO syntax

The basic ideas are that:

Declaration of instance variable
Access of instance variables inside methods
$self
Methods

{ use Class BLA => ISA-LIST; use Data::Dump qw/pp/; my Int ($x,$y) :has :rw = (10,11); sub set_x { my ($var) = @_; #warn "set_x $$x -> $var \n"; $$x = $var; } sub print_x { print "x = $$x \n"; } sub print_self_x { print "x = $self->{x} (via \$self)\n"; } sub dump { warn '$self:',\$self; warn pp '$self: ', $self; warn pp '$$x: ', $$x; warn pp '$$y: ', $$y; } }

The implementation is done via a macro expansion from use Class which injects some boilerplate into the head of the class, which handles the creation.

Injecting is basically done via a source filter or alternatively via Keyword::Simple. NB: just injecting some code doing introspection. No parsing, regexing or modification of the code you see.

I'm supposing this concise syntax could be used as a front end for all current OO models in Perl and might help offering a stable backwards compatible syntax if it's hardcoded into the engine.

A rough proof of concept follows here:

NB: This example is pretty barebone, and not meant to be an alternative to other OO Frameworks, but rather a frontend. It doesn't create accessors and the constructor is only simplistic.

Comments?

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

Replies are listed 'Best First'.
Re: RFC: Concise OOP Syntax
by daxim (Curate) on Aug 05, 2019 at 09:08 UTC
    As I've told you several times, your assumptions [m]ost of us are stuck with an older version of Perl and [t]he crucial problem for the acceptance is backwards compatibility are just not true. (I don't know the name of the logical fallacy, but essentially you project your own position and circumstances onto everyone.) You burden yourself with a lot of work that is based on false premises and – if finished – is realistically useful only to a minuscule amount of users.

    The rest can (and could for years) install Moops and get to enjoy superb class/roles/methods/types syntax sugar.

    use Moops; use Data::Dx; class BLA extends SOME::PARENT with SOME::ROLE, ANOTHER::ROLE { has x => is => 'rw', isa => Int, writer => 'set_x', default => 10; has y => is => 'rw', isa => Int, writer => 'set_y', default => 11; method print_x() { printf "x = %s\n", $self->x; } method dump() { Dx $self; } } my $bla = BLA->new; $bla->set_x(42); $bla->print_x; $bla->dump;
    If I had your skill and internals knowledge, I would improve Moops to add sugar for self-less attributes and less verbose attribute declarations.
      And I told you several times that I disagree.

      Thanks for the link mention of Moops, but it doesn't look like a syntax which will ever get into core.

      PS:

      > most of us are stuck with an older version

      never said this.

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

      update

      https://metacpan.org/pod/Moops

      sigh ...

      > STATUS

      > Unstable.

      > Until version 1.000, stuff might change, but not without good reason.

Re: RFC: Concise OOP Syntax
by daxim (Curate) on Oct 21, 2019 at 12:30 UTC