Why do we (I) need this? (small example)

Bruce Adams tortoise_74 at yeah.who.co.uk
Thu Jan 3 17:16:02 PST 2008


On Thu, 03 Jan 2008 20:10:51 -0000, downs <default_357-line at yahoo.de>  
wrote:

> I currently use the following code as part of dglut:
>>
>> glChecked("RenderToScreen", MatrixScope(init, renderScene(f),  
>> img2.With(WithFlag(GL_BLEND, true, { ... }))));
>>
>
> With the proposed features, this could be rewritten as follows:
>>
>> glChecked("RenderToScreen") MatrixScope { init; renderScene(f);  
>> img2.With WithFlag(GL_BLEND, true) { ... } }
>> // without trailing delegates
>> glChecked("RenderToScreen", { MatrixScope({ init; renderScene(f);  
>> img2.With({ WithFlag(GL_BLEND, true, { ... }); }); }); });
>>
>
> Now if this looks better is a matter of taste (personally I think it  
> does). But with the proposed extension,
> the first would translate to four function-call levels of wrappers,  
> while the second and third can be inlined completely.
>
> I don't think it should be necessary to decide for user-defined  
> abstractions OR speed, and since the delegate inlining issue
> looks hard to fix, this seems to be the only way to use your own  
> abstractions as well as take advantage of inlining.
>
>  --downs

Can you honestly say either of those look particularly readable? Imagine
trying to explain it to a new recruit, particularly one unfamiliar with D.
This is why Python invented compulsory whitespace.

How about just re-laying-out (is that a word?) your orginal as:

glChecked("RenderToScreen",
           MatrixScope(init,
                       renderScene(f),
                       img2.With(WithFlag(GL_BLEND,
                                          true,
                                          { ... }))));

If you must insist on a heavily nested functional style you could
ask for improved laziness support and write:

auto lazy cthulhu = WithFlag(GL_BLEND,true, {...});
auto lazy nylarathotep = img2.With(cthulhu);
auto lazy yogshoggoth = MatrixScope(init,
                                     renderScene(f),
                                     nylarathotep);
glChecked("RenderToScreen", yogshoggoth);

Then if you further wish to please the great old ones you could add
some comments between the lines to explain the code to noobs.
Then if you're lucky you might get to be eaten first  
(http://www.geocities.com/neverclan/c/cthulhu.html).

Regards,

Bruce.















More information about the Digitalmars-d mailing list