This evening, I had a fun interaction with Samir Talwar on twitter about comment syntax:
Samir: Help me out with some science, people. Which is the best comment syntax?
Alex: No syntax available for comments? 😀
Samir: You and @rachelcdavies should get together and write your own language that just yells “WRITE A TEST” whenever anyone tries to comment some code.
Alex: :)) Actually, when you write explanation text, I would uncomment it automatically after 5 seconds. When you comment code, it should be automatically deleted in 5 seconds.
This made me think: could we build a programming language whose sole purpose would be to train discipline?
Here are some features I would built into it:
- Any line of code that is not covered by a test is automatically deleted in 5 seconds
- All tests run automatically after each change
- Comments are temporary. If you comment code, it is deleted in 5 seconds. If you comment text, it is uncommented in 5 seconds. See 1 and 2 for what happens next.
- Functions are limited to 6 lines of code
- Objects have to be defined as one of: data object (only data members, automatically public), entity (same but with an automatic id) or service (immutable data, all functions return values)
- An object has maximum 6 methods
- There’s no inheritance. Or, perhaps there’s only interface inheritance, and only one level of inheritance accepted
A few ideas that sound more difficult to implement, or with unclear advantages:
- When a test fails, you can only change the lines of code that you changed since the last test passed, or add new lines of code
- After a test passes, automatically commit with the message “Implemented feature <test name>”
- When all tests pass, you can modify any line of code
- All names have to be part of a glossary composed of 80% domain terms and 20% technical terms. I’m unsure whether to allow prepositions or not.
- When you’re done, a narration is built from your code by using the names and function calls, and sent automatically to your colleagues for review
I could probably come up with more ideas, but it’s late and it’s time to stop.
What would you add?