Tags Perl
I'm now trying to convert my Perl MIX (Knuth's machine he uses to give programming examples in TAOCP) simulator to a class. Some observations:

  • No built in support for private methods - annoying. Sure, there are hacks like my $methodref = sub {..., but this makes calling methods clunky. I realize that Perl's philosopy is that there' no real need for private methods - but those DO have their uses...
  • Only now I notice how annoying the whole $self-> thing is. It's like calling everything through this in C++. For instance, in the simulator, to access the rA register, I must now do $self->rA. To access rI6, I must do $self->rI->[6], etc. This is really inconvenient !
Hmm... maybe I'll just go with a simple package for now - there, using Exporter and my variables, good encapsulation can be achieved, and I won't have to use $self all the time. I guess I'll wait for Perl 6 with its built-in OO support to reimplement it as an object.

Funny, I'm not usually an OO proponent - I believe that the best tool for the job must always be used, and sometimes this tool is OO. However, once I do use OO in Perl (not too often), I find it not too convenient and natural.