“Tree shaking” is a description of a particular method of DCE. ¯\_(ツ)_/¯
Daniel Armando Martinez
22

I think I know what you’re trying to get at, but the analogy could be misleading for those in need of a refresher course in geometry (and set theory).

•“squares” is a subset of “rectangles” (i.e, rectangles where all sides are the same length);

•“rectangles” is a subset of “quadrilaterals” (quadrilaterals with all angles equal to 90°);

•“quadrilaterals” is a subset of “polygons” (polygons with 4 sides).

The hierarchy does not go the other way: defining ‘rectangles’ as a superset of ‘squares’ does not get you to a proper definition unless you also specify what dimension of the definition of ‘square’ is allowed to ‘flex’.

After all, circles are a superset of squares too — just increase the number of sides towards ∞ while retaining the equal-sides and equal-angles constraints.

So no, a rectangle isn’t a fortiori a square. Categorically.

Every square is a very specific type of rectangle, and it is a fortiori a rectangle. However most rectangles are not squares; most quadrilaterals are not rectangles, most polygons are not quadrilaterals.

I would also dispute that DCE is a superset of tree-shaking.

They are quite different approaches to a problem, and they go about it in different ways.

The two approaches should be asymptotically equivalent — that is, if they did their job exactly right, they should both result in code with the minimum number of redundancies (consistent with the code continuing to perform as desired: it’s easy to get zero-redundancy code… an empty file is a subset of zero-redundancy code, but it’s probably not the target for most applications).

And if they both do what they aim to do, the relevant metric becomes the cost of doing one versus the other.

DCE and tree-shaking are as different as using a hammer and nails to nail together a frame, versus using a nailgun (or hex screws and a drill). Nailguns are faster (and more fun), but if you’re only ever going to build one frame, it probably doesn’t make sense to buy a \$500 nailgun.

The ‘eggs in cooking’ example was on point, I felt.

I know that if I added up all the time I’ve all spent picking bits of shell out of my code these past 30 years, I would probably cry for days.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.