Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

27. May 2012, 02:18:28 am
Xith3D CommunityGeneral CategoryFeature Requests & Brilliant Ideas (Moderators: Marvin Fröhlich, 'n ddrylliog)Changes in Vecmath 2
Pages: [1]
Print
Author Topic: Changes in Vecmath 2  (Read 2422 times)
BrazilianBoy
Becoming dependent
**
Offline Offline

Posts: 208


l_p_camargo@hotmail.com
View Profile Email
« on: 30. November 2007, 02:06:57 pm »

Why the Tuple.. classes don't return themselves when methods like tuple.addX(5) are called?

This would be very useful, and would allow clever recursive method calls like:
Code:
body.setPosition(body.getPosition().addX(0.5f).addZ(0.5f));
It also contributes to a clean, compact, and simpler code.

Lucas.
Logged

Getting my hands dirty Smiley
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 30. November 2007, 05:56:49 pm »

Well, I really don't like this kind of code trick. It leads to less readability for those, who don't know the specific piece of code. But I could add this to the methods, if anyone wants to use it. It won't harm the execution speed of these methods, IFAIK.

Marvin
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #2 on: 30. November 2007, 08:21:17 pm »

I have added those self-returners.

Marvin
Logged
BrazilianBoy
Becoming dependent
**
Offline Offline

Posts: 208


l_p_camargo@hotmail.com
View Profile Email
« Reply #3 on: 30. November 2007, 09:03:06 pm »

I have added those self-returners.
Thank you very much  Cheesy
Logged

Getting my hands dirty Smiley
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« Reply #4 on: 02. December 2007, 12:54:09 pm »

Well, I really don't like this kind of code trick.

It's not a code trick since it is exact the same way how a "+=" operator has to be defined in a language that supports operator overloading.
Logged

Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #5 on: 02. December 2007, 01:26:14 pm »

It's not a code trick since it is exact the same way how a "+=" operator has to be defined in a language that supports operator overloading.

Yeah, but would you like this one:
Code:
a += b = c;
? Wink

Marvin
Logged
Mathias 'cylab' Henze
Fierce Warrior
****
Offline Offline

Posts: 540

1064620
View Profile WWW
« Reply #6 on: 03. December 2007, 09:07:53 am »

Err... yes  Shocked

But you right, that this is a more tricky example, since it cannot be implemented as
Code:
a.add(b).set(c)
but has to be
Code:
a.add(b.set(c))
which resembles a+=(b+c) because of higher priority of the = operator. However, I always do those brackets anyway for clearity  Tongue

Having said that, I think methods like set() are a different kind of thing than add(), mul() etc.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic