Test cases and static typing
Pascal Costanza
costanza at web.de
Mon Oct 27 11:38:52 EST 2003
Fergus Henderson wrote:
> Pascal Costanza <costanza at web.de> writes:
>
>
>>What I want is:
>>
>>testxyz obj = (concretemethod obj == 42)
>>
>>Does the code compile as long as concretemethod doesn't exist?
>
> No, because the likelihood of that being a typo (e.g. for `concrete_method')
> is too high.
This proves that a static type system requires you to write more code
than strictly necessary. (Please think twice before you react. This is
not meant as a pejorative remark, even if it strongly sounds like one.
It's just an objective truth. Even if you think that this is how it
should be, it doesn't make my statement wrong.)
> I recently added support to the Mercury compiler for an option
> "--allow-stubs". For the equivalent code in Mercury, if this option
> is enabled, then it will compile if there is a _declaration_ for
> concretemethod, even if there is no _definition_. The compiler will
> issue a warning and automatically generate a stub definition which just
> throws an exception if it is ever called.
>
> It would be fairly straight-forward to also add support for allowing
> code like that to compile even if there was no declaration, but that
> does not seems like a good idea to me -- it would make it easier for
> typos to go unnoticed, with insufficient compensating benefit.
A good development environment gives you immediate feedback on such
kinds of typos. A good compiler for a dynamically type language issues a
warning. So these typos don't go unnoticed. The only difference is that
a dynamically typed language trusts the programmer by default, whereas a
statically typed languages doesn't trust the programmer. (To rephrase
it: A statically typed language gives you stricter support, while the
dynamically typed language gives you weaker support. But that's a
actually more or less the same statement.)
> I'm sure it would also be easy for developers of other statically typed
> languages to implement what you want, if they thought it was a good idea.
Of course.
It might be interesting to note that dynamically typed language are
probably a really bad idea when you don't have a good IDE. The features
that fans of statically typed languages care about are usually regarded
as part of the development environment's jobs. This is only to indicate
that programming in a dynamically typed language is not as horrible as
you might think when seen in the right context.
And here is one of the probable replies: Statically typed languages
don't require a sophisticated IDE in order to do useful work. This might
be an advantage in some scenarios.
Pascal
--
Pascal Costanza University of Bonn
mailto:costanza at web.de Institute of Computer Science III
http://www.pascalcostanza.de Römerstr. 164, D-53117 Bonn (Germany)
More information about the Python-list
mailing list