Is phobos too fluffy?

Paul Backus snarwin at gmail.com
Thu Sep 17 20:36:38 UTC 2020


On Thursday, 17 September 2020 at 18:44:09 UTC, H. S. Teoh wrote:
> Of course, once you take all of that other fluff out, the 
> raison d'etre of .each becomes a little shaky. :-P  It's 
> probably pushing it, but I'm tempted to suggest that perhaps 
> this is one of those opportunities Andrei was talking about to 
> improve the language: what if the language equates:
>
> 	iterable.foreach(i => { ... });
>
> with
>
> 	foreach (i; iterable) { ... }
>
> ?  I.e., the former lowers to the latter.  This seems to be a 
> natural (logical?) next step in the spirit of UFCS, except 
> applied to built-in loop constructs.

This seems totally backwards to me. Why implement something as a 
language feature when we can already do it with library code?

Also, "foreach but it works in range pipelines" is absolutely a 
worthwhile reason on its own to keep .each around. I understand 
some people don't want "trivial" stuff in Phobos, but there is a 
real value to convenience. (Not to mention that even 
seemingly-trivial generic code can have edge-cases that take some 
work to get right.)

To give a negative example: C++'s <random> library makes 
essentially no concessions to convenience, and as a result is 
gratuitously annoying to use. This blog post by Martin Hořeňovský 
goes into some of the details:

https://codingnest.com/generating-random-numbers-using-c-standard-library-the-solutions/


More information about the Digitalmars-d mailing list