Peter Stuifzand

Small safe steps

I really like the notion Safe steps in Responsive Design:

Safe Steps. Resolve the tension between efficiency and safety in favor of safety, then learn to take small, safe steps fast enough that from the outside it looks like you are flying.

I want to show an example of a change that changes the interface, without the need to change the callers. In the end I want to remove the call to get_controller_class. But first I make a small safe step. I have a method like this (in Perl).

sub create_controller_object {
    my ($self, $path, $context) = @_;
    my $class = $self->get_controller_class($path);
    my $obj = $class->BUILD({context => $context, controller => $path->{controller}});
    return $obj;
}

I want to allow the caller to pass the $class, so it will allow me to specify a different class than would be returned by get_controller_class.

I could change both the caller and this method and make the change at once. But the could break code and become a problem.

sub create_controller_object {
    my ($self, $path, $context, $class) = @_;
    $class //= $self->get_controller_class($path);
    my $obj = $class->BUILD({context => $context, controller => $path->{controller}});
    return $obj;
}

This code still does the same thing for all callers. But new callers can specify the $class parameter.

Now I can change all the callers to pass the result of get_controller_class from outside this method. If all callers are changed, then I can remove the call in this method.

This is really simple, almost to simple. That’s what it is about.

© 2023 Peter Stuifzand