4 ms·
> if you can make testing easier from day 0 people write more tests and get better coverage. I could see it helping move from 0 to nonzero, but most languages
by iudqnolq 5y ago
> if you can make testing easier from day 0 people write more tests and get better coverage.
I could see it helping move from 0 to nonzero, but most languages have a constant overhead in test setup. If one person starts testing, or you have a standard template, the setup is done.
> Also, the unit tests the compiler implements are just special functions, the actually running of the tests can be as dumb or as complicated as you want (Which D makes trivial because of the reflection capabilities).
Nice! That's basically the approach rust takes (annotate tests with #[test], either use the default test runner that generates a main fn that runs them or bring your own).
> One thing that I don't think you can do with other approaches, is actually have a unit test inside a template, so you know it gets tested for all parameters that it is instantiated with.
That does sound useful. You definitely can't do that in any language I've used. If you need that you definitely have buggy abstractions, but then we always do.
- mhh__ 5y ago> If you need that you definitely have buggy abstractions, but then we always do. Not quite, or at least not always. D embraces something called design by introspection - that basically means adapting behaviour at compile time based on what a parameter can do rather than what a parameter should do (in the case of a template). This allows you to write extremely expressive (and fast) code, however you do at this point need to test at a more granular level. https://www.youtube.com/watch?v=HdzwvY8Mo-w https://www.youtube.com/watch?v=HdzwvY8Mo-w
- WalterBright 5y ago> the approach rust takes Quite a lot of D's innovative features have become standard in other languages as well. For example, there was an overlooked feature in Ada that I always liked: int i = 1_000_000; int phone = 214_222_1234; I.e. _ can be inserted in numeric literals to make them easier to read. After D did popularized this, this feature started appearing in other languages. Other such features include ranges, and staticif. Even static assert.
- mhh__ 5y ago> staticif Or not appearing in the case of that one. Slightly before my time but I read the C++ papers considering it and they are a bit strange.
- WalterBright 5y agostaticif has recently appeared in C++, just under a different name.
- mhh__ 5y agoThe solution C++ has - as Andrei says - is not the same thing as static if because it introduces a scope
- WalterBright 5y agoI thought they fixed that in the latest version, but I haven't been following it closely.