Is phobos too fluffy?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Sep 19 06:59:54 UTC 2020


On Friday, September 18, 2020 6:05:39 AM MDT Imperatorn via Digitalmars-d 
wrote:
> On Friday, 18 September 2020 at 07:41:25 UTC, mw wrote:
> > On Friday, 18 September 2020 at 06:50:48 UTC, Imperatorn wrote:
> >> Not to criticize, but, if it has reached 330 KLOC there might
> >> be another problem :S
> >>
> >> How did it get that big?
> >
> > Sometimes for non-trivial program, `unittest` can easily be
> > longer than the program itself to cover all the test paths &
> > cases.
>
> Sure, but wouldn't you separate the code and tests in different
> projects?

No. It's very common practice in D code to put the tests immediately after
the code that they're testing. It makes it far easier to make sure that
everything has tests as well making it easier to maintain the code and
ensure that the code and tests are properly in sync. In addition to that, if
a unittest block immediately after a symbol is marked with a ddoc comment,
then it gets added to the documentation for that symbol, making it easy to
add examples to the documentation and have those examples be tested whenever
you run the unit tests without having to duplicate the examples and worry
about whether they're in sync between the documentation and the tests.

Of course, not everyone likes to have the tests with the code, and some
people will put them separately, but it's generally recommended that they go
together, and that's what Phobos does. And since we try to have Phobos be
both well-documented and well-tested, the vast majority of its LOC are made
up of documentation and unit tests.

- Jonathan M Davis





More information about the Digitalmars-d mailing list