r/programming • • 4d ago

Call Things What They Are

https://www.saturnci.com/call-things-what-they-are.html
155 Upvotes

45 comments sorted by

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.

12

u/max123246 3d ago edited 3d ago

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

Just look at it: https://docs.nvidia.com/cutlass/latest/media/docs/pythonDSL/cute_dsl_general/naming_conventions.html

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_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.

14

u/jasonswett 4d ago

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.

33

u/entronid 4d ago

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

5

u/FullPoet 4d ago

But also to be fair, why should I know what gear inches are

Why use a term you don't know what means - or cant be bothered to do the bare minimum of research?

No curiousity at ALL?

8

u/jasonswett 4d ago

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.

23

u/Snarwin 4d ago

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.

7

u/Lke590 4d ago

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...

13

u/flif 4d ago

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"

191

u/jechase 4d ago

There are only two hard problems in computer science:

  1. Cache invalidation
  2. Naming things
  3. Off by one errors

112

u/Eric848448 4d ago

Motherfucking dates and times.

38

u/un-pigeon 4d ago

Especially timezones!

29

u/poop-machine 4d ago

I hope we never colonize other planets because scheduling meetings across interplanetary time zones and relativistic time effects is going to be a nightmare.

8

u/un-pigeon 4d ago

Please don't talk about misfortune.

9

u/Eric848448 4d ago

https://youtu.be/-5wpm-gesOY

This guy knows what’s up.

5

u/Drugba 4d ago

I lead a team that was tasked with internationalizing an enterprise product. This video was the first thing I sent to anyone who joined.

1

u/Eric848448 4d ago

There’s an article out there about bad assumptions about US zip codes too.

3

u/raralala1 3d ago

timezone is easy, the worst part is DST like why are we still doing it.

2

u/un-pigeon 3d ago

Try explaining this concept to a client who has never changed time zones or who has never thought about the concept.

2

u/johntheswan 3d ago

Leap years, seconds, etc

17

u/creeper6530 4d ago

4. eading.Multithr

17

u/orxT1000 4d ago

5. Asynch
9. Asynch

3

u/Turbots 3d ago

Spelling!

1

u/therealjohnsmith 4d ago

The problem is that names need to be refactored along with functionality because the meaning shifts as the problem space is better understood

-2

u/nelz9999 4d ago

I literally used that in a work conversation YESTERDAY! 🤣

-5

u/Spleeeee 4d ago

You were off by one.

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.

  • 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

It's hell.

20

u/hughperman 4d ago
  • nuCussyButt
  • loyalHun
  • no notes, it's perfect

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.

1

u/vetinari 2d ago

Ha! Cartesian coordinate systems are easy; try arguing that with geodetic ones :-)

1

u/ShinyHappyREM 18h ago

Cartesian coordinate systems are easy

You'd think so, but...

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

11

u/EliSka93 4d ago

I'm currently trying to adapt some code a mathematician wrote...

They're some of the worst offenders.

5

u/entronid 4d ago

i mean they just call things single letters

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/insidious_concern 2d ago

But I have 27 things to name

1

u/ShinyHappyREM 18h ago

use ÄÖÜ

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/-Redstoneboi- 2d ago

"what's your address" isn't exactly great either

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.