by WalterBright · 2y ago · 0 comments
1. incomplete
2. wrong
3. missing
My goal is to write code that is so clear it doesn't need documentation.
I don't want to read the code of your function to figure out what its doing. I want to read the function signature, and if that's not clear enough a comment explaining its purpose and parameters. Code explains how it does something, but often does not clearly explain what that something is.
For example, having the parameter to a function declared `const` means the function cannot alter it, and this is checked by the compiler. It won't be necessary to mention that in the function documentation.
P.S. This doesn't work in C and C++, despite them having a `const` type qualifier. This is because the `const` is not transitive, and can be legitimately cast away. Therefore, it's useless as a guarantee. D's `const` is transitive, and although you can cast it away in @system code, you're on your own with that.
I hear this so often but I think it is an excuse. Those 3 points are also true about your code.
> There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors
The difference is there are things the compiler can verify to be correct.