A Philosophy of Software Design Flashcards
Why do you create classes and methods?
To abstract complexity. Abstraction hides complexity. There is no point in creating an interface or method if we are not hiding implementation details. Abstraction controls complexity by hiding it. Classes should have depth, shallow interfaces, and big implementation. Remember that side effects are part of an interface. Remember about the Unix file interface.
What should we do about exceptions?
Make exceptions disappear by changing the semantics of the code. Remember the about the meaning of the unset variable command and about the windows file vs Unix file mentioned in the talk.
Exceptions vs Return errors codes
Exceptions add more value if they travel far up the stack. If you are going to deal with the exception right after calling maybe an error code is better. E.g., dealing with a not found error in an API.
When throw exceptions vs redefine semantics?
You should throw if you can’t return what your signature says. E.g., file.read() should throw, “asf”.char_at(-1) should throw, “21444”.substring(-1, 17) could clip the range.
Tactical vs Strategical approach
Tactical approach focus on just getting it to work. The system turns into spaghetti really fast.
We MUST use Strategical approach were the goal is great design:
- Reduce complexity
- Simplify future development
- Develop faster in the future
- Spend extra time today, pays on the long run
General vs Specific classes
General -> Simpler and deeper
Specific -> Shallow
As the tests get more specific the code gets more generic.