Yaron Minsky: Rules for Effective Programming
Snippet from Effective ML
- Favour Readers Over Writers: Readers drive clarity and simplicity. Always write code such that it's easy to read
- Create Uniform Interfaces: Uniform interfaces help set expectations for how the code/data can be treated. They make it easier to jump into new code.
- Make Illegal States Unrepresentable: Think about the invariants of your data, and design datastructures so that your data cannot enter into an illegal state.
- Code for Exhaustiveness: Prefer explicit case matching over implicit default cases. A default case is a bug waiting to happen when the shape of the data changes.
- Open Few Modules: Or in the more general case, use namespaced functions to improve readability. OCaml has a nifty feature where you can use namespaced functions in a local scope! This improves the readability even more than having to require the namespace for the whole file.
- Make Common Errors Obvious: Make it explicit in the function name that this function can throw an exception. Then the caller knows to expect / handle a possible error.
- Avoid Boilerplate: Reduces code readability, increases chances of subtle bugs.
- Avoid Complex Type Hackery: The enemy of correctness is complexity. And complex types are complex.
- Do not be puritanical about purity: Remember that side-effects are the only way you actually change anything in the real world.
Published On: Fri, 26 May 2023.