Why Phobos is cool

tastyminerals tastyminerals at gmail.com
Wed Jul 8 09:27:24 UTC 2020


On Wednesday, 24 June 2020 at 21:37:37 UTC, H. S. Teoh wrote:
> Phobos sometimes gets a bad name around these parts, but 
> actually it's pretty cool (in spite of well-known warts).  One 
> of the cool things about it is the batteries-included 
> philosophy that used to be its guiding principle.  Over the 
> course of my usage of D, the following have stood out as being 
> particularly convenient when I needed it:
>
> 1) std.bigint: one time, I was working on a quadratic 
> irrational arithmetic module, and pretty quickly discovered 
> that numerical overflow was a problem that cropped up pretty 
> often.  Or rather, I was seeing what I *thought* was caused by 
> arithmetic overflow, and wanted to be sure.  Solution?  Easy: 
> templatize the coefficient type, import std.bigint, and within 
> several minutes, I have a working implementation that can 
> support arbitrarily large coefficients -- with which I not only 
> confirmed that the observed problems were caused by arithmetic 
> overflow, but also obtained a working solution simultaneously.  
> Win!
>
> 2) std.numeric.poly: another time, I had to work with 
> evaluating a bunch of polynomials, and specifically, with 
> evaluating their roots quickly and accurately.  I could roll my 
> own, poorly, and get results that may or may not be 
> highly-skewed by accumulated errors... or I could use 
> std.numeric.poly to get a reliable evaluation of the 
> polynomial, and, better yet, use std.numeric.findRoot to 
> compute roots with the confidence that the value I get will 
> have as small an error as is possible within the constraints of 
> built-in hardware floats. Plus, this saved me tons of 
> development and debugging time to roll my own solution. Win!
>
> 3) Just today, I needed to implement a fast Fourier transform. 
> Not expecting this to be in Phobos, I was glancing over various 
> algorithms to decide which one suited my use case best and is 
> easy enough to implement quickly. And then I discovered 
> std.numeric.Fft, already done and nicely-packaged and ready to 
> use.  Total win!!
>
> Seriously, D + Phobos is cool beans.  Yes it's not perfect -- 
> the language has its fair share of dark corners, WATs, and 
> Phobos has its share of poorly-designed APIs and outdated 
> modules.  But seriously, a lot of what's currently there is 
> pretty darned cool, and we shouldn't let all the bad stuff 
> cloud our appreciation of just how cool it already is.
>
>
> T

I was honestly surprised to read here that Phobos gets a bad 
name. But I am not a D expert to judge anyway.

For example, I simply can't stand Python stdlib docs and only go 
there when everything else fails.
They are really hard to read for me for some unknown reason 
(design, wording or both?) and I know that I am not alone in 
this. But Python can get away with it, right and why's that? :)
On the contrary Scala standard library is a great example of 
being well written and designed.

Personally, I was impressed by Phobos once I started going 
through the docs for the first time after reading Ali's 
"Programming in D" book. It is actually Phobos that made me 
believe that D has a solid and rich standard library. I was 
pleasantly surprised that description of many functions contained 
complexity information and pragmatically explained how things 
work.
For example, std.algorithm contains many cool things like 
"balancedParens" or "levenshteinDistance" (which even Python 
doesn't have and needs an external C++ lib to use). I like how 
each module is split into logical groups and how the function 
names are simply linguistically more precise. If there is no a 
function that you expect to have, you get a feeling that it is 
not there because it is probably a one liner in D or something 
that should be done with the available tools. I also like the 
general design and layout. It is all very readable. All that 
persuaded me to proceed with the language further. My only 
critique or rather a wish would be more code examples.
Of course, I can imagine things are not all pretty for people 
working with D for many years and it is absolutely fine. It 
should be like this because there will be no challenge and 
therefore progress. However, from beginners view Phobos is cool.




More information about the Digitalmars-d mailing list