It's approaching the middle of November, and here in Gloucester it's started to get really quite cold.
But, you know, I'm not bitter by any stretch. It's a million times warmer than it was when I was living in Scotland (really a million - try living there if you don't believe me). I think today will be the last day of "just a t-shirt" for a while though. It was just too cold. I would have only gotten away with a t-shirt up until september in scotland though.
Appologies to all scots. I'm sure some parts of your country are lovely (well, some parts are), but your weather sucks, and Livingston was just nasty.
Oh, and perl's OO is broken...
picture this:
package Base;
my %FEATURES = (a => 1, b => 0, c => 1);
sub features {
my @features;
foreach (keys %FEATURES) {
push @features, $_ if $FEATURES{$_};
}
return @features;
}
1;
and a sub-class:
package SubClass;
use base 'Base';
my %FEATURES = (a => 0, b => 1, c => 1);
1;
Now query SubClass->features(), and you get ('a', 'c').
This is covered somewhere in Damian's book, I recall, but it's a gotcha that people used to true OO should watch out for.
The way to fix it is to make the FEATURES hash into a method call that returns a hash. This way, when you call the base features() method, and it looks up the FEATURES hash, it gets the inherited method, and thus the right set of FEATURES.
I'm sure this will be fixed in Perl 6, otherwise I'll be around to kick Damian's butt
Not Broken (Score:1)
Re:Not Broken (Score:1)
package main;
my %FEATURES = (a => 1, b => 0, c => 1);
print Base->features;
package Base;
sub features {
my @features;
foreach (keys %FEATURES) {
push @features, $_ if $FEATURES{$_};
}
return @features;
}
1;
It returns ('a', 'c'), even though the variable is declared in main ... because the data is not declared in any package at all,
Re:Not Broken (Score:1)
It's still annoying, and something that would "work" in other OO languages, without using the data-as-sub work around.
Warm (Score:1)
Try Class::Data::Inheritable (Score:1)
Perl does not have any way to inherit class data, which is lame.
Check out Schwern's Class::Data::Inheritable for a solution.
-dave
Re:Try Class::Data::Inheritable (Score:1)
Re:Try Class::Data::Inheritable (Score:1)
My point was that you shouldn't even _expect_ it to work with 'my'. With 'our' (or a global) you might think that it _should_ work (though it wouldn't).
I was basically saying that even though pudge was right, he was missing your main point, which was simply that Perl should have inheritable class attributes.
-dave
Re:Try Class::Data::Inheritable (Score:1)