logoalt Hacker News

jayd16today at 3:17 PM1 replyview on HN

Ok now add a Path shape that has to calculate the area of a polygon with arbitrary complexity.

Consider how the workload is now dominated by the core task of actually calculating the area, reducing the impact of struct usage.

Consider the diffs required to make this change.

It's not like Clean Code should be taken as gospel but this micro-benchmark is not a realistic example of what CC is trying to solve.


Replies

lunar_mycrofttoday at 3:31 PM

In that case, you'd branch into a separate function/block that runs the calculation. Sure, it's slower than a simple array index to find a coefficient, but you're only incurring that cost when you actually need it and it's still much faster than using polymorphism everywhere instead.

show 1 reply