I might go further (recognising that this is not the point of the blog of course) and say that a length is an object with a numerical value and a unit distance, so although it might make sense for a particular system to standardise on either metric or US customary units, in many cases it makes sense for `@wheel.rim.diameter` to return a `Length` object, so you can also `@wheel.rim.diameter.to_f(:inches)` or `@wheel.rim.diameter.to_f(:cm)`.
In case you're confused by the tire sizes below, know that bicycle tire sizing is, by tradition, inconsistent. Road bikes originated in Europe andd use metric sizing. [...] Mountain bikes originated in the United States and give tires sizes in inches
Source: Chapter 6 of the book this article is about
The mars climate orbiter was lost because two types of units were used in the same system. Ground software sent thruster impulse data in imperial pound-force-seconds, while NASA's navigation software treated the numbers as metric newton-seconds (a 4.45x discrepancy)
100% agree on the naming thing. Before AI took over one of my guidelines was “no abbreviations,” a bit strict but it helps coming back to code later. Couple that with naming intent and specifics keeps code readable and easy to understand and modify. I never bought into the “fewer keystrokes” mentality. If typing is so hard then practice it. It is (was) a core feature of the profession.
Yeah I couldn't put my finger on it, but there were a lot of things that bothered me about that book and this nailed it.
I bought the book with the expectation of getting good insights on how to do this kind of analysis and design and came away from it. More confused than ever.
Great read. Even Sandi Metz failing to follow her own advice. Explains why Claude and Codex are so awful at it - their entire training set falls foul of this
- Reaching for a bigger design than it needs, to impress. - Reallocating its imaginary budget on variable_name_char_count to prompter-directed-apologies. - Destroying our trade.
Good article, I prefer expressive variable names over minified ones. We're not so strapped for memory that the legibility of the code should play second fiddle.
I worked with a guy who was resistant to naming things what they are and he would come up with ridiculous, unrelated names for things. Sometimes he would even use different names for the same concept in different places in the code, because he had this belief that reusing the same name in a different context was bad. He left the company with a huge mess of code to maintain! I'm now using AI to help me untangle the translations of nonsense he wrote throughout the code base.
I agree with some of this, but also `gear_inches` is its own concept. It’s not just the size of the gear. So for that specific instance, she did call it what it was.
Counterpoint: Her code fits on my phone screen and conveys its point in service of a coherent book-length series of lessons. Yours is what, more explicit?
The article suggests renaming the ratio method to gear_ratio, while at the same time it suggests renaming gear_inches to size. That's rather inconsistent, to remove the gear_ prefix from one method while adding it to the other. They should either be named gear_size AND gear_ratio (which is redundant since they're already in the Gear class, or better they should be named size AND ratio.
If you're going to get pedantic about naming things, at least get it right.
That way it's really clear to the reader we're doing float division and not integer division. For better or worse, a lot of languages have this quirk where something needs to be converted to float to indicate we have a float result.
I like Python / (float) and // (integer) a lot for this reason.
18
u/Zestyclose-Turn-3576 1d ago
I definitely approve.
I might go further (recognising that this is not the point of the blog of course) and say that a length is an object with a numerical value and a unit distance, so although it might make sense for a particular system to standardise on either metric or US customary units, in many cases it makes sense for `@wheel.rim.diameter` to return a `Length` object, so you can also `@wheel.rim.diameter.to_f(:inches)` or `@wheel.rim.diameter.to_f(:cm)`.
6
u/izuriel 1d ago
Also the wrapping of two properties in another class just to discard later and not creating it in the constructor. Maybe the book cleans that up.
3
u/nfstern 1d ago
Yeah I couldn't put my finger on it, but there were a lot of things that bothered me about that book and this nailed it.
I bought the book with the expectation of getting good insights on how to do this kind of analysis and design and came away from it. More confused than ever.
12
u/pickering_lachute 1d ago
Great read. Even Sandi Metz failing to follow her own advice. Explains why Claude and Codex are so awful at it - their entire training set falls foul of this
6
u/bluerock0427 1d ago
I worked with a guy who was resistant to naming things what they are and he would come up with ridiculous, unrelated names for things. Sometimes he would even use different names for the same concept in different places in the code, because he had this belief that reusing the same name in a different context was bad. He left the company with a huge mess of code to maintain! I'm now using AI to help me untangle the translations of nonsense he wrote throughout the code base.
3
u/jgaskins 7h ago
I agree with some of this, but also `gear_inches` is its own concept. It’s not just the size of the gear. So for that specific instance, she did call it what it was.
2
u/Main-Drag-4975 1d ago
Counterpoint: Her code fits on my phone screen and conveys its point in service of a coherent book-length series of lessons. Yours is what, more explicit?
0
u/joemi 1d ago
The article suggests renaming the
ratiomethod togear_ratio, while at the same time it suggests renaminggear_inchestosize. That's rather inconsistent, to remove thegear_prefix from one method while adding it to the other. They should either be namedgear_sizeANDgear_ratio(which is redundant since they're already in the Gear class, or better they should be namedsizeANDratio.If you're going to get pedantic about naming things, at least get it right.
0
u/[deleted] 1d ago
[deleted] — view deleted comment
0
u/[deleted] 1d ago
[deleted] — view deleted comment