Hacker News new | ask | show | jobs
by AstralStorm 2349 days ago
Main problem with the style is lack of overarching structure and cohesion.

Preferable state is high internal cohesion and low coupling. Most code is opposite. Ravioli is when you trade high coupling without introducing cohesion, which is structure. Typical state after dumb refactor rather than rework.

Simple extraction of functions does not get you anything (if done well within a module, maybe increases cohesion), while making them reusable modules trades reduced cohesion for increased coupling, which is bad.

If you deduplicate too much you suddenly cannot change anything simply... As every place that got deduped is now coupled to one implementation. Once you need some special care, you get to replicate it again oftentimes.

Only true primitives are really worth it to not replicate and parts of code that won't change. (Ask the crystal ball again.)

See if deduplicaton gets you any of useful high level designs, like MVC, event-driven, reactive, message based. Without overarching design, you end up with a mass of locally useful ones that together are incompatible thus requiring lots of different, unique glue code.

The big mistake people do is to equate design patterns with code patterns. Which is what the silly GoF book did a lot. For example "fire and forget background parallel tasks" is a design pattern. Reactor (executes Strategies to deal with Events) is one while Singleton or Context are not. Event also is not. Etc. Generally anything that doesn't actually structure anything is a code pattern.

1 comments

It is quite possible to get an MVC by deduplicating things. Image we have two tables that display some data by the same means, e.g., a web page. This will be about the same code twice. For instance, both will iterate over rows and columns. Removing that duplication will give you an M and a V. Then you may also have to react to some events in about the same way. Remove that duplication and you have a C.