Why Phobos is cool

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Jun 24 21:37:37 UTC 2020


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

-- 
If the comments and the code disagree, it's likely that *both* are wrong. -- Christopher


More information about the Digitalmars-d mailing list