Tassilo v. Parseval said:
Also sprach Anno Siegel:
XP being Extreme Programming. Say, Anno, you didn't really think that it
might have been something Redmondish? ;-)
Oh. Okay, sorry
Extreme Programming didn't come to mind.
Meanwhile, I have found the exact spot where I picked up this statement
for everyone to check:
http://www.extremeperl.org/bk/coding-style
Grep for 'fails fast'.
I have taken a look. I wouldn't necessarily conclude from that remark
that "failing fast" is a tenet of Extreme Programming. It simply states
the old argument that it is better to die than to risk doing damage.
In the particular case I tend to agree. The function that "fails
fast" here is the plan() function of Test.pm, whose only purpose is
to prepare for a number of tests to be run. In that capacity, deciding
not to run the tests when the plan is in error is entirely reasonable.
If someone really wants to run plan() for some other purpose, they can
wrap eval() around it.
I was rather thinking of libraries than programs. If you have a
function/method that is supposed to do destructive I/O and it is passed
garbage, it is certainly better to abort immediately than carrying on.
Otherwise it might happen that the function does half of the I/O and
then eventually dies leaving things in an inconsistent state.
To elaborate, when I say "die late" i don't mean to return an incomplete
or defective result with no indication. "Die late" implies that the
user *can* decide to die later, meaning that there must be an error
indicator. So the user can avoid the possible damage, but the
responsibility is his.
Someone could have decided to let system calls in Perl die in case of
errors, instead of returning a boolean success indicator. That would
save clpm a lot of admonitions that begin with "Always, yes *always*...",
reminding people of the responsibility they fail to take. We would also
see a whole lot of "eval { open(...) }; if ( $@ ) { ... }". I like it
the way it is.
I am always in favour of design on-the-fly. I still have vivid memories
of the kind of planning-hoops I had to go through at university. There
was one lab in particular, where we had to program a rather largish Java
application involving a GUI. It all began with writing boring
requirement specifications that were afterwards modelled into UML. As I
recall it, the class diagram I came up with did impress mostly everyone.
However, it turned out to be unimplementable in Swing because it assumed
an event-model that simply didn't exist in this widget set.
So I had to change everything. In the end, I secretly changed my UML
diagrams to fit my final program and hoped that no one would notice
(they didn't, of course). Had I designed the thing on-the-fly, the
result would have been very similar without the many hours of overhead
needed to create an UML diagram that no one cared about or wanted to
see.
I don't have a formal education in CS, and anecdotes like this tend to
ease my regret about that. From afar I have watched some diagramming
techniques come and go (flowcharts were discarded in the 70s, Nassi-
Shneiderman in th 80s). UML seems to be an OO equivalent -- I haven't
looked closer yet. They have always been put forward as a planning
tool, and there has always been a tendency to use them as an analysis
tool, i.e. draw the diagram for an already written program to understand
its structure.
What happened to you seems quite typical. What use is a perfect plan
when it turns out that there is no reasonable implementation under
practical constraints.
So I prefer the much more practical XP approach which essentially says:
"Implement the first thing that works and that you can think of and then
refactor". Perl is a wonderful language for that.
Indeed. However, it doesn't hurt to become aware of the pitfalls *this*
approach has. One of them is cramming too much functionality into a routine
you're writing, just because it's a good occasion (and also because the
ways the routine will be used aren't quite clear yet). Programmers like to
implement, it's the designer's job to decide what it worth implementing.
When the designer and the coder are the same person, at the same time,
that job becomes harder.
Anno