Live Coding with Ben @ YouTube
A nice talk from Ben Orenstein. It’s about “law of demeter” and “applying factory pattern”, with some funny branch offs (relative line-numbering on vim sounds interesting).
Identifying appropriate relationships among objects is a very important factor in object-oriented-design. Putting too much focus on dividing the roles of objects can cause the deeply nested relationships. Both roles (modularities) and relationships need to be balanced.
- You can call a method of parameter. But you should not call a method of return value of a method.
- One common heuristic is that “if the code is duplicated twice, refactor them”. However, it doesn’t occur in real life. The issue of this approach is you sometimes cannot recognize the code duplication by tracking only the changed part of the code.
- Decent programmers have good habits. You need some disciplines to always follow.
- Avoid “let” statement in tests because the object construction is separated from the text itself. Also, the object becomes fragile, which is difficult to change for a certain specific test scenario.
Some related information.
- Demeter: It’s not just a good idea. It’s the law.
- It’s referenced in the above video, and lot of insights on this topic.
- Play by Play: Refactoring with Ben Orenstein.
- It’s an insightful one too.
- The Giant Robots Smashing into Other Giant Robots podcast.
- It’s hosted by Ben Orenstein and I’m regularly listening to it.