Any chance to call Tango as Extended Standard Library
bearophile
bearophileHUGS at lycos.com
Mon Jan 19 16:27:57 PST 2009
Andrei Alexandrescu:
> I know. Its popularity is part of what makes it dangerous. It's to good
> programming what fast food is to food :o).
I think that's a false analogy: fast food kills you slowly, while experience shows me that in many programs a significant (large) percentage of lines of code don't need to be a the top performance.
So a good thing to do in such parts is to use the most handy, easy to remember, safer (as in anti-bug-prone), and short syntax/semantics you have. In the other small percentage of the code where performance is all important and/or you need full flexibility, you can tolerate something less easy to remember and harder to understand syntax/semantics (that you may also need to look into the docs if you don't know how to write).
This may lead to have two different syntaxes/solutions in the D2 language. Duplication is generally bad. But if the first syntax/solution is simple enough (like, simpler than the current opApply, that I have to look up each time despite using it often), then the summed complexity of both solutions isn't much bigger than the complexity of the second solution alone :-)
So I think having a syntax simpler than the opApply plus a full ranged syntax can be acceptable. The simpler syntax may look for example more or less like this (as you can see there is very little noise and very little to remember):
struct DoubleRange(int n) {
int opIter() {
for (int i; i < n; i++)
yield(i * 2);
yield(1000);
}
}
The following handy lazy iterable may even become syntactic sugar for the struct I have just shown, as you can see even less noise, for a really common programming pattern:
yield int doubleRange(int n) {
for (int i; i < n; i++)
yield(i * 2);
yield(1000);
}
Currently with my libs you have to write the following, that is less nice (and it's not compiler-supported, so it's probably slower than necessary) (idea adapted and modified from Witold Baryluk):
http://www.fantascienza.net/leonardo/so/dlibs/generators.html
struct DoubleRange(int n) {
void generator() {
for (int i; i < n; i++)
yield(i * 2);
yield(1000);
}
mixin Generator!(int);
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list