On Wed, May 02, 2012 at 09:55:13AM -0400, David Golden wrote: > On Wed, May 2, 2012 at 9:25 AM, Tom Christiansen <tchrist@perl.com> wrote: > > Is > > > > $s = `proggie`; > > > > really that much harder than: > > > > $s = f(); > > > > Just curious. > Second order: it's often easier to get (structured) data back from a > function and test correctness than to capture output and parse it for > correctness, plus the data is probably more constant than the output > formatting, which makes tests less fragile. Some actual output > testing is always good, but that's not where I prefer to start. Also, output intended for humans isn't an API. Code which has to parse "pretty" output inevitably makes assumptions about the structure, which runs the risk of blows up when someone tries to make what they rightly think is a cosmetic change. See, for instance, all the recent "fun" when Carp added a single character to its output. Or that we got complaints when we slightly changed the output of `perl -v` because someone, somewhere was relying on its format. Yes, in this case, both ends of the pipeline are under our control, so such explosions aren't going to happen anywhere near as easily. But we still have to figure out how to instruct the outer program how to correctly call the *uninstalled* inner program with the correct interpreter and correct library path overrides, which is also pain. Once testing gets involved, it's generally much easier to write something as a module that implements the guts, and the harder-to-test part (be it invoked command, CGI script, webservice, etc) as the thinnest practical layer round that. Nicholas ClarkThread Previous | Thread Next