Could Python supplant Java?
duncan at NOSPAMrcp.co.uk
Wed Aug 21 11:43:01 CEST 2002
Peter Hansen <peter at engcorp.com> wrote in
news:3D62CCFE.BF1237D9 at engcorp.com:
> TDD and Python are an *excellent* fit, since TDD benefits greatly from
> Python's very dynamic nature and flexilibity, while TDD supports
> Python almost perfectly in one area where it seems many feel it has
> a weakness - compile-time error checking.
I read something by Kent Beck that highlights one of the problems you
get from compile-time error checking when doing TDD in Java:
(from a draft of 'Test-Driven Development By Example')
"""As a result of using Self Shunt, you will see tests in Java
implementing all sorts of bizarre interfaces. In optimistically typed
languages, the test case class need only implement those operations that
are actually used in the running of the test. In Java, however, you have
to implement all the operations of the interface, even if most of the
implementations are empty, so you would like interfaces to be as narrow
as possible. The implementations should either return a reasonable value
or throw an exception, depending on whether you want to be notified if
an unexpected operation is invoked."""
To summarise for the benefit of anyone suffering from buzz-word-overload,
when you write a test for an object that uses another object, e.g. reads
from a file, you may make the testcase class implement something that
dummies out the 'file' interface and passes itself to the object under
test. With Python, if all that happens is that the object under test reads
the file, you just implement a dummy 'read' method. In Java you might also
need to implement close and isOpen methods even though they are never
called. If the Java interfaces aren't sufficiently narrow you might find
you have to implement a very large number of spurious methods in each test.
-- Duncan Booth
duncan at rcp.co.uk int month(char
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list