learnpython.org - an online interactive Python tutorial

Roy Smith roy at panix.com
Fri Apr 22 15:22:33 CEST 2011

In article <iorui3$a9g$1 at speranza.aioe.org>, Mel <mwilson at the-wire.com> 

> > Strings should auto-type-promote to numbers if appropriate.
> "Appropriate" is the problem.  This is why Perl needs two completely 
> different kinds of comparison -- one that works as though its operands are 
> numbers, and one that works as though they're strings.  Surprises to the 
> programmer who picks the wrong one.

Ugh, tell me about it.

The project I'm currently working on used to use PHP (which has the same 
auto-promotion semantics as Perl) as the front end to a SQL database.  
The PHP code gleefully turned strings into numbers and back again all 
over the place, but it all got cleaned up at the database interface 
since SQL has strict typing.

We converted the back end database to MongoDB, which does not have 
strict typing.  We're still cleaning up the mess of inconsistent data 
(i.e. string vs integer) that creeps into the database through various 
paths.  Not to mention 0 vs. '' vs null vs false.

Implicit type conversion can be convenient.  But, then again, so can 
removing the safety guards from a chain saw.

More information about the Python-list mailing list