Is phobos too fluffy?

H. S. Teoh hsteoh at
Thu Sep 17 20:56:40 UTC 2020

On Thu, Sep 17, 2020 at 08:36:38PM +0000, Paul Backus via Digitalmars-d wrote:
> On Thursday, 17 September 2020 at 18:44:09 UTC, H. S. Teoh wrote:
> > what if the language equates:
> > 
> > 	iterable.foreach(i => { ... });
> > 
> > with
> > 
> > 	foreach (i; iterable) { ... }
> This seems totally backwards to me. Why implement something as a
> language feature when we can already do it with library code?

Oh well, it was worth a shot. :-P

> 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.)

Convenience, esp. for small wrappers like .each, is determined by
frequency of use.  Is there an easy way to count the number of uses of
.each in public D projects?  It'd be good to have some data to back up
our decisions, otherwise we're just sailing blind based on pure

> 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:

Oy, don't get me started on C++... Once, I had an old C++ project where
I identified a particular performance bottleneck that could be improved
by using hashtables.  Should be easy, right?  Esp. since C++11
finally(!) has hashtables in the standard library.  Long story short,
yeah there are hashtables, all right, but the interface is so klunky to
use and the defaults so unhelpful that it would require major code
refactoring just to get it to work (not to mention an already
significant amount of code cleanup to make the original C++98 code
compile with C++11 -- all just to get hashtables!).

After fighting with it for more hours than I was prepared to spend on
what I thought would be a "trivial" change, I threw in the towel... and
later decided to rewrite the entire code in D -- and have been very
happy with this latter decision ever since!  One of the major sources of
happiness was the way D has AA's as part of the language, and using
structs as AA keys Just Worked(tm) out-of-the-box.  Whatever warts AA
may have had (or still have), it's still orders of magnitude better than
the totally-unfriendly C++ API.


ASCII stupid question, getty stupid ANSI.

More information about the Digitalmars-d mailing list