3 ms·
/** * @ensure const(foo), const(bar.x) **/ Does the compiler see inside comments? I think that Python does that for types because they want to preserve b
by gus_massa 6y ago
/**
* @ensure const(foo), const(bar.x)
**/
Does the compiler see inside comments? I think that Python does that for types because they want to preserve backward compatibility, but I never like it. Why not something like:
#ensure const(foo), const(bar.x)
or
@ensure const(foo), const(bar.x)
- Nuoji 6y agoThree reasons: 1. Implementing pre/post condition checks are optional for a conforming compiler. Putting the checks in special docs comments underscores that the checks are optional. The more C way would perhaps be to use pragma. 2. Putting checks either between comments and function signature, function signature and body, or at the start of the signature body visually divides function signature from code that’s actually run. 3. Since these are hard requirements on calling functions the information needs to be in the documentation anyway. This ensures that docs and contracts are always in sync. But yes, I think your opposition to this is a valid one. It is not ideal, rather it is the best trade off I could find. Given the above.