[Melbourne-pm] Stack traces

Toby Corkindale toby.corkindale at strategicdata.com.au
Tue Feb 12 20:41:18 PST 2013


On 13/02/13 13:02, Sam Watkins wrote:
> On Wed, Feb 13, 2013 at 10:50:56AM +1100, Toby Corkindale wrote:
>> I've seen Java stack traces that are easier to figure out than this.
>
> <snip 646 line stack trace>
>
> Frankly, I think the solution is - don't use all that ridiculous bloated crap!
> Keep it simple.  If you can write it in one line, do so;
> Don't write 20 pages when 1 will do.  Don't use bloated 3rd party modules,
> only if they are as clean and simple as possible for the necessary task.

It's not really as simple as that.

> Read "The Practice of Programming" ...
> Chant "Simplicity, Clarity, Generality" ...

But there's also: Don't Repeat Yourself.
Don't copy and paste code around when you could use a single package.
But as requirements get more complex, so do your dependencies, which may 
themselves be simple, but be made up of many further dependencies.
Even if they are all relatively simple in and of themselves, the 
combination of all grows complex.


For example.. you could write a program like this, to check inputs 
(badly) for your subroutines:
----------------------------
sub foo {
   my ($self, $one, $two, %three) = @_;
   unless (defined $one and $one =~ /^\d+$/) { die "err for param one" }
   unless (defined $two and $two =~ /^\w+$/) { die "err in param two" }
   unless (exists $three{thing}) { die "missing thing in hashref" }
}

sub bar {
   my ($self, $one, $two, %three) = @_;
   unless (defined $one and $one =~ /^\s+$/) { die "err for param one" }
   unless (defined $two and $two =~ /^\d+$/) { die "err in param two" }
   unless (exists $three{bloop}) { die "missing bloop in hashref" }
}
----------------------------


Or, you could do it this way:
----------------------------
use Method::Signatures;
method foo (Int $one, Str $two, :$thing!) { }
method bar (Str $one, Int $two, :bloop!) { }
----------------------------


Now I'm sure you'll agree the latter method meets your own requirements 
for "If you can write it in one line, do it". Yet, it's added a 
dependency upon another module, which may itself be complex.



-Toby


More information about the Melbourne-pm mailing list