I see const userName = user.name; followed by exactly one use of userName. The name says nothing that user.name hadn’t already said. It’s a hop the reader makes for nothing.
Fowler already had the answer: Inline Variable is the documented inverse of Extract Variable. Both moves live on the same continuum and most people only ever walk one way. Extract when the expression hides intent. Inline when the binding adds nothing the expression didn’t already say. The failure isn’t that the extract happened. It’s that the move never runs in reverse.
The other end of the continuum is the case I don’t want inlined. A function that retries three times and waits 5000 milliseconds between attempts reads worse than the same function with MAX_RETRIES = 3 and BACKOFF_MS = 5000. The constant earns its name because it carries information the literal doesn’t. That’s the test. It cuts both ways.
The trouble is that inlining never gets proposed. Extraction has a lint rule, a keyboard shortcut and a refactoring menu item behind it. Inlining has a name in a catalogue and no muscle memory. So the bindings accumulate, each one individually defensible. The function slowly fills with nouns that point at other nouns.
Agents make it worse, and in a way I hadn’t expected. Handed a file full of these bindings, an agent reads the names as the vocabulary and builds on them, so a binding that never earned its existence becomes the handle for everything downstream. It copies the surface it was given. The surface is a list of names.
Wrote the longer version up here.
In general, I agree. Still, this is highly language-dependent.
For example, in C# (and technically Python/JS/etc), a property evaluation can look like
user.name(though realistically it might befoo.Countor something) but perform non-trivial work to produce an output. Used once? Sure, just inline it. Used twice? Might be better not to, depending on the work of course.In Rust,
let username = user.name;movesnameout ofuser(assuming it’s aStringor other non-Copytype). There are fringe cases where this can be useful, especially when it comes to macros or when working with the borrow checker. To give an example, you can borrow fromusernamewithout borrowing fromuser.namewhich can let you mutate and useuserseparately (like settingnameagain so it’s no longer partially destructured and you can passuseraround).These are all fringe cases. In the common case, just inline it.
The other end of the continuum is the case I don’t want inlined. A function that retries three times and waits 5000 milliseconds between attempts reads worse than the same function with MAX_RETRIES = 3 and BACKOFF_MS = 5000. The constant earns its name because it carries information the literal doesn’t. That’s the test. It cuts both ways.
Yeah, give those a name. A config file is a good home for the values, even if that config file is just a source code file that exports constants.
Sorry for not engaging with the content, but “<thing> first” is the Developer version of “<thing>maxing”, the way this Idiom doesn’t really ever refer to any order that <thing> should be first in except priority, or attention.

