Perl-Apollo / Corinna

Corinna - Bring Modern OO to the Core of Perl
Artistic License 2.0
156 stars 19 forks source link

consider syntax for "class X {}" without the "{}" #36

Closed dk closed 2 years ago

dk commented 3 years ago

I read the recent Damian Conway's article on the OO syntax, and one thing has struck me which is a bit inconsistent in the class {} syntax. Namely, his code example uses both "package X {}" and "class X {}" for declaring stuff for, respectively, packages and classes, but since Cor is not interested in packages, and perl already has the "package X;" syntax, these two namespace declarations are not that close to each other as I think as they may (and should) be.

What I mean is that since we have already

package X;

sub y {}

why shouldn't we have also

class X;

method y {}

?

That would be consistent with the existing syntax, and also all declarations won't need that extra space in front of them as in

class X
{
    method y {}
}
Grinnz commented 3 years ago

This is currently implemented in Object::Pad and there's really no technical reason it can't be part of Corinna.

haarg commented 3 years ago

I would prefer to allow class Foo;. The only caveat is that classes are intended to be "sealed" at the end of their compilation. But I think we could define classes to end at the end of the compilation unit, as well as if the class or package is changed.

Ovid commented 3 years ago

This might eventually happen, but for now, the postfix block means we don't need to worry about lexical leaking into another scope, or new keywords leaking beyond that scope. We have a much more constrained problem space.

Per our Principle of Parsimony, not requiring a postfix block for the MVP could be a decision that would be hard to walk back if people start relying on Corinna, but a postfix block is trivial to walk back. Thus, this is a post-MVP discussion.

Update: I see some issues were addressed above by Grinnz and haarg. We might make this happen later, but I would really prefer avoiding this in the MVP.

Ovid commented 2 years ago

Closing this ticket. We may (will) revisit post v1.