Python from Wise Guy's Viewpoint
Pascal Costanza
costanza at web.de
Wed Oct 22 21:15:34 EDT 2003
Fergus Henderson wrote:
> Pascal Costanza <costanza at web.de> writes:
>
>
>>Marshall Spight wrote:
>>
>>>But why should more regression testing mean less static type checking?
>>>Both are useful. Both catch bugs. Why ditch one for the other?
>>
>>...because static type systems work by reducing the expressive power of
>>a language. It can't be any different for a strict static type system.
>>You can't solve the halting problem in a general-purpose language.
>
>
> Most modern "statically typed" languages (e.g. Mercury, Glasgow Haskell,
> OCaml, C++, Java, C#, etc.) aren't *strictly* statically typed anyway.
> They generally have some support for *optional* dynamic typing.
>
> This is IMHO a good trade-off. Most of the time, you want static typing;
> it helps in the design process, with documentation, error checking, and
> efficiency.
+ Design process: There are clear indications that processes like
extreme programming work better than processes that require some kind of
specification stage. Dynamic typing works better with XP than static
typing because with dynamic typing you can write unit tests without
having the need to immediately write appropriate target code.
+ Documentation: Comments are usually better for handling documentation.
;) If you want your "comments" checked, you can add assertions.
+ Error checking: I can only guess what you mean by this. If you mean
something like Java's checked exceptions, there are clear signs that
this is a very bad feature.
+ Efficiency: As Paul Graham puts it, efficiency comes from profiling.
In order to achieve efficiency, you need to identify the bottle-necks of
your program. No amount of static checks can identify bottle-necks, you
have to actually run the program to determine them.
> Sometimes you need a bit more flexibility than the
> static type system allows, and then in those few cases, you can make use
> of dynamic typing ("univ" in Mercury, "Dynamic" in ghc,
> "System.Object" in C#, etc.). The need to do this is not uncommon
> in languages like C# and Java that don't support parametric polymorphism,
> but pretty rare in languages that do.
I wouldn't count the use of java.lang.Object as a case of dynamic
typing. You need to explicitly cast objects of this type to some class
in order to make useful method calls. You only do this to satisfy the
static type system. (BTW, this is one of the sources for potential bugs
that you don't have in a decent dynamically typed language.)
>>I think soft typing is a good compromise, because it is a mere add-on to
>>an otherwise dynamically typed language, and it allows programmers to
>>override the decisions of the static type system when they know better.
>
> Soft typing systems give you dynamic typing unless you explicitly ask
> for static typing. That is the wrong default, IMHO. It works much
> better to add dynamic typing to a statically typed language than the
> other way around.
I don't think so.
Pascal
More information about the Python-list
mailing list