Quora: Why hasn't D started to replace C++?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Feb 9 22:38:23 UTC 2018


On Fri, Feb 09, 2018 at 01:39:22PM -0800, Walter Bright via Digitalmars-d wrote:
> On 2/9/2018 6:01 AM, Atila Neves wrote:
> > Unit tests are a great idea, right? Try convincing a group of 10
> > programmers who have never written one and don't know anyone else
> > who has. I have; I failed.
> 
> Unit tests are one of the great success stories of D. I believe it was
> a success because it was so simple to add unit tests to the code, and
> to run those tests.

Yeah, it is so simple you feel ashamed for not writing them.  Which in
turn generates a positive feedback loop where your unittests uncovers
bugs early (rather than 2 months later when your customer's box blows
up), so you feel motivated to write more tests, and your code quality
continues improving.


> D's unit testing system didn't even need to be very good. It just had
> to be *easy*. And that changed everything.

Speaking of unittests... currently we have a problem:

	import std.regex;
	void main() {}

Compiling with -unittest:

	real	0m1.137s
	user	0m0.994s
	sys	0m0.141s

Compiling without -unittest:

	real	0m0.528s
	user	0m0.458s
	sys	0m0.069s

The problem: compiling with -unittest causes Phobos unittests to be
instantiated, even if the user isn't compiling Phobos directly.

Proposal: unittests should only be compiled if the module it's found in
is being compiled (i.e., among the modules listed on the command-line),
even with -unittest.

This won't break anything, because as long as user projects compile all
of their modules explicitly, -unittest will still work as before. I'd
guess practically all user projects will do this. (There may be a few
exceptions, e.g., if a module contains only templates, but IIRC even
then you still have to list the module on the command-line, otherwise
some templates won't instantiate correctly.)

It will improve compilation times and reduce executable bloat --
unittests from external libraries that are only linked, not compiled,
won't be included.  It also makes more sense -- if I'm using a 3rd
party library, why should I care to run *their* unittests?  I'm only
interested in testing my own code.

What do you think?


T

-- 
People demand freedom of speech to make up for the freedom of thought which they avoid. -- Soren Aabye Kierkegaard (1813-1855)


More information about the Digitalmars-d mailing list