Python vs .Net
mystery at golden.net
Wed Jan 8 23:27:39 CET 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  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.
matrix = matrix + matrix;
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
> > 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 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
> > > > 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
> > > > 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
> > >
> > > 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
> > 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:
> B C
> 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
More information about the Python-list