Replies: 3 comments 3 replies
-
The use Object::Pad;
class C {
field $_fieldvar :reader :writer;
method m { ... $_fieldvar is visually distinct here... }
} I'm in two minds about whether we should add them to
and honestly that's about all. I can't really think of any other advantage of actually having them. There is a possible idea that the notation of them does lend itself a way to get access to field variables of other instances than field $:x;
field $:y;
method cmp($other) {
return $:x <=> $other:x || $:y <=> $other:y;
} but that's fairly outlandish at the moment. Whereas, on the con side:
I was initially in favour of having them, only I couldn't implement it in At the moment I am leaning towards saying we shouldn't do these in core perl - or, at least, if we do they'd be optional. Making them optional means it is possible at all to write code using |
Beta Was this translation helpful? Give feedback.
-
Summarizing the above ... Do nothing.This is the easiest. Pros and cons.
|
Beta Was this translation helpful? Give feedback.
-
I still don't like the idea of twigils for Perl fields (ETOOMUCHPUNCTUATION). The problem to be solved is: it's tough to distinguish field variables from other "internal" variables and parameters I would have thought the easiest solution was to reverse the Taking @Ovid's original example, that would mean: field $attrseq;
field $attr;
method set_attrs (@_pairs) {
my $_sequence = [ $attrseq->@* ];
my $_attributes = { $attr->%* };
while ( my ( $_attribute, $_value ) = splice @_pairs, 0, 2 ) {
$_attribute = lc $_attribute;
unless ( exists $_attributes->{$_attribute} ) {
push @$_sequence => $_attribute;
}
$_attributes->{$_attribute} = $_value;
}
return $self->_rewrite_tag( $_sequence, $_attributes ); Or taking a subsequent example of field/parameter name clashes: class Foo {
field $name :param;
method set_name ($_name) {
$name = $_name;
}
method reverse_name () {
return scalar reverse $name;
}
} If we have to have something more than a convention, then I'm very much opposed to "optional" field twigils. That is, you would have to write: class Foo {
field $*name :param;
method set_name ($name) {
$*name = $name;
}
method reverse_name () {
return scalar reverse $*name;
}
} I'd still (marginally) prefer magical underscores to twigils. But in as unmagical a form as possible. But again, I'm still not convinced we really need either mechanism. |
Beta Was this translation helpful? Give feedback.
-
In my work to translate existing code to use Corinna, I did find it a bit frustrating to not have a clear indication of what's a
field
variable:Twigils would instantly solve that, but I objected at first because I was concerned that even more punctuation added to the language would not help. I think I may have been wrong. However, what twigil would we use? Many of them are already used for special variables. This makes parsing much harder. But imagine if we didn't allow formats to be declared in classes (they're almost dead anyway, right?). We could use
field bar :param
and have a$:bar
variable. Now it's easier to distinguish:However, for the colon, people could type
$::attr
and not realize they're getting$main::attr
instead. Oops.The subscript operator is a possibility:
$;var
, but it's ugly (yes, that's subjective).$*var
is also a possibility as it was removed in v5.10.0.$=var
.$=
is for formats and we'd have to ban them in classes.Beta Was this translation helpful? Give feedback.
All reactions