Re: [Vala] Operator overloading
- From: Levi Bard <taktaktaktaktaktaktaktaktaktak gmail com>
- To: John Carr <john carr unrouted co uk>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Operator overloading
- Date: Mon, 23 Mar 2009 14:43:51 -0400
How this relates to
video game programming is beyond me.
A typical thing i used to see when modding Half-Life is the Vector
class which allows you to do vector math as though you were dealing
with simple types.
vector.x *= 5; vector.y *= 5; vector.z *= 5; becomes vector *= 5;
You can also add vectors together and so on.
It's certainly *not* something that is ground breaking and that would
bring massive improvements to the game development community. That
said, in the + vs method call case, consider vector1.add(vector2) -
does it add the vectors together and store in vector1, or does it
return a new vector. For this kind of thing, + and += have clearer and
more established intentions, i think.
We deal with these kinds of issues with function definitions all the
time already, though.
What are the arguments? What is the return value? What are the side effects?
There are also unclear semantics with the + and += operators that
don't exist with functions.
For example, if I have: vector1 *= 5, does that mean vector1 is
repeated 5 times in order, each value of vector1 is repeated 5 times
in order, or each value of vector1 is multiplied by 5? (At which point
you have to look up the overloads for the type(s) contained in the
vector.) Is *= optimized to modify vector1 in place, or does it create
a temp vector and then change vector1's reference?
--
http://homes.eff.org/~barlow/EconomyOfIdeas.html
http://www.dreamsongs.com/MobSoftware.html
http://www.gnu.org/philosophy/shouldbefree.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]