But... I don't want my delegates to be lazy - breeding advice
Derek Parnell
derek at nomail.afraid.org
Tue Aug 22 21:43:07 PDT 2006
On Tue, 22 Aug 2006 18:39:57 +0100, Tom S wrote:
> Walter, if you *really* want to keep lazy expression evaluation in its
> current form, then please *at least* don't force everyone to use it.
Amen to that!
> Adopting delegate function parameters for lazy expressions is a mistake.
Well ... its the implicit conversion of expressions to delegates that
concerns me. I can see that most of the time it should be harmless, but it
still opens the window of opportunity for seriously long debugging
sessions.
> At least consider adding a new keyword, e.g. 'lazy' or 'expression',
> please. The syntax could look like:
>
> void foo(int expression() foo) {
> }
>
> or
>
> void foo(lazy int foo) {
> }
or ...
void foo( delegate int () foo) {}
void foo( expression int () foo) {}
> or just some other variant. Delegates would then be delegates and
> wouldn't accept lazy expressions. But lazy expressions could accept
> delegates.
>
> The above approach has three significant advantages over the current
> state of things:
>
> 1. When the coder doesn't intend to use lazy expression evaluation,
> his/her functions that take delegates as params won't silently accept
> lazily evaluated expressions
A big plus, in the manner of "least surprise".
> 2. Less existing code will be broken or the changes will be easier to
> fix - renaming the keyword to some other variable name compared to the
> nontrivial fixes that have to be done now.
This also enhances understanding when reading someone else's code. It
allows better understanding of the coder's intentions.
> 3. In future, the 'expression' or 'lazy' types might provide meta-data
> allowing advanced metaprogramming techniques
Hmmm ... interesting.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
23/08/2006 2:30:50 PM
More information about the Digitalmars-d
mailing list