Naming is the cheapest documentation you will ever write. A precise name removes the need for a comment and makes mismatches obvious in review. The hard part is that when you cannot name something cleanly, that is often a signal the abstraction is wrong - split or reshape it instead of adding a paragraph explaining it. I would rather have a slightly longer, boring name than a short clever one that needs context to understand.
You'd hate how every Cutlass developer write GPU kernels. It's miserable to read their variable names. They name variables like were trying to shave bytes off the code. Shit like tAgSFA for a partitioned scale factor for A
I'm sure it would have been a great demonstration of CTWTA if the author hadn't fucked it up by not knowing what gear inches are.
You absolutely may not replace gear_inches with size_inches since the former is a term of art.
The whole problem was that the class wasn't named correctly. It isn't a gear, since those don't have rims, it's a gearing. A gearing is what is made of a chainring, cog, and wheel. And a gearing has a specific ratio, development, and gear inches.
PS: I'm sure there is an interesting follow-up about developers having to understand the business side of stuff to be able to CTWTA. Because it seems here the problem is not just calling things what they are, but what happens when the next person comes along and doesn't have the necessary background to recognize what the name means.
Damn it. Fair point. I'll have to update the article. But also to be fair, why should I know what gear inches are? Why should anyone? The author shouldn't have used an example which requires you to know something that's not common knowledge.
It's also frustrating that the name Gear was used for what is apparently a Gearing. And I wonder: does gearing.gear_inches make sense? Maybe it does, maybe it doesn't. I don't have the background to know. I'll have to research. Once again, bad example to use in a book.
tbf, while it doesnt work amazing as an example, whoever working with this code either should know what it is or should have quick access to someone who does
I'm obviously capable of finding out what it means, and I'm interested in doing so. But I would rather the author just use an example everyone can understand without setting down the book and doing research on bicycling.
It's also frustrating that the name Gear was used for what is apparently a Gearing.
"Gear" is also a correct term for this. The problem is that the word "gear" has multiple meanings that are relevant in this context. From Merriam-Webster:
gear noun
[...]
6a(2): a toothed wheel
6b: one of two or more adjustments of a transmission (as of a bicycle or motor vehicle) that determine mechanical advantage, relative speed, and direction of travel
You will recognize definition 6b from phrases like "first gear," "second gear," "shift gears," and so on.
It's a fair argument that the example requires too much specific knowledge to be a good example.
It seems they used gear, the same way one might when talking about a stick-shift car. (first gear, second gear, etc.) But it does carry the confusion of talking about an individual gear. I think gearing would have been less ambiguous.
Incidentally, your cumulative misunderstandings do bring you to a relatively correct answer. Because describing the result as the size of a single gear should be quite close to describing it as the size of the wheel of a penny-farthing.
Penny-farthings... Imperial units are something else...
My rule is that if the code contains something unexpected or something than most people would interpret differently, then there should be a comment.
We do this in traffic to warn cars, it even has a unicode symbol: ⛐
A simple link to the wikipedia article would be enough.
Not having units on the fields is a major red flag: this kind of stuff is what made the "Mars Climate Orbiter" crash. "The navigation team at the Jet Propulsion Laboratory (JPL) used the metric system of millimeters and meters in its calculations, while Lockheed Martin Astronautics [...] inches, feet, and pounds. JPL"
I hope we never colonize other planets because scheduling meetings across interplanetary time zones and relativistic time effects is going to be a nightmare.
One of the arguments I've seen for some web development libraries is "because naming things is hard" and so I wondered when a designer/dev is talking to a peer and trying to sort out where a problem is how do they communicate?
"Oh I see the problem, it's from the flex flex-col overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm transition-shadow hover:shadow-md dark:border-gray-800 dark:bg-gray-900 component"
or do they still dead-name them "Oh I see the problem, it's the card component" or "it's card variant A" or "card CTA with description"
The problem with naming things and calling them what they are spans a host of problems related to context and domain specific knowledge. What is something generally (colloquially) vs what do the experts in that domain call it. I.E. drug vs medication, doctor vs prescriber, patient versus person, gear vs sprocket, and so on. Somewhere you need a system and a glossary of terms that are agreed on and most often you don't have that sort of contract anywhere. Naming conventions often come up on the fly and even when they are agreed upon upfront you run into exceptions that don't get discussed or documented anywhere.
I work with someone that is widely regarded as an incompetent junior dev that's somehow got the mid-level title, he's so bad he must be related to Julius. I wish I could literally print this into a book and smack him around the head with it.
Button that makes new customer? nwCuBtn, newCustButn
Function that takes a loyalty card who's name is synonymous with Honey? Name the argument hone because that one letter being saved is important.
A database column? inclusionsormaybeexclusionscustomerexpiredrecent
There is one particular topic where I am a CTWTA extremist: Coordinate systems. Why bother debating the merits of X-forward or Z-forward, or any such convention, when your axes could be named Forward, Right, and Up? It's clear! It's simple! If you pantomime them enthusiastically, it turns into a little dance!
It's mostly a recreational argument for me at this point.
On the flipside, I've had some surprisingly productive arguments over the years about applying CTWTA via types rather than variable names. The practicality is very much language-dependent, and there are plenty of codebases where it'd be an absolute pain to set up while still meeting deadlines, and it can inadvertently foster Not-Invented-Here syndrome, but it's theoretically great. As long as everyone agrees on where the line is.
I can relate but can't help you Devs simply pickup things that they were taught In the earliest days of programming they're taught programs that have small variable names just to keep the program visually small so they don't get overwhelmed and later they pick that short variable naming as a convention and use it everywhere
It made sense at that time since it took less letters to write or type it was faster to type and write and score more marks
But later when you go write code for production and start maintaining it on long runs....
only then you start to realise your big codebase at work has become ambiguous, now your choice of names doesn't make sense anymore, you're a day short shipping a new feature that you've promised a week ago but you're at 6th day making non-sense commits "chore: fixing variable names, added naming conventions in contribution.md etc."
And that is when you're the only maintainer of the project now just imagine you have a team of 5 then you're fixated to their un-told naming schemes and just keep pushing and you'll never get to think on such a trivial matters
Yeah....
I guess it's a teaching problem... No one taught these things...
IMO the ending example is harder to read, even it's more clear about the implementation. And this is a simple example. I can't imagine how much text would it take to express a complex business problem.
61
u/Downtown_Cat_7425 4d ago
Naming is the cheapest documentation you will ever write. A precise name removes the need for a comment and makes mismatches obvious in review. The hard part is that when you cannot name something cleanly, that is often a signal the abstraction is wrong - split or reshape it instead of adding a paragraph explaining it. I would rather have a slightly longer, boring name than a short clever one that needs context to understand.
110
u/Lke590 4d ago edited 4d ago
I'm sure it would have been a great demonstration of CTWTA if the author hadn't fucked it up by not knowing what gear inches are.
You absolutely may not replace
gear_incheswithsize_inchessince the former is a term of art.The whole problem was that the class wasn't named correctly. It isn't a gear, since those don't have rims, it's a gearing. A gearing is what is made of a chainring, cog, and wheel. And a gearing has a specific ratio, development, and gear inches.
PS: I'm sure there is an interesting follow-up about developers having to understand the business side of stuff to be able to CTWTA. Because it seems here the problem is not just calling things what they are, but what happens when the next person comes along and doesn't have the necessary background to recognize what the name means.
191
u/jechase 4d ago
There are only two hard problems in computer science:
17
u/nhavar 4d ago
One of the arguments I've seen for some web development libraries is "because naming things is hard" and so I wondered when a designer/dev is talking to a peer and trying to sort out where a problem is how do they communicate?
"Oh I see the problem, it's from the flex flex-col overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm transition-shadow hover:shadow-md dark:border-gray-800 dark:bg-gray-900 component"
or do they still dead-name them "Oh I see the problem, it's the card component" or "it's card variant A" or "card CTA with description"
The problem with naming things and calling them what they are spans a host of problems related to context and domain specific knowledge. What is something generally (colloquially) vs what do the experts in that domain call it. I.E. drug vs medication, doctor vs prescriber, patient versus person, gear vs sprocket, and so on. Somewhere you need a system and a glossary of terms that are agreed on and most often you don't have that sort of contract anywhere. Naming conventions often come up on the fly and even when they are agreed upon upfront you run into exceptions that don't get discussed or documented anywhere.
32
u/ReallySuperName 4d ago edited 4d ago
I work with someone that is widely regarded as an incompetent junior dev that's somehow got the mid-level title, he's so bad he must be related to Julius. I wish I could literally print this into a book and smack him around the head with it.
nwCuBtn,newCustButnhonebecause that one letter being saved is important.inclusionsormaybeexclusionscustomerexpiredrecentIt's hell.
3
u/TheOtherZech 3d ago
There is one particular topic where I am a CTWTA extremist: Coordinate systems. Why bother debating the merits of X-forward or Z-forward, or any such convention, when your axes could be named Forward, Right, and Up? It's clear! It's simple! If you pantomime them enthusiastically, it turns into a little dance!
It's mostly a recreational argument for me at this point.
On the flipside, I've had some surprisingly productive arguments over the years about applying CTWTA via types rather than variable names. The practicality is very much language-dependent, and there are plenty of codebases where it'd be an absolute pain to set up while still meeting deadlines, and it can inadvertently foster Not-Invented-Here syndrome, but it's theoretically great. As long as everyone agrees on where the line is.
5
u/PratikVR 4d ago
I can relate but can't help you Devs simply pickup things that they were taught In the earliest days of programming they're taught programs that have small variable names just to keep the program visually small so they don't get overwhelmed and later they pick that short variable naming as a convention and use it everywhere
It made sense at that time since it took less letters to write or type it was faster to type and write and score more marks
But later when you go write code for production and start maintaining it on long runs....
only then you start to realise your big codebase at work has become ambiguous, now your choice of names doesn't make sense anymore, you're a day short shipping a new feature that you've promised a week ago but you're at 6th day making non-sense commits "chore: fixing variable names, added naming conventions in contribution.md etc."
And that is when you're the only maintainer of the project now just imagine you have a team of 5 then you're fixated to their un-told naming schemes and just keep pushing and you'll never get to think on such a trivial matters
Yeah....
I guess it's a teaching problem... No one taught these things...
6
u/rekkonnect 4d ago
I could use half the rant and double the reasoning of why people don't apply CTWTA, and it's just laziness
And really we have bigger fish to catch than to masturbate over how good CTWTA is when applied
3
u/_choam_ 4d ago
Either call something what it is, or use a one letter name when calling something what it is is more confusing.
1
u/stools_in_your_blood 4d ago
It has always bothered me when people refer to an email address as an "email", as in "what's your email?" It's like calling a phone number a phone.
1
u/maelstrom071 4d ago
Very good piece, and a rule I generally try to follow
1
u/Ashnoom 2d ago
I've just named a function " TheyNeedToWakeUpAfterJustGoingToSleep" to complement the "TheyJustWentToSleep"
(I am observing some IO lines, high = awake and low = asleep)
1
u/enchufadoo 2d ago edited 2d ago
IMO the ending example is harder to read, even it's more clear about the implementation. And this is a simple example. I can't imagine how much text would it take to express a complex business problem.