hn.today

Call Things What They Are

saturnci.com24 points14 comments
Screenshot of Call Things What They Are

Jason Swett argues that clear software depends on naming values and methods for what they actually represent, rather than relying on shorthand that forces readers to infer their meaning. He uses a bicycle example from Practical Object-Oriented Design in Ruby: a Wheel’s `diameter` is calculated from `rim + tire * 2`, but those names conceal that the values are rim diameter and tire thickness. Even after consulting the book, Swett says he could not confidently identify the quantities until he asked an AI assistant. He also objects to Gear’s names: `chainring` and `cog` stand for tooth counts, while `gear_inches` and `ratio` omit information about what the methods return.

His rewrite makes those meanings explicit, using names such as `rim_diameter_inches`, `tire_thickness_inches`, `chainring_tooth_count`, `gear_ratio`, and `diameter_inches`; he also renames `gear_inches` to `size_inches`, since the Gear object has a size rather than a gear. Applying unit suffixes consistently, he says, further clarifies the calculations. Swett’s central claim is that naming is a simple design practice with substantial, lasting benefits: a focused pass changing names alone can make legacy code much easier to understand, without changing its behavior. He presents this as an accessible improvement compared with more demanding software-design techniques and criticizes programmers - and AI coding tools - for routinely choosing vague or inaccurate names.

Read on saturnci.com14 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.