Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

heusserm (4461)

  (email not shown publicly)
AOL IM: MatthewHeusser (Add Buddy, Send Message)

Matt Heusser is JAPH and an XP-Er []. (The Methodology, not the Operating System.) Right now, he's doing a lot of Test Driven Development in Perl.

Journal of heusserm (4461)

Thursday September 11, 2003
07:23 AM

Simplest Thing that could possibly ... redux

[ #14653 ]
Ok, so here's the function:

sub RemoveSpaces
        my $s = shift;
        return $s;

Here's the thing: This couldn't possibly break.

Does this mean that I don't need to test it, or at least I don't need to automate the testing of it?

One of the big elementes of XP and "well-factored" code is small sub-routines. Subs that are small enough that you can understand everything that is going on - or subs small enough to only need one comment, and that comment is the name of the sub.

In CS 611 (Software Engineering), we talked about collapsable code a lot. Basically, if you only have one return per function and don't have any knotted loops, it's possible to get complete code coverage of an entire function. If your next-level function does the same, you can abstract the lower-level function out and get code coverage of the higher function.

XP then provides two benefits:

1) Smaller systems have less complexity, and thus less bugs. XP emphasises keeping code small and simple.

2) Functions in XP stay small. There are less things that can break - examining a small portion of a chess board is much easier than trying to examine the entire board and all the possibilities. This leaves less things that can possible break.

And having less things that can possibly break is a very good thing.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • sub RemoveSpaces
              my $s = shift;
                  return $s;
    ... Here's the thing: This couldn't possibly break.
    And yet, it's invalid syntax. It is broken.

    Test early, test often, test always.

    • Randal L. Schwartz
    • Stonehenge
  • Though a test would catch that it doesn't compile (as Randal points out), it would also allow you to change it later to something like this:

    sub RemoveSpaces
        my $s = shift;
        $s =~ tr/ \b\r\n\f//d;
        return $s;

    It's okay if you don't want to do that, but I'd prefer it to the regex.

  • > Here's the thing: This couldn't possibly break

    What happens if you get undef?