Could Python supplant Java?

laotseu bdesth at nospam.free.fr
Wed Aug 21 19:15:43 EDT 2002


FISH wrote:
> Peter Hansen <peter at engcorp.com> wrote in message news:<3D62C9AB.D6A6CE34 at engcorp.com>...
> 
>>FISH wrote:
>>[snip]


> 
> The way I look at it is this: when using a dynamically typed
> language, how often do I mix the type of data I store in a 
> given variable?  Although a language may be able to convert
> between types transparently (for example, converting the string
> "123" into the integer 123) on the whole a given variable will
> be assumed by the software to carry one specific type of data 
> only.  
> 
> To clarify: When processing a text file line-by-line via a 
> variable, it matters not if your language automatically converts 
> lines consisting of only digits into an integer... because any 
> processing is likely to use everything as if it was text.  In
> other words, although the language will find the 'optimum'
> datatype for each line read in, the proccessing loop using the
> variable is likely to treat everything in a uniform way - in
> our example it would probably treat everything as a string.
> 
> I don't see (personal opinion!) a genuine need to have a single 
> variable which can mutate between being handled and processed as 
> a number one minute, and handled and processed as a string the 
> next (for example).  Indeed, I consider such overloading of a
> single variable potentially confusing (and therefore bordering
> on bad practice).
> 
> If I wanted to make use of the automatic conversion of types 
> offered by some languages, I would much rather this shift in 
> interpretation was *explicitly* documented in the code (by 
> using a conversion function, like atoi() for example) rather 
> than just allowing a 'digit filled string' to be treated as 
> an int as if by magic! :-)


Woops. You should probably read about the difference between 'Strong vs 
Weak' and 'Dynamic vs Static' typing.

If you think that dynamic typing means that the string object '123' 
could be automagically converted to the integer object 123, you are 
*plain* wrong.

Python has *strong* typing. This means that an integer object *is not* a 
string object. If you try to call an integer's method on a string 
object, you'll get an exception (unless this method exists in both types 
of course).

Laotseu




More information about the Python-list mailing list