🌉 bridged from @nark3d@thelemmy.club by Tidepool
nark3d
@nark3d.thelemmy.club.ap.tdpl.io
Inline First: a binding has to say something the expression doesn't
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. https://prickles.org/tenet/inline-first/S5
Guard Clauses: the preconditions are the point of the function
I wrote up the guard clause pattern because most functions I read still have the arrow shape. The code works, so nobody touches it. Guard clauses are about what the body is allowed to assume. A function that checks null, type and permission at the top and returns early on each has told you three facts before you read a line of the work. A function that nests the same three checks has told you nothing until you've counted the closing braces at the bottom. That's the operational part. Once the checks sit at the top as separate returns, a reviewer can argue with the assumption itself. Is this function really the right place to enforce permission? Should that null be possible at all? Buried four levels deep, nobody asks. The pyramid is a hidden preconditions problem. https://prickles.org/tenet/guard-clauses/S4
Cyclomatic caps: the limit is the lever, not the warning
Writing up the caps we run in the repo. The number that gets the reaction is complexity at 3. People hear that and assume I've mistyped it. It's 3 because the cap is a tripwire. Below it, nobody argues. Above it, the build fails and the function gets split. There's no "just this once" column in the lint config, which is the whole point. The reason it's set that tight is that a soft convention gets negotiated with and a hard limit doesn't. I've spent enough years watching engineers argue with style-guide warnings to know how that conversation ends. The warning gets muted, or it gets an inline disable with a comment explaining why this one is fine. The comment is usually wrong six months later. A failing build is a different kind of object. It doesn't care how senior you are. The cap being the achievement is what I disagree with. The cap makes you do the extraction. If the function splits into two functions that each still do too much, you've satisfied the linter and learned nothing, which is why I don't treat a green build as evidence the design is fine. It's evidence the code hasn't drifted yet. Setting it this tight surprised me with how often the cap caught something a reviewer would have let through. Three branches and a fifteen-line ceiling sounds generous until you write against it. Then the ones that fail are the functions where a fourth special case had been creeping in without anyone saying so. The linter never gets tired at the end of a long diff. The cap only enforces the part of the problem you can count. https://prickles.org/tenet/cyclomatic-caps/S2
Encapsulation: keyword encapsulation isn't the same as hiding a decision
Parnas wrote down the test in 1972 and most codebases still fail it. A module is characterised by the design decision it hides from every other module. That's the whole rule. Private fields, protected methods, a tidy export list, none of that counts for anything if the decision underneath is still visible to everyone who calls in. The getter and setter pair. A class takes a field private, then exposes read and write for it. Every caller can reach in and set the thing, so the module has fused itself to every callsite that knows about its insides, exactly as if the field had been public. The keyword did the syntactic part and nobody did the design part. The field is private and the decision is not. A module exporting a helper that one caller uses is the same failure at the file level. The boundary is theatrical. If only one caller needed it, the helper belongs inside that caller, and leaving it on the public surface tells every future reader that it's part of the contract when it isn't. Agents have made this worse rather than better. Handed a class with a getter for every field, an agent reads the getters as the vocabulary of the module and builds on them. A person might notice the shape is thin and go and look, an agent takes the surface as the contract, because the surface is what it was given. Two getter-and-setter classes and the decision that was supposed to be hidden is now the interface for the next twenty files. The surface is the meaning, because the surface is what gets copied. https://prickles.org/tenet/encapsulation/F6
Self-documenting code: if the comment is doing the explaining, the code isn't
A comment is worth leaving. I've come round to thinking there isn't one that explains what the code does. If you need a sentence to say what a block is for, the block is telling the wrong story. Rename the function. The comment disappears because nothing needed explaining. People hear when I say this that I want no comments at all. A comment that explains why, or cites the paper the algorithm came from, or records the incident that made this branch exist, is doing work the code cannot do. That kind of note belongs next to the module and ages fine. The one I want gone is the running narration, the line above the loop that says what the loop does. Those rot first, because the code underneath them changes and the sentence above it doesn't. This is not a style preference. A comment is a second copy of the meaning. The code does what it does and the comment says what it used to do. The reader now has to decide which one to believe. That's worse than no explanation at all, because the wrong one is right there in the same file looking authoritative. Agents have made me firmer on it rather than softer. A developer reading a vague function works the intent out from everything around it. An agent takes the function name and the comment at face value and builds on whichever it read last, so a lazy name becomes the vocabulary for the next twenty files. The code is the meaning because the code is what gets copied. If the meaning isn't obvious, the move is always the same: rename the function, split it, improve the parameter names. Look again and look harder before you reach for the comment. The full write-up is at https://prickles.org/tenet/self-documenting-code/F5
Simplicity: the cap is the easy half
Linter caps are easy. Max parameters at three, complexity limits, a hard cap on function length. Those are mechanical and they work, but they don't touch the move that actually costs you. Generating a four-parameter helper from one example is easy. The agent does it in seconds, the diff looks tidy, and no cap fires because four is under the limit and the function is short. The tell is in the sentence I have to say in review: what requirement does this serve? Most of the time the honest answer is none yet. A parameter added for the next time it's needed, a flag so one caller can opt out of half a helper, a config option in case someone asks. Each one is rational on its own and there is no moment where anyone decides to make the codebase harder to open. It compounds. The sub-discipline I find hardest is rejecting the easy generation. The agent will produce the general version because the general version is what the shape suggests, and accepting it feels like good taste rather than the opposite. The version I want instead serves the requirement in front of me. A note so the next person can generalise when the requirement arrives. The 1973 line still holds. Simplicity is a necessary condition. The cap only enforces the part of it you can count. https://prickles.org/tenet/simplicity/F4
Don't Repeat Yourself: the word doing the work is knowledge
I've watched DRY get applied as a reflex more than as a rule. Two similar lines appear and a helper is extracted, and six months later that helper is a flag for every caller and a name that no longer covers any of them. The failure isn't that the team deduplicated. It's that they deduplicated on appearance and skipped the second sentence Hunt and Thomas wrote, the one with the word knowledge in it. Code that looks alike isn't necessarily the same fact. Two loops that happen to iterate the same way for different reasons are two facts. Merge them and the next change to one becomes a change to both, which is exactly the rot DRY exists to stop. The test I use is whether the two copies would have to change together. If they would, they're one fact. If they wouldn't, they're two facts that currently rhyme. The boundary matters as much as the count. Inside a bounded context, deduplication is cheap insurance, because both copies answer to the same owner and the same change. Across a context boundary, a shared helper fuses two products into a single change, and now every team that touches one has to think about the other. The coupling costs more than the duplication did. So I extract on the second occurrence inside a context. A little copied code is cheaper than a helper with a name that means three things. Fair to the reflex: the reflex exists because duplicated knowledge really does rot, and neglected copies drift until there's no way to tell which is right. The rule is sound. The trigger is wrong. The full write-up is at https://prickles.org/tenet/dont-repeat-yourself/F3
Persistent Brief: commit the paragraph everyone keeps pasting
I have watched teams treat the agent like a goldfish. Every session opens with the same paragraph in the chat: we use Tailwind, no inline styles, single quotes, named exports, please don't add comments. By the third session someone has pasted it from a Notion page. By the tenth, half the team has a slightly different version. By the thirtieth, two engineers are arguing about which one is right and the agent is following whichever paragraph landed last. The fix has been sitting in Anthropic's own engineering writing since 2024. Commit the brief. Put it in the repo, in a file the agent reads at the start of every session, and let it be versioned like everything else the team owns. Put the brief under 200 lines. Anthropic's recommendation is load-bearing. You read the brief or you do not. That is what the line count decides. A brief that grows into a wall of text gets skimmed the way a new joiner skims a 900-line onboarding doc. The paragraphs that matter end up buried under the ones that do not. Keeping it short makes the team choose what changes the agent's output, rather than dumping every convention the codebase has ever had. The other thing the cap does is make the brief a living document. A short file is cheap to edit, so it gets edited when the convention changes. A long one is not, so it rots, and then someone starts a fresh paragraph in the chat because the committed version no longer reflects reality. That is how you end up with thirty versions again. The longer version is at https://prickles.org/tenet/persistent-brief/AI2
Parameter Object: count the commas backwards and you have your answer
I have lost count of the times I have read a call with five positional arguments and had to count commas backwards to work out which one is the timeout and which is the retry count. The fix has been in the catalogue since 1999: introduce a parameter object. Bundle the fields that keep travelling together and give the bundle a name and a type. The call sites stop reading like SQL with the column names removed. The trigger I use is the third caller. Two call sites passing the same group can be coincidence. A third one tells you the concept has been in the domain all along without anyone naming it. A third caller passing the same group is the point at which the group wants a name. Waiting for a lint warning misses this, because the warning fires on width and the problem is that the group has no name. The cap is editorial and we set it the same way, max-params at 3. But the rule catches the symptom rather than the cause. A constructor taking four loose strings passes nothing and fails everything, while a four-argument call where three of them are genuinely independent is fine. The rule makes you look. A parameter object does not automatically improve things. Once a function takes a parameter object, every caller has to build one, and if that object is a bag with no methods you have moved the comma-counting to the construction site. The object should be the place the validation lives, so an invalid one cannot be built. If it is only a struct, you have added a hop. Naming the object usually turns up a domain word that was not in the codebase before. That part still surprises me. The extraction is mechanical, but the name is a decision. You were avoiding that decision every time you typed that fifth argument. I run the same reasoning on agents now. An agent handed a five-argument signature will keep adding positional arguments, because the shape it sees is the shape it copies. It cannot count commas backwards either. The longer version is at https://prickles.org/tenet/parameter-object/S3
Naming: if you have to open the body, the name isn't done
Everyone I've worked with agrees that naming matters. Almost nobody spends any time on it. The name gets picked while the code is half written and then it sticks, because renaming feels like fuss once the thing works. The check I use in review is to read the function name and the parameters and say in one sentence what the call does. If I can do that without opening the body, fine. If I can't, either the name is bad or the function is doing two jobs and no single name will cover it. In my experience it's the second more often than you'd think, so I run this before I look at length or complexity. It finds the same problem earlier. The best names are the ones the product owner already uses. The worst describe the machinery: process, handle, manager, helper, data. Each is a placeholder for a noun nobody has bothered to find yet. The type should agree with the name too. A parameter called id typed as string takes anything. Call it userId with a UserId type and the call site, the signature and the compiler all say the same thing. The fair objection is width, and code that borrows abbreviations from the paper it implements. Width is an editor problem. For code that follows a paper, cite the paper next to the module and the abbreviation is the honest name for its readers. For ordinary application code I'd hold the line. Agents have made me stricter about this. They abbreviate out of habit and it's easy to wave through proc because the prompt said processing. A developer who meets that later opens the body and works it out. An agent takes the name at face value and builds on it, so one lazy name becomes the vocabulary for everything around it. I write these up at https://prickles.org/tenet/intention-revealing-names/F2 if the longer version is any use.