Custom Blocks

Michel Fortin michel.fortin at michelf.com
Tue Aug 10 06:50:19 PDT 2010


On 2010-08-10 06:01:10 -0400, Jacob Carlborg <doob at me.com> said:

> I think Ruby and Scala have one of the best syntax for code 
> blocks/delegates. Until then we can use this somewhat ugly hack:
> 
> fun(a, b, c) in {
> // body
> };
> 
> For the above to work "fun" should return a struct which implements the 
> opIn method.

But is this ugly hack (as you call it) really better than the "normal way"?

	fun(a, b, c, {
		// body
	});

At least with this one you know what to expect, and fun's code will be 
much easier to read too because you have no intermediary struct. Ugly 
hacks should be used only when they improve things substantially, which 
does not seem to be the case here.

If it was part of the language then it'd be less of a hack and probably 
more usable.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list