April 27, 2007 Re: Cool thing about D, number #72 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter wrote:
> I've always had this dilemma in C++ when writing graphicsy methods, whether a function that takes a point should take separate components (float,float,float) or a vector (Vec3f), or perhaps a pointer (float*). In D there's also the option of float[3]. Or just for convenience sake maybe overloads for all of the above.
>
> I just realized today the coolness of tupleof for this kind of situation. You can make the function takes the plain floats
>
> do_something_at_point(float x, float y, float z);
>
> And still call it using a Vec3f via tupleof!
>
> Vec3f world_origin;
> ...
> do_something_at_point(world_origin.tupleof);
>
> as opposed to
>
> do_something_at_point(
> world_origin.x,
> world_origin.y,
> world_origin.z);
>
> It's a minor thing, but it rocks.
>
>
> --bb
Thats awesome.
I think it would be cool if we had a D.algorithms newsgroup; but then again, I think I'd never visit this newsgroup :)
-Joel
| |||
April 27, 2007 Re: Cool thing about D, number #72 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter wrote:
> I just realized today the coolness of tupleof for this kind of situation. You can make the function takes the plain floats
>
> do_something_at_point(float x, float y, float z);
>
> And still call it using a Vec3f via tupleof!
>
> Vec3f world_origin;
> ...
> do_something_at_point(world_origin.tupleof);
I finally realize how useful tuples are!
Great contribution.
--
Luís
| |||
April 28, 2007 Re: Cool thing about D, number #72 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | Luís Marques wrote:
> Bill Baxter wrote:
>> I just realized today the coolness of tupleof for this kind of situation. You can make the function takes the plain floats
>>
>> do_something_at_point(float x, float y, float z);
>>
>> And still call it using a Vec3f via tupleof!
>>
>> Vec3f world_origin;
>> ...
>> do_something_at_point(world_origin.tupleof);
>
> I finally realize how useful tuples are!
> Great contribution.
>
> --
> Luís
Me too, thanks Bill. These are the 'little' things where D shines and make it so enjoyable to program in.
| |||
April 29, 2007 Re: Cool thing about D, number #72 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to janderson | janderson wrote:
> Bill Baxter wrote:
>
>> I've always had this dilemma in C++ when writing graphicsy methods, whether a function that takes a point should take separate components (float,float,float) or a vector (Vec3f), or perhaps a pointer (float*). In D there's also the option of float[3]. Or just for convenience sake maybe overloads for all of the above.
>>
>> I just realized today the coolness of tupleof for this kind of situation. You can make the function takes the plain floats
>>
>> do_something_at_point(float x, float y, float z);
>>
>> And still call it using a Vec3f via tupleof!
>>
>> Vec3f world_origin;
>> ...
>> do_something_at_point(world_origin.tupleof);
>>
>> as opposed to
>>
>> do_something_at_point(
>> world_origin.x,
>> world_origin.y,
>> world_origin.z);
>>
>> It's a minor thing, but it rocks.
>
> I think it would be cool if we had a D.algorithms newsgroup; but then again, I think I'd never visit this newsgroup :)
In six months I'l go "man there was this thing about using .tupleof when passing arguments, but I'm damned if I can't find it". Happens to me all the time.
I wonder, is there someplace where gems, nifty things, gotchas, etc. are collected from these newsgroups?
| |||
April 29, 2007 Re: Cool thing about D, number #72 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Georg Wrede | Georg Wrede wrote:
> janderson wrote:
>> Bill Baxter wrote:
>>
>>> I've always had this dilemma in C++ when writing graphicsy methods, whether a function that takes a point should take separate components (float,float,float) or a vector (Vec3f), or perhaps a pointer (float*). In D there's also the option of float[3]. Or just for convenience sake maybe overloads for all of the above.
>>>
>>> I just realized today the coolness of tupleof for this kind of situation. You can make the function takes the plain floats
>>>
>>> do_something_at_point(float x, float y, float z);
>>>
>>> And still call it using a Vec3f via tupleof!
>>>
>>> Vec3f world_origin;
>>> ...
>>> do_something_at_point(world_origin.tupleof);
>>>
>>> as opposed to
>>>
>>> do_something_at_point(
>>> world_origin.x,
>>> world_origin.y,
>>> world_origin.z);
>>>
>>> It's a minor thing, but it rocks.
>>
>> I think it would be cool if we had a D.algorithms newsgroup; but then again, I think I'd never visit this newsgroup :)
>
> In six months I'l go "man there was this thing about using .tupleof when passing arguments, but I'm damned if I can't find it". Happens to me all the time.
>
> I wonder, is there someplace where gems, nifty things, gotchas, etc. are collected from these newsgroups?
>
Start a wiki page?
| |||
April 30, 2007 Re: Cool thing about D, number #72 | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Georg Wrede | == Quote from Georg Wrede (georg@nospam.org)'s article > janderson wrote: > > Bill Baxter wrote: > In six months I'l go "man there was this thing about using .tupleof > when passing arguments, but I'm damned if I can't find it". Happens to > me all the time. > I wonder, is there someplace where gems, nifty things, gotchas, etc. > are collected from these newsgroups? In theory, I've collected some of those things in the Tutorials project (http://www.dsource.org/projects/tutorials/wiki/), but the reality is that I don't have enough time to create many new pages these days (and I'd rather do other things). So I just bookmark the cool newsgroup posts and hope that I'll be able to find them again in the future. If some other people want to add cool stuff to the Tutorials project, I won't get it their way, though. They don't even have to ask for permission -- all they need is a dsource login. ;) jcc7 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply