←back to thread

401 points Bogdanp | 5 comments | | HN request time: 0.208s | source
1. WalterBright ◴[] No.45536151[source]
Even better if the documentation examples are part of the test suite!
replies(2): >>45536592 #>>45538247 #
2. tialaramex ◴[] No.45536592[source]
Right, one of the best out-of-box tooling decisions for Rust is that by default, and out of the box cargo will assume all your documentation examples are tests it should compile and execute.

This means so long as you run the tests before shipping you basically can't ship with examples you forgot to update after an API change because they either don't compile or don't work.

And you might think well, nobody would ship examples that don't even compile right? But on more than one occasions I've used a Microsoft C# library that comes with examples clearly hand made by their engineers (yes I'm that old that it couldn't be LLM output) without checking they work. Somebody has sketched out what ought to work, they haven't tested it, and a reviewer has seen that it looks right and OK'd it, but again, never tested that it works. This is extremely frustrating because the documentation is wrong but now what?

replies(2): >>45539358 #>>45540486 #
3. Finnucane ◴[] No.45538247[source]
i have at times looked at tests to get an idea of how the developer expected the code to be used.
4. SAI_Peregrinus ◴[] No.45539358[source]
I'd go a bit further and say that all tests are documentation examples. Rust is nice because it has symmetry and documentation examples are tests.
5. WalterBright ◴[] No.45540486[source]
The dlang website generator does not succeed unless all the coding examples run successfully.