I know about properties in python and how they make it possible to use a classes attribute just like before but with some possible modification in between.
Anyway, having done some perl recently I came to love the idea of having even less code and having getter and setter combined
like:
sub filename {
my $self = shift;
my $filename = shift;
if ($filename){ $self->$filename = $filename;}
else {return $self->$filename;}
}
Obviously in perl you can omit the () behind the method which makes this approach "cleaner" and more transparent to the users of my class.
In py I could do similar the only downside being the need for () when accessing:
def filename(self, setter=None):
if setter is not None:
self._filename = setter
else:
return self._filename
To me this is just way more compact then doing the property thing and I believe my code is more readable.
So is there anything wrong with my approach or is it unidiomatic for some reason?
Thanks!