Python vs .Net

Etienne Charland mystery at golden.net
Wed Jan 8 17:27:39 EST 2003


I would see 2 says. You could

1) Have a IMatrix interface, and each element is of that type. You could
have a typed matrix:
IMatrix [4][4] matrix;
that interface would contain methods needed to do what you want to do with
the matrix elements and could be implemented for different types

2) Have an array of type Object, and use operator overloading. You can have
your custom classes with custom operators.
Object[4][4] matrix;
matrix[1] = matrix[2] + matrix[3];

note that operator overloading is not availlable in VB.Net, only in C#.
However, I prefer using the first approach since it gives more flexibility
and it's, IMO, easier to read.

"Brian Quinlan" <brian at sweetapp.com> wrote in message
news:mailman.1042016958.29335.python-list at python.org...
> > 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.
>
> A typical definition might be:
>
> typedef float[4][4] matrix
>
> But what if I want it to work with doubles? Or I do have a different
> implementation of matrix that uses a single array of 16 floating point
> types.
>
>
>
> > > > 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.
>
> That's what you get.
> > 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'(?)
>
> If you have a hierarchy like this:
>
> A
> |___
> B   C
> |
> D
>
> If you add a C instance and a D instance, it would make sense that the
> result is an A instance, because that is that the common base of the two
> types.
>
> Cheers,
> Brian
>
>






More information about the Python-list mailing list