3 ms·
The key to maintainable code is encapsulation. Give every piece of functionality an interface. All the other code that uses it must use it through that interfa
by twblalock 5y ago
The key to maintainable code is encapsulation.
Give every piece of functionality an interface. All the other code that uses it must use it through that interface. The interface should be as generic as possible and not leak internal implementation details.
This makes everything better: you can test each piece of functionality in isolation, and use mocks when you test the code that depends on that piece. You can replace the implementation without changing the interface or the other code that uses it. You can have different people work on different parts of the codebase without merge conflicts.
The other biggest piece of advice I can give is to use a statically typed language. Sorry, Python type hints are not good enough. Maintaining a large codebase, years after it was written by other people, is far easier with a static type system. That's why dynamic languages added type hints in the first place, although they can never match what statically typed languages had from day one. Don't sacrifice that for ease of implementation or speed of prototyping: over the long run you will spend far more time running code, debugging code, and maintaining code, than you will spend writing new code. Front-load all that effort by using a static type system.