Objects in Python

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Aug 23 00:34:52 EDT 2012


On Wed, 22 Aug 2012 18:46:43 +0100, lipska the kat wrote:

> We need to separate out the 'view' from the 'implementation' here. Most
> developers I know, if looking at the code and without the possibly
> dubious benefit of knowing that in Python 'everything is an object'
> would not call this 'strong typing'

Most developers are wrong :)

A very useful resource to read is "What To Know Before Debating Type 
Systems", which was put on the internet, lost, then found and put back up 
here:

http://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/

I don't *quite* go so far as to agree that "strong typing" and "weak 
typing" are meaningless, but they certainly don't mean quite as much as 
people sometimes think.

It also includes this brilliant quote:

"I find it amusing when novice programmers believe their main job is 
preventing programs from crashing. ... More experienced programmers 
realize that correct code is great, code that crashes could use 
improvement, but incorrect code that doesn’t crash is a horrible 
nightmare."

In Python's case, we say:

1) objects are strongly typed -- every object has a type, which is 
usually immutable and sometimes known at compile time;

2) names (what some people insist on calling variables) are not typed at 
all (with the exception of a handful of keywords like None);

3) most Python built-ins are strongly typed, and users are discouraged 
from writing excessively weakly-typed operations (you could write an int 
subclass that can be added to a string or a list, just as you can add it 
to a float, but you shouldn't);

4) there's a culture of preferring "duck typing", which is kind of an ad 
hoc form of interfaces, over strict type testing, so users are also 
discouraged from writing excessively strongly-typed operations (if you 
just need something you can iterate over, why insist that it must be a 
list and nothing but a list?).


-- 
Steven



More information about the Python-list mailing list