Re: Array initialisation
Joshua Cranmer wrote:
Daniel Pitts wrote:
Patricia Shanahan wrote:
I often choose arrays in preference to collections because of the better
notation for accessing and changing elements. Much more to do with code
clarity than with performance.
Alas, if only Java supported proper operator overloading :-/
The two instances in which I can support operator overloading:
1. Bracketed access for Collection-types (probably limited to integer
indices, although a special type for Maps wouldn't be too bad).
2. +,-,*,/ for near-numeric types (i.e., BigDecimal and BigInteger).
These have some potential commutativity concerns, so I wouldn't be too
miffed if this aspect were left out (although limited operator
overloading without touching basic mathematical operations is... almost
pointless).
Knowing that any feature can be abused, the intent of +,-,*,/, (maybe %)
overloading would be to allow types that have a natural meaning for
those operators. C++'s use of << for streams and Java's use of + for
string concatenation are good examples of "what not to do". Oops.
Specifically, I have a "Distance" type that I would like to support +,
-, * for. Also I have a Duration type, and a (mathematical) Vector
type, as well as a DistanceOverDuration type, which would be the return
for Distance::operator/(Duration duraction) :-)
Distance*Distance would return Area, etc...
The expressive power of these operators on these types would be very
beneficial.
The biggest problem is people doing stupid things like "x*y" doesn't
mean multiplication.
Even in the case of my Vector type, I wouldn't use * for dot or cross
products, although I would probably use it for a scalar multiplication.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>