Isn't `each` too much of a good thing?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.com
Thu Sep 17 18:11:48 UTC 2020


On 9/17/20 1:41 PM, Seb wrote:
> On Thursday, 17 September 2020 at 16:18:18 UTC, Andrei Alexandrescu wrote:
>>
>> We support opApply with one, two, or more arguments. Built-in 
>> hashtables (when was the last time you were in a place in your life 
>> where hashtable.each was useful?). You name it - we support it.
> 
> It's a standard library - catering for almost everything is in the job 
> description ;-)

You know it doesn't quite work like that. By that argument most range 
algorithms should work on static arrays, and actually beginners ask for 
such on occasion. We have deemed that too much effort for no good 
outcome. In that context, each is both an outlier and a dangerous precedent.

I recall you and I discussed each in the past. Probably we agreed it 
should work with everything one could reasonably use a loop with. Maybe 
you worked on it, too. I didn't check because it's not important; we 
should dissociate the code from whoever created it, and indeed I found 
myself critical of code I later discovered I'd written myself. This 
particular code is finely done, it's the charter we need to revise.

The fact that constraints come in form not knowable or verifiable by the 
user is a deal-breaker as bad as accepts-invalid. That transcends 
backward compatibility.

(Reminds me with a discussion I had with a salesman: "You should really 
subscribe to X." "What is X?" <vague description> "I don't understand." 
"Well it's really good, you should really try it out regardless so you 
get an idea." "How can you advise me to subscribe to something I don't 
understand?")

I created https://issues.dlang.org/show_bug.cgi?id=21260.


More information about the Digitalmars-d mailing list