__traits(documentation, X)

Simen Kjærås simen.kjaras at gmail.com
Thu Jan 18 14:37:18 UTC 2018


On Wednesday, 17 January 2018 at 22:15:08 UTC, H. S. Teoh wrote:
> 2) Self-checking programs:
>
> 	import std.algorithm;
> 	static assert(import(__FILE__).canFind("\n/**"),
> 		"Dude, why did you remove the ddoc comment?!");
>
> 	/** Remove this comment to get a compile error */
> 	void main() {
> 	}
[snip]
> Imagine an advanced version of (2), for example, code that will 
> force a compilation error if it wasn't formatted correctly.

I found an interesting Rust project a few years back, called 
Launch-Code:
https://github.com/kmcallister/launch-code

The idea is that unsafe functions be cryptographically signed by 
some authority, and the code refuses to compile if a junior dev 
tries and fuck with it. On a per-function basis, so he could 
still mess up the code that doesn't launch missiles.

We could do the same in D - parse the code with CTFE, hash the 
function body, then assert that the comment matches the hash. 
Should be fairly easy at that point to generate the signatures as 
well.

--
   Simen


More information about the Digitalmars-d mailing list