Python vs .Net

Greg Brunet gbrunet at nospamsempersoft.com
Wed Jan 8 07:42:25 CET 2003

```"Brian Quinlan" <brian at sweetapp.com> wrote in message
news:mailman.1042002854.10321.python-list at python.org...
>
> Let's imagine a routine like this:
>
> def matrix_rotate(matrix, angle, vector):
>     "Rotate the specified matrix"
>     from math import sin, cos
>
>     ...
>
> In Python, the matrix_rotate routine would likely work with a wide
> variety of "matrix" types without any additional effort. In C#, you
> would need to define a IMatrix interface and force all matrix
arguments
> to conform to that interface.

Sorry - but my math is a bit rusty - wouldn't a matrix just be an array
of floats (or maybe complex numbers), that would seem to be a pretty
straightforward definition and one that wouldn't impose an undo burden
on using the routine.

> > Now regardless if we're talking about "+" or Add, I think that we
can
> > both agree on what to expect if both a & b are Integers or Strings.
> > What if one is an integer & one is a string, however.  What if the
> > string has a numeric value?  What if we have an Integer and a Float.
>
> It makes mathematical sense for integers and reals to be addable
because
> the set of integers is a subset of the set of reals.
>
> Strings and integers are quite unrelated.

Actually what I was trying to infer with this, and the reference to the
PEP later on, is that if you add 2 integers, I would expect an integer
result.  What kind of result would you get when adding an integer and a
float?  Neither Python nor VB has any problems with that  & doesn't
require a specific cast - I think that it's called 'promotion' or
something like that in VB, where 2 compatible (but different type)
arguments can be mixed and the result is in the form of the argument
with the larger 'scale'(?)

> > Older versions of VB suffered from what folks called "Evil Type
> > Coercion".  It tried to do the 'right' thing, so that 5+"5" returned
> 10
> > and 5 & "5" returned 55 (while 5+5=10 and "5"+"5"=55 as expected).
> This
> > was obviously a bad thing because it was inconsistent - better to be
> > consistent.  OTOH, I see a bit of this even in Python with the
change
> in
> > the division operator behavior (PEP 238) - should 5/2 return an
> integer
> > or a float?
>
> VB was engaging in weak typing. Python is strongly typed. In Python
you
> can't get a string to act like an integer without an explicit cast.

Agreed - and thankfully that's been corrected (in VB).  I am glad that
both are strongly typed.  Cheers,

--
Greg

```