Classes

Classes are a bit easier to declare in python -- they are shorter and can go anywhere.

package Empty;
sub new {
    return bless({}, shift);
}       
sub nothing {undef};
package main;
$empty = new Empty;
$empty->nothing; #nothing happens
$empty->{something} = 2;
#empty is a hash {'something' => 2}

class Empty:
    def nothing(self):
        pass


empty = Empty()
empty.nothing() 
empty.something = 2
# empty.__dict__ is a hash {'something': 2}

A python class is an object that returns an object, but so is everything else. Classes are convenient for inheritance and mutability.

package Full;
sub new {
    my $class = shift;
    my $self = { @_ };    
    bless($self, $class);
    return $self;
}
class Full:
    def __init__(self, **keywords):
        self.__dict__ = keywords