OO in Python? ^^

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sun Dec 11 11:20:46 EST 2005


On Sun, 11 Dec 2005 07:10:27 -0800, bonono wrote:

> 
> Steven D'Aprano wrote:
>> > And I don't think Haskell make the programmer do a lot of work(just
>> > because of its static type checking at compile time).
>>
>> I could be wrong, but I think Haskell is *strongly* typed (just like
>> Python), not *statically* typed. At least the "What Is Haskell?" page at
>> haskell.org describes the language as strongly typed, non-strict, and
>> allowing polymorphic typing.
>>
> What is your definition of statically typed ? The non-strict as far as
> I know is not referring to type checking. It does check type at compile
> time though it is quite different from language like C, Java, the
> polymorphic typing.

Strongly typed means that objects have a type. All objects in Python have
a type.

Strongly typed languages like Python forbid you from performing operations
on mismatched types, e.g. 1 + "1" does not work. In order to perform
operations on mismatched types, you must explicitly perform a conversion,
e.g. 1 + int("1").

Weakly typed languages do not prevent you performing operations on
mismatched types, e.g. something like 1 + "1" is allowed in languages like
Basic and Perl.

Untyped languages do not have any type information at all -- everything
is just bytes. The most obvious example is assembly language.

It should be noted that strong and weak typing is a matter of degree:
despite being mostly strongly typed, Python does do automatic coercion of
ints and floats, and although it is (arguably) weakly typed, Perl won't
allow you to treat scalars as arrays or vice versa.

Dynamic typing means that variables can be dynamically set to objects of
wildly different types. For Python, we would say that any name can be
bound to any object of any type.

Static typing is the opposite of dynamic typing. Once a variable or
name is defined as a certain type (either by a declaration, or
implicitly the first time it is used), it can only be assigned to values
of that same type.

These two articles may be helpful:

http://www.voidspace.org.uk/python/articles/duck_typing.shtml
http://www.artima.com/forums/flat.jsp?forum=106&thread=7590


A thoughtful defence of static typing is here:

http://www.xoltar.org/misc/static_typing_eckel.html

The fact that it is sub-titled "How Java/C++/C# Ruin Static Typing for the
Rest of Us" should give some idea what it is about.


-- 
Steven.




More information about the Python-list mailing list