Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This technique is not called "Inline unit tests", it's called contract programming.

I can't imagine writing such code without proper support from IDE like automatic folding and/or special colors.

There is also problem of asynchronous code, events etc. Something that can't be covered with such simple contracts.




Given the simplicity of my macro, I didn't call this 'contract programming' on purpose. For real JavaScript Contract Programming, check out contracts.js (from the same author of sweet.js).


Among others(there are many contract implementations for js on github) this one is pretty average, not modern enough, not compatible with code which uses promises. Such implementation should go beyond direct arguments and result value of function call.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: