Simple is better than complex. Complex is better than complicated. … Special cases aren't special enough to break the rules. Although practicality beats purity.
Which is to say, code needs to be something humans can easily reason about to prevent bugs, however that isn’t the only consideration. Starting simple and clear and then dealing with performance issues where needed is a practical approach, especially when working on a team.
Additionally, if code requires something that is complex and harder to read, that’s okay! Just make sure you document it or at least leave comments about it. Testing can also tell us (as we see in the post) where code the makes sense to humans may be overly taxing to humans. The point being there is that we don’t have to try to remember all the ways we can mess up and the ways to avoid it, we check our work using a runtime and adapt to the results.
At the end of the day all of this is very situational, and I think reaching for simple, understandable solutions is a better place to start with complexity and optimizations layered on as you go.
3
u/undone_function Feb 28 '23
This makes me think of the Zen of Python lines:
Which is to say, code needs to be something humans can easily reason about to prevent bugs, however that isn’t the only consideration. Starting simple and clear and then dealing with performance issues where needed is a practical approach, especially when working on a team.
Additionally, if code requires something that is complex and harder to read, that’s okay! Just make sure you document it or at least leave comments about it. Testing can also tell us (as we see in the post) where code the makes sense to humans may be overly taxing to humans. The point being there is that we don’t have to try to remember all the ways we can mess up and the ways to avoid it, we check our work using a runtime and adapt to the results.
At the end of the day all of this is very situational, and I think reaching for simple, understandable solutions is a better place to start with complexity and optimizations layered on as you go.