Naming is hard. And I share the frustration. Longer names are a little less wieldy to start, but future readers of the code, including future you, will appreciate the effort.
One related overlapping problem is the need to also manage dimensions or units of measurement. That's the `_inches` suffix in the article's sample code. More precise, but still binds to legacy U.S. customary units in a mostly metric world. Having plain numeric values carry no units (nor dimensions, though that's more subtle) leads to ever so many errors. The loss of Mars Climate Orbiter, e.g., along heaps of money and hundreds of person-years invested. Wish dimensions and units were more fundamental to mainstream programming language computations. Until then, please consider using libraries that fill the gap such as Pint (Python), ruby-units (Ruby), unitmath (JavaScript/TypeScript), or uom (Rust).
I'll share one reason: long variable names can obscure the shape of otherwise concise code. When this happens, they occlude information at the whole-program or whole-function level, even as they add information at the variable level.
Por que no los dos? We can read code however we want now; it should be trivial to build the view that collapses long names down to notation-style short names (or, in my case, vice versa --- hover over or click on `s` to see that it's "count of records selected for this query").
I guess I would respond with a weak claim and a strong claim. The weak claim is yes, tools can do that, but there's arguably still something to be said for a program as text in a language, without needing tool support to read it.
The strong claim is that you don't end up with the same shape if you abstract out the long names at the end, because the shape of a program evolves with each bit that you add as you write it.
(Maybe all of this goes away once no one looks at code anymore, but we're not there yet, or at least I'm not.)
I've been hung up on this since I was a teenager learning to code, how insanely limiting linear text is as a medium of expression for code. This just feels like a perfect example. Concise notation is a valuable lens! Authorial intent and backstory is a valuable lens! You can't have both at the same time in a simple text editor.
The problem is text editors!
I'm "yes, and"-ing your point about notational concision for what it's worth. Though I worry it's all a Scheme to get people to take APL more seriously.
The pushback always seems to be about how long names look, never about the cost of misreading short ones. I'll take some extra verbosity over having to guess every single time.
Tyre thickness should not appear in the formula of wheel diameter though... Also it would be better to include the unit in the names of non dimensionless values.
> I'll be honest with you, dear reader: I couldn't figure out the meanings of these variables by thinking through it on my own, nor by flipping through the book's pages. I had to go and ask Claude.
this is definitely learned helplessness. You do _not_ need claude to read a few lines of context and figure this out.
class Wheel
def diameter
rim + (tire * 2)
end
end
If you know what a diameter is, then this snippet contains all the information you need to understand what `rim` and `tire` most likely are; the missing information is units but those appear to be out of scope in this book example.
Some people call it slop, although a more professional framing would be to call it high variance ambiguous language. Don’t even get me started on jargon, like referring to things as “surfaces” instead of what they are (react components, pages on a website, etc)
Naming is hard. And I share the frustration. Longer names are a little less wieldy to start, but future readers of the code, including future you, will appreciate the effort.
One related overlapping problem is the need to also manage dimensions or units of measurement. That's the `_inches` suffix in the article's sample code. More precise, but still binds to legacy U.S. customary units in a mostly metric world. Having plain numeric values carry no units (nor dimensions, though that's more subtle) leads to ever so many errors. The loss of Mars Climate Orbiter, e.g., along heaps of money and hundreds of person-years invested. Wish dimensions and units were more fundamental to mainstream programming language computations. Until then, please consider using libraries that fill the gap such as Pint (Python), ruby-units (Ruby), unitmath (JavaScript/TypeScript), or uom (Rust).
This is just "long variable names are good" which for some reason gets a lot of pushback.
> which for some reason gets a lot of pushback
I'll share one reason: long variable names can obscure the shape of otherwise concise code. When this happens, they occlude information at the whole-program or whole-function level, even as they add information at the variable level.
Por que no los dos? We can read code however we want now; it should be trivial to build the view that collapses long names down to notation-style short names (or, in my case, vice versa --- hover over or click on `s` to see that it's "count of records selected for this query").
I guess I would respond with a weak claim and a strong claim. The weak claim is yes, tools can do that, but there's arguably still something to be said for a program as text in a language, without needing tool support to read it.
The strong claim is that you don't end up with the same shape if you abstract out the long names at the end, because the shape of a program evolves with each bit that you add as you write it.
(Maybe all of this goes away once no one looks at code anymore, but we're not there yet, or at least I'm not.)
I've been hung up on this since I was a teenager learning to code, how insanely limiting linear text is as a medium of expression for code. This just feels like a perfect example. Concise notation is a valuable lens! Authorial intent and backstory is a valuable lens! You can't have both at the same time in a simple text editor.
The problem is text editors!
I'm "yes, and"-ing your point about notational concision for what it's worth. Though I worry it's all a Scheme to get people to take APL more seriously.
Claude in particular seems pretty resistant to it. Renaming its variables to something I understand is half of my code reviews sometimes.
The pushback always seems to be about how long names look, never about the cost of misreading short ones. I'll take some extra verbosity over having to guess every single time.
I like it.
I like even better that be able to Call Things What They Are, you must first Know What They Are.
And if you have figured that out, you are close to being able to explain Why Things Are What They Are.
Tyre thickness should not appear in the formula of wheel diameter though... Also it would be better to include the unit in the names of non dimensionless values.
The unit could even be encoded in the type system
Right.. it's almost like the programmer would be helped by knowing what type of "messages" the object in hand accepts.
I agree here, but c'mon...
> I'll be honest with you, dear reader: I couldn't figure out the meanings of these variables by thinking through it on my own, nor by flipping through the book's pages. I had to go and ask Claude.
this is definitely learned helplessness. You do _not_ need claude to read a few lines of context and figure this out.
If you know what a diameter is, then this snippet contains all the information you need to understand what `rim` and `tire` most likely are; the missing information is units but those appear to be out of scope in this book example.One of the many problems with POODR.
Some people call it slop, although a more professional framing would be to call it high variance ambiguous language. Don’t even get me started on jargon, like referring to things as “surfaces” instead of what they are (react components, pages on a website, etc)
I would propose an alternative, Call Things What They're Like.