<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Deep Roots – Naming as a Process</title><link>/articles/naming-process/</link><description>Recent content in Naming as a Process on Deep Roots</description><generator>Hugo -- gohugo.io</generator><atom:link href="/articles/naming-process/index.xml" rel="self" type="application/rss+xml"/><item><title>Articles: Naming as a Process (Article 1)</title><link>/articles/naming-process/naming-as-a-process/</link><pubDate>Thu, 17 Oct 2019 00:00:00 +0000</pubDate><guid>/articles/naming-process/naming-as-a-process/</guid><description>
&lt;p>We all know naming is a pain in the ass and you can&amp;rsquo;t trust the names in your code. But it doesn&amp;rsquo;t have to be that way.&lt;/p>
&lt;p>Many people try to come up with a great name all at once. This is hard and rarely works well. The problem is that naming is design. Here are the things you are typically trying to do all at once while naming:&lt;/p>
&lt;ul>
&lt;li>Deciding the things the code should do&lt;/li>
&lt;li>Deciding which things go together&lt;/li>
&lt;li>Deciding which abstractions best represent those clusters&lt;/li>
&lt;li>Picking a name that clarifies intent&lt;/li>
&lt;li>Picking a name that distinguishes from all the other similar intents&lt;/li>
&lt;li>Describing the side effects of the code&lt;/li>
&lt;li>Keeping your name under 15 characters&lt;/li>
&lt;/ul>
&lt;p>This is why naming is hard.&lt;/p>
&lt;p>Our brains can&amp;rsquo;t juggle seven cognitively complicated tasks &lt;strong>at once&lt;/strong>. After brain overload, most of us give up and settle for a crappy name.&lt;/p>
&lt;p>Naming something perfectly the first time isn&amp;rsquo;t going to happen. Let&amp;rsquo;s talk about evolutionary naming.&lt;/p>
&lt;p>The easiest approach for finding good names is to progress along a series of regular steps.&lt;/p>
&lt;p>&lt;img src="images/naming-as-a-process.png" alt="Naming as a Process">&lt;/p>
&lt;h2 id="the-solution--annoyingly-simplified">The solution &amp;hellip; annoyingly simplified&lt;/h2>
&lt;p>At each step, I look at one part of the code, understand one kind of thing that is happening, have an insight, and write it down. I repeat this until I have moved one step down this list. I keep going until I have a good enough name for my purpose.&lt;/p>
&lt;h2 id="the-big-picture">The big picture&lt;/h2>
&lt;p>Those of you who are reading ahead will wonder why I am focusing on names. I mean, names are annoying to come up with and perhaps this will make it easier, but is that really a problem?&lt;/p>
&lt;p>The answer to that question lies at the heart of understanding, preventing, and paying off technical waste.&lt;/p>
&lt;h3 id="the-source-of-all-technical-waste">The source of all technical waste&lt;/h3>
&lt;blockquote>
&lt;p>Wasteful code is any code that is hard to scan. Technical waste is anything that increases the difficulty of reading code.&lt;/p>
&lt;p>Me.&lt;/p>
&lt;/blockquote>
&lt;p>My focus on code reading may seem odd to many of you. After all, we’re programmers. We’re good at reading complex code, and our job is to update code. Shouldn’t the definition of technical waste be something about the cost and risk of changing code?&lt;/p>
&lt;p>This is.&lt;/p>
&lt;p>It turns out that the largest single thing developers spend time doing is reading code.&lt;/p>
&lt;p>More than design.&lt;br>
More than writing code.&lt;br>
More than scanning.&lt;br>
And yes. Even more than meetings (well, probably).&lt;/p>
&lt;p>According to an analysis from Eclipse data, programmers spend around 60-70% of their entire programming time reading code.&lt;/p>
&lt;p>So if we want to be more efficient, we need to improve our ability to read code.&lt;/p>
&lt;h3 id="its-about-risk-too">It&amp;rsquo;s about risk too&lt;/h3>
&lt;p>Bugs aren&amp;rsquo;t random. Unsurprisingly, bugs get written more often when:&lt;/p>
&lt;ul>
&lt;li>methods are long or deeply nested (cyclomatic complexity),&lt;/li>
&lt;li>concepts are spread around,&lt;/li>
&lt;li>code does multiple things,&lt;/li>
&lt;li>there are side effects.&lt;/li>
&lt;/ul>
&lt;p>Make a method longer or make code more complex to reason about and people write more bugs when they edit it.&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>But those aren&amp;rsquo;t the #1 cause of bugs.&lt;/strong> Poor naming was #2 but became #1 when inconsistent indentation was solved by IDE&amp;rsquo;s.&lt;/p>
&lt;/blockquote>
&lt;h2 id="bugs-come-from-incomplete-understanding">Bugs come from incomplete understanding&lt;/h2>
&lt;p>Now that we know bugs aren&amp;rsquo;t random, let&amp;rsquo;s look at what leads to a bug.&lt;/p>
&lt;ol>
&lt;li>Mistakes happen when our mental model doesn&amp;rsquo;t match the reality of the code.&lt;/li>
&lt;li>Neuroscience shows that our short-term memory only has seven registers.&lt;/li>
&lt;/ol>
&lt;p>So if the real code would take more than seven registers to model, we can&amp;rsquo;t help but write bugs. So let&amp;rsquo;s make the code take fewer registers. Since it takes more registers to comprehend code than to remember what it does, the easiest way to reduce registers is to make the code easy to comprehend.&lt;/p>
&lt;p>So if our definition of technical debt is code that is difficult, expensive, or risky to change, then the root cause of that is code that is hard to scan. And what makes code easy to scan? Good names.&lt;/p>
&lt;h2 id="which-brings-us-back-to-names">Which brings us back to names&lt;/h2>
&lt;p>Definitions are where we communicate instructions to the computer. Names are the place we communicate our insights and intentions to other humans.&lt;/p>
&lt;h2 id="implementing-the-solution">Implementing the solution&lt;/h2>
&lt;p>Remember, the annoyingly simplified solution is to have one insight at a time, write it into a name, and repeat until your name shifts to the next stage. The remaining challenge is to learn how to make each kind of naming shift. For each stage you will need to know:&lt;/p>
&lt;ul>
&lt;li>where to look for insights,&lt;/li>
&lt;li>what kinds of insights to glean,&lt;/li>
&lt;li>how to write them down in a name,&lt;/li>
&lt;li>how to use tools to do this at speed, and&lt;/li>
&lt;li>how to know when you are done.&lt;/li>
&lt;/ul>
&lt;p>We have extracted this into a series of micro-skills that are designed to be easy to learn and pay off with advantages from the start. That sequence is Code by Refactoring. Start by helping your team &lt;a href="https://learn.digdeeproots.com/buy-naming-as-a-process/">learn Naming as a Process&lt;/a>.&lt;/p>
&lt;h2 id="adopt-now">Adopt Now&lt;/h2>
&lt;p>Help your team adopt Naming as a Process now!&lt;/p>
&lt;p>&lt;a href="https://learn.digdeeproots.com/habit/naming-as-a-process/">See How it Works&lt;/a>&lt;/p>
&lt;h2 id="read-more">Read More&lt;/h2>
&lt;p>Next up: &lt;a href="https://www.digdeeproots.com/articles/get-to-obvious-nonsense/">Get to Obvious Nonsense&lt;/a>.&lt;/p>
&lt;p>Or read the whole &lt;a href="https://www.digdeeproots.com/articles/on/naming-as-a-process/">Naming as a Process blog series&lt;/a>.&lt;/p></description></item><item><title>Articles: Get to Obvious Nonsense (Article 2)</title><link>/articles/naming-process/get-to-obvious-nonsense/</link><pubDate>Wed, 16 Oct 2019 00:00:00 +0000</pubDate><guid>/articles/naming-process/get-to-obvious-nonsense/</guid><description>
&lt;p>The two most terrible kinds of names are also the most common:&lt;/p>
&lt;ul>
&lt;li>Names that mislead you, and&lt;/li>
&lt;li>Important parts of something else, so they don’t even have a name.&lt;/li>
&lt;/ul>
&lt;p>In the spirit of naming as a process, we want a quick way to fix these two problems. It needs to be trivially fast and light, so that we can do it the hundreds of thousands of times that most codebases need.&lt;/p>
&lt;p>We will turn Missing and Misleading into Obvious Nonsense.&lt;/p>
&lt;p>Obvious Nonsense isn’t great, but at least it isn’t misleading! Now it becomes obvious to everybody on the team that the name is nonsense and they won’t be tricked into writing a bug.&lt;/p>
&lt;h2 id="fixing-missing-names">Fixing Missing Names&lt;/h2>
&lt;p>Why start there? Making code readable is our ultimate goal, however often code has many different concepts in the same method/class/field/variable. We want to pull out each concept and give it a name. When a concept is embedded within another thing, we can see its name as &lt;em>missing&lt;/em>.&lt;/p>
&lt;h3 id="part-1-look-at-long-things">Part 1: Look at Long Things&lt;/h3>
&lt;p>Focus on long things that are related to the task at hand; the long methods, long classes, long files, long argument lists, long expressions. All of these are more readable and consumable when broken into pieces with one concept each.&lt;/p>
&lt;h3 id="part-2-look-for-1-lump-that-hangs-together">Part 2: Look for 1 lump that hangs together&lt;/h3>
&lt;p>I look around for things that seem to go together. Examples include:&lt;/p>
&lt;ul>
&lt;li>A paragraph of statements&lt;/li>
&lt;li>A non-obvious expression (usually involving arithmetic or logic)&lt;/li>
&lt;li>A set of parameters that are frequently passed together.&lt;/li>
&lt;li>A set of parameters that are used together in the method (such as a bool which indicates whether another variable is valid)&lt;/li>
&lt;/ul>
&lt;p>I just pick one chunk that hangs together. It doesn&amp;rsquo;t really matter how good a chunk I find. There are techniques that will find better chunks and speed up my understanding, but any chunk will get me one step closer. We can leave refinement for later. Good is too expensive; all I want is better (quickly).&lt;/p>
&lt;h3 id="part-3-write-down-by-extracting-it-as-applesauce">Part 3: Write down by extracting it as Applesauce&lt;/h3>
&lt;p>We want to understand this lump of stuff. The first step is to create a thing to be named. Typical languages allow us to name any of 5 different things, so we must create one of these things. To do this, we use one of 5 refactorings:&lt;/p>
&lt;ul>
&lt;li>Extract Method (to name a bunch of statements)&lt;/li>
&lt;li>Introduce Variable, Parameter, or Field (to name an expression)&lt;/li>
&lt;li>Introduce Parameter Object (to name a set of parameters that are passed around together)&lt;/li>
&lt;/ul>
&lt;p>We want an Obvious Nonsense name, so use &lt;code>Applesauce&lt;/code>. Everyone on the team will instantly recognize it as nonsense. Also, because there is only one nonsense name, you will need to make this name honest (the next step) before you make more nonsense in the same scope.&lt;/p>
&lt;h2 id="applesauce-really">&lt;code>Applesauce&lt;/code>? Really?!&lt;/h2>
&lt;p>Obvious nonsense feels unprofessional. It’s not how you want to represent your work. Creating bugs, however, is more unprofessional - we are just more used to it and have come to accept it. Things that contain many unnamed concepts are difficult to reason about, which will cause developers to write bugs.&lt;/p>
&lt;p>The &lt;a href="https://www.digdeeproots.com/articles/naming-as-a-process-learning-path/#packages">self-directed and coached habit changes&lt;/a> for this process address common resistances, including the urge to take the time to create a good name.&lt;/p>
&lt;h2 id="finding-better-chunks-in-long-methods">Finding Better Chunks in Long Methods&lt;/h2>
&lt;p>There are a few ways for you to hone your chunk finding skills. Once you’re in a long method and you see that there are possible missing names, use these strategies to find the best pieces to break out.&lt;/p>
&lt;h3 id="look-at-the-bottom-first">Look at the Bottom First&lt;/h3>
&lt;p>Long methods tend to be organized as:&lt;/p>
&lt;ol>
&lt;li>guard clauses&lt;/li>
&lt;li>use parameters to read the data the method actually wants into local variables&lt;/li>
&lt;li>process&lt;/li>
&lt;li>calculate a result&lt;/li>
&lt;li>either write it down somewhere or return it.&lt;/li>
&lt;/ol>
&lt;p>This means that the more important stuff is near the end of the method. So start looking for chunks from the bottom, not the top.&lt;/p>
&lt;p>This also makes extraction easier in most languages, because functions often allow multiple parameters but only one return value. So it is easier to flow messy information (like a bunch of local variables) into a function than out. This is not a problem in languages with functions that have the same cardinality for both parameter lists and returns (support destructuring return like Python or support only one parameter like Haskell).&lt;/p>
&lt;h3 id="use-binary-search-to-read-less">Use Binary Search to Read Less&lt;/h3>
&lt;p>In general you&amp;rsquo;re not reading code for the joy of reading it. You&amp;rsquo;re trying to accomplish something. Use that something to guide what code you bother reading.&lt;/p>
&lt;p>Use binary search to quickly find chunks that are highly relevant. Look for large chunks that don&amp;rsquo;t contain whatever it is you are seeking, or small chunks that do. Either quickly reduces the search space.&lt;/p>
&lt;p>Foreshadowing a bit into the next step, when you extract a large chunk of code you know to not be related, just get the name up to &lt;a href="https://www.digdeeproots.com/articles/naming-is-a-process-nonsense-to-honest/">barely Honest&lt;/a> and then move on. For example, you could call it &lt;code>probably_DoStuffUnrelatedTo[whatever]()]&lt;/code>.&lt;/p>
&lt;h3 id="follow-control-structures">Follow Control Structures&lt;/h3>
&lt;p>Long methods are often dominated by a single control structure (after the guard clauses and fetching data into locals). The body of that control structure is often a good target. If there are multiple control structures in sequence, instead take the whole last control structure.&lt;/p>
&lt;p>For example, if a method &lt;code>BecomeFroglike()&lt;/code> contains one giant &lt;code>foreach&lt;/code> loop, extract the body of the loop and call it &lt;code>MakeOne[whatever the control variable is]BecomeFroglike()&lt;/code>.&lt;/p>
&lt;p>And if a method contains a &lt;code>foreach&lt;/code> loop, then an &lt;code>if&lt;/code> block, then another &lt;code>foreach&lt;/code> loop, extract those into three methods, each taking the whole control structure. The outer method is then just a series of 3 method calls in sequence.&lt;/p>
&lt;p>Exception handling is a little special. The body of a &lt;code>try&lt;/code> block is often a good target for extraction. I usually name the resulting function &lt;code>*_Impl()&lt;/code>. Complicated &lt;code>catch&lt;/code> blocks are usually not worth extracting (though there are exceptions), so instead look for ways to extract the useful bits away from them.&lt;/p>
&lt;h2 id="fixing-misleading-names">Fixing Misleading Names&lt;/h2>
&lt;p>Another common challenge to reading code is when the name is indicates something different than what it does. When a concept is not being represented accurately by the name, we say its name is &lt;em>misleading&lt;/em>.&lt;/p>
&lt;h3 id="part-1-look-at-names-that-you-are-using">Part 1: Look at Names that you are using&lt;/h3>
&lt;p>Focus on whatever names you encounter in the code you are reading.&lt;/p>
&lt;h3 id="part-2-look-for-under-information-or-misinformation">Part 2: Look for under-information or misinformation&lt;/h3>
&lt;p>I look around for partial lies. Examples include:&lt;/p>
&lt;ul>
&lt;li>A method named by when it is called in a lifecycle (PageLoad, PreInit).&lt;/li>
&lt;li>A variable named the same as its type (GridSquare gridsquare).&lt;/li>
&lt;li>Method name that leaves out critical information (method named composeName that also writes that name to the database).&lt;/li>
&lt;li>Any name that ends in -er or -Utils (DocumentManager, CalculationUtils).&lt;/li>
&lt;/ul>
&lt;h3 id="part-3-write-down-by-renaming-it-to-applesauce">Part 3: Write down by renaming it to &lt;code>Applesauce&lt;/code>&lt;/h3>
&lt;p>Don’t bother trying to figure out what it does or a good name for it. Just call it &lt;code>Applesauce&lt;/code> and move on with your coding. We have the social norm that should always be good; however, if the name is misleading, even if it looks good, is &lt;strong>not&lt;/strong> good. Misleading names will cause someone to write bugs.&lt;/p>
&lt;h2 id="check-it-in">Check it in!&lt;/h2>
&lt;p>I used to consider whether to check in at this point. It feels so small, and &lt;code>Applesauce&lt;/code> feels like such a terrible name!&lt;/p>
&lt;p>After 4 more years of practicing this, however, I no longer consider. I &lt;strong>always&lt;/strong> check in.&lt;/p>
&lt;p>Both of these changes make the code better. Not a lot better, but better. They are fast, easy, safe, and don’t make anything worse. By checking them in I immediately get back to a clean slate and am ready for whatever comes next.&lt;/p>
&lt;p>Replacing a missing name tends to result in more insights about the code, so it is likely that both this commit and the next will be large. I want to split this up from that. Replacing a misleading name will almost always prevent one future bug. It is worth checking that in immediately so that there is no chance a failure at my next task will roll this back. Either way, check in now.&lt;/p>
&lt;h2 id="adopt-now">Adopt Now&lt;/h2>
&lt;p>Help your team adopt Naming as a Process now!&lt;/p>
&lt;p>&lt;a href="https://learn.digdeeproots.com/habit/naming-as-a-process/">See How it Works&lt;/a>&lt;/p>
&lt;h2 id="read-more">Read More&lt;/h2>
&lt;p>Next up: make our fresh Obvious Nonsense name &lt;a href="https://www.digdeeproots.com/articles/naming-is-a-process-nonsense-to-honest/">become Honest&lt;/a>.&lt;/p>
&lt;p>Or read the whole &lt;a href="https://www.digdeeproots.com/articles/on/naming-as-a-process/">Naming as a Process blog series&lt;/a>.&lt;/p></description></item><item><title>Articles: Get to Honest (Article 3)</title><link>/articles/naming-process/get-to-honest/</link><pubDate>Tue, 15 Oct 2019 00:00:00 +0000</pubDate><guid>/articles/naming-process/get-to-honest/</guid><description>
&lt;p>We have a thing with a name. But its name is obvious nonsense. &lt;/p>
&lt;p>One of my more gnarly experiences was when I worked within a system that spoke to the FAA’s system. This particular method was named &lt;code>PreLoad()&lt;/code>, telling me when the system calls the method (not very useful). The problem is that there is a missing name. Nothing tells me what would happen on &lt;code>PreLoad()&lt;/code>. &lt;/p>
&lt;p>Based on &lt;a href="https://www.digdeeproots.com/articles/naming-as-a-process-missing-to-nonsense/">Article 2&lt;/a>, I then extracted the entire body of &lt;code>PreLoad()&lt;/code> and called it &lt;code>Applesauce()&lt;/code>. At that point, the code explicitly says that upon &lt;code>PreLoad()&lt;/code>, do &lt;code>Applesauce()&lt;/code>.&lt;/p>
&lt;p>Now we want to make &lt;code>Applesauce()&lt;/code> honest.&lt;/p>
&lt;h2 id="making-the-name-honest">Making the Name Honest&lt;/h2>
&lt;p>I want to make the name honest. It doesn&amp;rsquo;t need to be completely honest. It just needs to tell me one honest thing. I look at the method to figure out one thing that appears to be key to its execution. I just read through the body and see what appears central.&lt;/p>
&lt;h3 id="part-1-look-inside-the-body">Part 1: Look inside the body&lt;/h3>
&lt;p>Focus on inside the body. Look for patterns that repeat here or between this and other methods.&lt;/p>
&lt;p>I find it useful to look for variables that are system components (&amp;ldquo;database,&amp;rdquo; &amp;ldquo;screen,&amp;rdquo; &amp;ldquo;network,&amp;rdquo; &amp;ldquo;service&amp;rdquo;), look where the return value comes from, and see if something is used many times.&lt;/p>
&lt;h3 id="part-2-look-for-one-thing-the-code-does">Part 2: Look for one thing the code does&lt;/h3>
&lt;p>As you look for simply &lt;strong>one&lt;/strong> thing that the code inside the body does, consider also the judgment of how easy it will be to work with, how safe it is, or other useful traits.&lt;/p>
&lt;p>In the example, I noticed that there was a global named db that was used a lot. Several places created recordset objects, set values, and read or wrote them using the db. Since it mixed reads and writes, I named the method &lt;code>probably_doSomethingEvilToTheDatabase_AndStuff()&lt;/code>.&lt;/p>
&lt;p>As a name, &lt;code>doSomethingEvilToTheDatabase()&lt;/code> is “interesting” enough. Why would I also write &lt;code>probably_&lt;/code> and &lt;code>_AndStuff&lt;/code>? I wasn’t certain what the method does, but I had found one thing, and frankly, wasn’t 100% on that one. The &lt;code>probably_&lt;/code> informed my team that I wasn’t certain that it does the one thing I was saying it does. The &lt;code>_AndStuff&lt;/code> informed my team that this name needs more iteration. It’s honest, but not complete.&lt;/p>
&lt;p>Meanwhile, it &lt;strong>is&lt;/strong> honest in several ways, recording several insights that I had.&lt;/p>
&lt;ol>
&lt;li>The main effect of the method seems to involve the database.&lt;/li>
&lt;li>I don&amp;rsquo;t yet understand what it is doing to the database.&lt;/li>
&lt;li>I am getting all judgy about how it is treating the poor database. I don&amp;rsquo;t like it.&lt;/li>
&lt;li>It does more things that I don’t understand at all.&lt;/li>
&lt;/ol>
&lt;p>The last three insights are as important as the first. Even if I wandered away at this point, a future reader of the code would have some insight. They wouldn&amp;rsquo;t know what the method did, but they&amp;rsquo;d be properly wary of it.&lt;/p>
&lt;p>They&amp;rsquo;d know that no one knows exactly what it does, it does that thing to the central database, and the last person to touch it thought it was doing some nasty stuff. Good! I&amp;rsquo;ve transmitted all the knowledge that I have about this method. I&amp;rsquo;ve put them in the proper frame of mind for working with it.&lt;/p>
&lt;h3 id="part-3-write-down-by-renaming-to-a-better-name">Part 3: Write down by renaming to a better name&lt;/h3>
&lt;p>The components necessary for this better name includes two things:&lt;/p>
&lt;ul>
&lt;li>One honest thing it does; and &lt;/li>
&lt;li>Clarity about what we don&amp;rsquo;t know yet.&lt;/li>
&lt;/ul>
&lt;p>The way you perform the renaming is important. Don’t just edit the name; use a rename refactoring. When we edit the name we have a chance of accidentally changing behavior in some way, but when you use a rename refactoring, you ensure safety. &lt;/p>
&lt;h2 id="be-specific">Be specific!&lt;/h2>
&lt;p>The most common way to screw up at this point is to be too general in your name. Being specific is good!&lt;/p>
&lt;p>The intent of naming in this way is to allow a reader to understand a chunk of code without looking at it, just by looking at the name for that chunk of code. That reader needs specific detailed knowledge. So the name has to be specific.&lt;/p>
&lt;p>For example, I could have named my function &lt;code>handleFlightInfoSomehow()&lt;/code>. That would have been honest, but it hides the potential risky thing done to a very important part of the system. Thus &lt;code>doSomethingEvilToTheDatabase&lt;/code> is more specific as to the risk.&lt;/p>
&lt;p>Looking ahead just a bit, the next step will be to make the name convey everything the code is doing (be Honest and Complete). If we are specific, then the only route to completeness is to add to the name. I keep the same precision but add more description.&lt;/p>
&lt;p>If I am overly general or imprecise now, then it most or all of the things the function does will be already roughly describable by the name. This will make it a lot harder for me to see the things that aren&amp;rsquo;t yet conveyed in the name, which will make it harder to create a name that fully describes the code behind it.&lt;/p>
&lt;h2 id="not-just-for-functions-or-nonsense-names">Not just for functions or nonsense names&lt;/h2>
&lt;p>This step applies when naming classes or variables as well as bad names that are not yet obvious nonsense. Common bad names for classes are anything that ends in -&lt;code>Manager&lt;/code> or -&lt;code>Operations&lt;/code>. Poorly named variables are usually named the same thing as their type.&lt;/p>
&lt;p>In either case, we need to have one insight into this thing. What is one important responsibility of the class? For a variable, what differentiates this one &lt;code>Foo&lt;/code> instance from all the other &lt;code>Foo&lt;/code> instances that might be out there? How does the code using the variable think of this one? Whatever that insight is, write it down.&lt;/p>
&lt;h2 id="adopt-now">Adopt Now&lt;/h2>
&lt;p>Help your team adopt Naming as a Process now!&lt;/p>
&lt;p>&lt;a href="https://learn.digdeeproots.com/habit/naming-as-a-process/">See How it Works&lt;/a>&lt;/p>
&lt;h2 id="read-more">Read More&lt;/h2>
&lt;p>Next up: make how our basically honest names &lt;a href="https://www.digdeeproots.com/articles/naming-is-a-process-honest-to-completely-honest/">become completely honest&lt;/a>.&lt;/p>
&lt;p>Or read the whole &lt;a href="https://www.digdeeproots.com/articles/on/naming-as-a-process/">Naming as a Process blog series&lt;/a>.&lt;/p></description></item><item><title>Articles: Get to Completely Honest (Article 4)</title><link>/articles/naming-process/get-to-completely-honest/</link><pubDate>Mon, 14 Oct 2019 00:00:00 +0000</pubDate><guid>/articles/naming-process/get-to-completely-honest/</guid><description>
&lt;p>I need to make my name fully describe everything this method does. Each level of improved naming should record more insights and make it easier for the next person to read the code.&lt;/p>
&lt;p>This level actually makes it unnecessary for the next person to read the code. We want them to be able to trust that the name includes absolutely everything the method does so they can read and understand calling methods without having to read the method we&amp;rsquo;re fixing.&lt;/p>
&lt;p>In the previous articles of this blog series, everything being done was accomplished in one step. However, being completely honest is hard so we need to take it in steps.&lt;/p>
&lt;p>Each time you iterate on an honest name by making it more honest, you’ve made it easier on the next coder. A name might progress through this phase over the course of weeks or months. Eventually, though, the name will have become completely honest.&lt;/p>
&lt;p>To complete “one more iteration” of the name becoming more honest, we look through the body of the method and find one of two things:&lt;/p>
&lt;ul>
&lt;li>Expand the Known: find one &lt;strong>more&lt;/strong> thing that it does. Add it to the name.&lt;/li>
&lt;li>Narrow the Unknown: find one specific thing that we &lt;strong>don’t&lt;/strong> know. Add it to the _AndStuff part of the name.&lt;/li>
&lt;/ul>
&lt;h2 id="expand-the-known">Expand the Known&lt;/h2>
&lt;p>The first option in your iteration of making the name more honest is simply finding one &lt;strong>more&lt;/strong> thing that it does, which is explained in these three parts.&lt;/p>
&lt;h3 id="part-1-look-inside-the-body">Part 1: Look inside the body &lt;/h3>
&lt;p>You know this by now. It is often useful to look for paragraphs or control structures.&lt;/p>
&lt;h3 id="part-2-look-for-one-thing-the-code-does-that-isnt-in-the-name">Part 2: Look for one thing the code does that isn’t in the name&lt;/h3>
&lt;p>The process is:&lt;/p>
&lt;ol>
&lt;li>Find one thing that the code does (an effect, a calculation, a result, a state change).&lt;/li>
&lt;li>See if that is already included in the name (it might be a legitimate substep of something that is already in there).&lt;/li>
&lt;li>If not, add it (see Part 3).&lt;/li>
&lt;/ol>
&lt;p>Don&amp;rsquo;t broaden the parts of the name. Your goal is not to find one abstraction that includes everything the method does. Your goal is to be precise; a reader should be able to read the method name and know &lt;em>exactly&lt;/em> what the method does.&lt;/p>
&lt;h3 id="part-3-write-down-by-adding-a-clause-to-the-name">Part 3: Write down by adding a clause to the name&lt;/h3>
&lt;p>Ignore everything you&amp;rsquo;ve been taught about naming conventions. Long names are good. Conjunctions are good. Belaboring the point is good. Your only goal is to make sure that everything this thing does is represented in the name. And therefore anyone can trust the name. They no longer have to read the thing, just its name.&lt;/p>
&lt;p>Imagine emailing the method name to someone. Just the name. Would they be able to generate exactly all of the things in the method body? They shouldn&amp;rsquo;t want to add any more things and they shouldn&amp;rsquo;t miss any. &lt;/p>
&lt;p>The purpose of the second section (middle) of the name is to simply record what &lt;strong>is&lt;/strong> known. Recall from previous articles that probably_ flags the team that there is uncertainty. _AndStuff records what is &lt;strong>not&lt;/strong> known, while the center lists everything that &lt;strong>is&lt;/strong> known. So add your new clause to the middle section.&lt;/p>
&lt;h2 id="narrow-the-unknown">Narrow the Unknown&lt;/h2>
&lt;p>The second option in your iteration of making the name more honest is finding one specific thing that we &lt;strong>don’t&lt;/strong> know, which is explained in these three parts.&lt;/p>
&lt;h3 id="part-1-look-inside-the-body-or-at-the-name">Part 1: Look inside the body or at the name&lt;/h3>
&lt;p>If you’re looking inside the body, focus on data or parameters you haven’t analyzed yet. This will help you add a clause to the set of unknowns. &lt;/p>
&lt;p>Another strategy to consider is to:&lt;/p>
&lt;ol>
&lt;li>Look at the name of the method,&lt;/li>
&lt;li>Pick one of the clauses of unknowns that you want to narrow, and&lt;/li>
&lt;li>Look at the parts of the method body that are related to that clause. &lt;/li>
&lt;/ol>
&lt;h3 id="part-2-look-for-one-category-of-things-that-the-code-doesnt-do">Part 2: Look for one category of things that the code doesn’t do&lt;/h3>
&lt;p>As the title suggests, you are looking for a category of things that the code &lt;strong>doesn’t&lt;/strong> do, but also look for one &lt;em>partial truth&lt;/em> for something the code does do. Let’s look at some examples. &lt;/p>
&lt;p>&lt;strong>Something that it doesn’t do&lt;/strong>Assume that I have a name _AndDoSomethingWithGraphicsContextAndStuff(). I realize that the method doesn’t write to the GC or use it to draw anything; it is read-only. I might name it to _AndDoSomethingReadOnlyToGraphicsContextAndStuff(). I don’t know what it does, but I’ve reduced the unknown.&lt;/p>
&lt;p>&lt;strong>A partial truth about what it does do&lt;/strong>&lt;br>
Assume my name includes _AndDoSomethingToDatabaseAndStuff(). I discover the code opens a write cursor and no reads, and rename to _AndWriteSomethingToDatabaseAndStuff(). I don’t yet know what is written, but I’ve exposed a partial truth and reduced the unknown.&lt;/p>
&lt;p>The process is:&lt;/p>
&lt;ol>
&lt;li>Identify one piece of data related to what you’re looking for (that may be a variable, parameter, or field).&lt;/li>
&lt;li>Trace that data’s usage through the method to find one thing that is either done or not done with it.&lt;/li>
&lt;li>Update the name accordingly (see Part 3).&lt;/li>
&lt;/ol>
&lt;h3 id="part-3-write-down-by-adding-a-clause-to-the-name-1">Part 3: Write down by adding a clause to the name&lt;/h3>
&lt;p>The purpose of the _AndStuff section of the name is to record and quantify the unknown behaviors of this method. That is why we start simply with _AndStuff. However, now that you are moving from an Honest Name to Completely Honest, we can provide more precision than _AndStuff. So now you are going to record the more precise information you have by adding a clause to _AndStuff.&lt;/p>
&lt;h2 id="finishing-the-iteration-towards-completely-honest">Finishing the iteration towards Completely Honest&lt;/h2>
&lt;p>A Completely Honest name will include only the middle section.&lt;/p>
&lt;p>To get rid of the third section, we have to eliminate the last unknowns. We will need the object to be so readable that we know for a fact it doesn’t do anything beyond what we’ve said. It is usually easiest to identify all the impacted data and generate specific clauses in the third section. Once we’ve traced all the data, we know there can be no other impacts, so we can remove the general AndStuff(). Then we simply have to chase down every unknown clause one at a time until the third section is gone.&lt;/p>
&lt;p>To get rid of the first section we have to be totally confident in the rest of the name. The probably_ indicates that we are not yet sure. To become totally confident we will need two things. First, we will need tests that verify the method does everything we say it does in the middle section. Second, we will need the object to be so readable that we know for a fact all unknowns are scoped by the third section. Once both are true, we can eliminate the probably_. However, later editors then need to either be justifiably confident in their naming steps or re-add the probably_. For this reason, removing the probably_ is often the last step.&lt;/p>
&lt;h2 id="really-big-methods">Really big methods&lt;/h2>
&lt;p>Sometimes understanding a subcomponent requires extracting it and getting it to have a better name. This is especially common with long methods. When you do this, keep your focus on the main name. Extract a chunk and record insights only until you know whether or not it is important for naming your main thing. Then update the main name and move on.&lt;/p>
&lt;p>Guard clauses are a good example. They&amp;rsquo;re usually easy to identify but take up a bunch of space. I won&amp;rsquo;t actually use them in the name of the thing (most of the time), but they can make it hard to read the rest.&lt;/p>
&lt;p>I&amp;rsquo;ll extract a bunch of what I think are guard clauses, get the name for the extracted component to be Honest, and see if they actually are all guard clauses. If so then I leave them alone and come back to the main method.&lt;/p>
&lt;p>I&amp;rsquo;ll extract guard clauses until I&amp;rsquo;m left with the residual. Then I&amp;rsquo;ll analyze that more deeply and make sure I get everything into the name of my main method. I might inline the guard clauses again when I am done, or just leave them named something like _ValidateAllInputs().&lt;/p>
&lt;p>In the example from the FAA issue I shared in &lt;a href="https://www.digdeeproots.com/articles/naming-is-a-process-nonsense-to-honest/">Article 3&lt;/a>, I needed to take several steps to find all the things my method was doing. I eventually identified 4 main chunks of functionality, each of which happened in many steps. So my method became parseXmlAndStoreFlightToDatabaseAndLocalCacheAndAddToScreenIfVisible().&lt;/p>
&lt;h2 id="things-that-arent-methods">Things that aren&amp;rsquo;t methods&lt;/h2>
&lt;p>This step also applies to variable and class names.&lt;/p>
&lt;ul>
&lt;li>Classes should be named by all of their individual responsibilities.&lt;/li>
&lt;li>Variable names should include all the ways the variable is used.&lt;/li>
&lt;/ul>
&lt;p>In deep legacy code variables may be used in a surprising number of ways. An example is once when I had a poor, overused in/out parameter that I had to name searchHintThenBestMatchSoFarUntilItBecomesReturnValueOrReasonNoMatchWasFound.&lt;/p>
&lt;p>There is a strong design rule that says classes should have a single responsibility. That’s true. However, in this step we are ignoring what “should” be true and trying to simply be completely honest about what is true right now. Classes often have a primary responsibility while also including a couple of other responsibilities that mostly make sense and are too small to break out. That being said, this naming stage is simply being completely honest about &lt;strong>all&lt;/strong> of those responsibilities. We will decide what to do about the multiple responsibilities in the next step.&lt;/p>
&lt;h2 id="naming-by-what-it-does-not-by-what-it-is">Naming by what it does, not by what it is&lt;/h2>
&lt;p>Here the insights that I&amp;rsquo;m having are all the important characteristics of the thing I am naming. I&amp;rsquo;m naming it by what it &lt;em>does&lt;/em>, not by what it &lt;em>is&lt;/em>. This shift is a critical step in eliminating god classes and long methods.&lt;/p>
&lt;p>**Named by what it is…**When a thing is named by what it is, then it accumulates everything vaguely related to that identity. Use this when you want other coders to naturally gather related pieces of functionality from other code and increase cohesion.&lt;/p>
&lt;p>**Named by what it does…**When it is named by every single thing it does, then our desire for shorter names drives us to have it do less stuff. Use this when you want other coders to break it apart and simplify each chunk.&lt;/p>
&lt;blockquote>
&lt;p>How something is named will drive the behavior of how people will engage with it and the future evolution of the method, variable, or class.&lt;/p>
&lt;p>Me.&lt;/p>
&lt;/blockquote>
&lt;h2 id="adopt-now">Adopt Now&lt;/h2>
&lt;p>Help your team adopt Naming as a Process now!&lt;/p>
&lt;p>&lt;a href="https://learn.digdeeproots.com/habit/naming-as-a-process/">See How it Works&lt;/a>&lt;/p>
&lt;h2 id="read-more">Read More&lt;/h2>
&lt;p>Next up: use your completely honest name to &lt;a href="https://www.digdeeproots.com/articles/naming-is-a-process-completely-honest-to-does-the-right-thing/">guide the code to do what it should do&lt;/a>.&lt;/p>
&lt;p>Or read the whole &lt;a href="https://www.digdeeproots.com/articles/on/naming-as-a-process/">Naming as a Process blog series&lt;/a>.&lt;/p></description></item><item><title>Articles: Get to Does the Right Thing (Article 5)</title><link>/articles/naming-process/get-to-does-the-right-thing/</link><pubDate>Sun, 13 Oct 2019 00:00:00 +0000</pubDate><guid>/articles/naming-process/get-to-does-the-right-thing/</guid><description>
&lt;p>Congratulations on having a completely honest name! It is a huge step to simply represent exactly what the code does. All of the steps until now collected information into the name. In making the name complete, we have now made it possible to reason over the responsibilities of the class/method/variable without having to read its full implementation. This sets us up to change its responsibilities, so now we’re going to use the name to guide chunking the code.&lt;/p>
&lt;h3 id="part-1-look-only-at-the-name">Part 1: Look only at the name&lt;/h3>
&lt;p>At this step, I look only at the name. I ignore both its usage sites and its body. The only question to ask is “does this name make sense?”&lt;/p>
&lt;h3 id="part-2-look-for-one-responsibility-to-separate">Part 2: Look for one responsibility to separate&lt;/h3>
&lt;p>The easiest way to find a responsibility to separate is to look for a name clause we want to eliminate. There are typically two kinds of clauses we want to eliminate. Each is found by one key question:&lt;/p>
&lt;ul>
&lt;li>Is this clause unrelated to other clauses in the name?&lt;/li>
&lt;li>Is this clause a concern we want to encapsulate?&lt;/li>
&lt;/ul>
&lt;h3 id="part-3-write-down-by-structurally-refactoring">Part 3: Write down by structurally refactoring&lt;/h3>
&lt;p>Writing it down requires structural refactoring by extracting or encapsulating one behavior of the thing. We need to keep the name completely honest. If we don&amp;rsquo;t like the name then we have to change what the thing does so that we can use a different name.&lt;/p>
&lt;h2 id="can-we-get-more-specific-than-structural-refactoring">Can we get more specific than “structural refactoring???”&lt;/h2>
&lt;p>There are hundreds of different code patterns and destination patterns that each call for a different refactoring. Code by Refactoring is my attempt to gather those context-specific practices into an overall technique that implements Naming as a Process described in this blog series as well as several other key legacy coding ideas. While handling every possible structural change requires all of Code by Refactoring, the patterns common in your specific codebase require only some of the shifts.&lt;/p>
&lt;p>Two especially common goals are 1) safely moving a responsibility from a method and 2) encapsulation. Code by Refactoring resolves these two goals in the &lt;a href="https://www.digdeeproots.com/legacy/fix-complex-methods/">Fix Complex Methods Changes Series&lt;/a>. This particular series of habits help you refactor a complex method into a new system with identical behavior, but in a tidy readable way.&lt;/p>
&lt;p>Once the habits have been learned within &lt;a href="https://www.digdeeproots.com/legacy/fix-complex-methods/">Fix Complex Methods&lt;/a>, a developer might respond to a particular instance with an approach like these.&lt;/p>
&lt;h3 id="safely-moving-a-responsibility-from-a-method">Safely moving a responsibility from a method&lt;/h3>
&lt;p>The most common cause is that my method does too many things. I want to split the responsibilities and update all the callers to use them separately. The challenge is flowing the data between the methods without creating a mess elsewhere.&lt;/p>
&lt;p>An example is the handling of the XML and the database in &lt;code>parseXmlAndStoreFlightToDatabaseAndLocalCacheAndShowOnScreenIfVisible()&lt;/code>. I&amp;rsquo;d like to split that into 2 parts: one that turns XML into a flight, and one that operates on a flight.&lt;/p>
&lt;p>The solution is to find a series of refactorings that split methods and cluster their data as we go. This might entail moving methods between classes, transforming methods to take data via parameters instead of using fields, or introducing new classes. Fortunately, the impacts tend to be localized to just the method we are working on and all of its direct callers, which is easily handled as long as we have a good technique for Inline Method.&lt;/p>
&lt;p>Here is a common case, used when we start with a simple static method.&lt;/p>
&lt;ol>
&lt;li>Extract method all the stuff after the part &amp;lsquo;../../post/get-to-does-the-right-thing&amp;rsquo;I want to break out.&lt;/li>
&lt;li>Introduce a parameter object for everything going into the new method.&lt;/li>
&lt;li>Extract method the part &amp;lsquo;../../post/get-to-does-the-right-thing&amp;rsquo;I want to break out. Have it return the new parameter object.&lt;/li>
&lt;li>Introduce a parameter object for this new method.&lt;/li>
&lt;li>Extract method all the stuff before the part &amp;lsquo;../../post/get-to-does-the-right-thing&amp;rsquo;I want to break out. Have it return the new parameter object.&lt;/li>
&lt;li>Split the name of the outer method up into names for the 3 parts based on what does what chunks.&lt;/li>
&lt;li>Add any missing clauses required to make the names complete. For example, the above split may divide a calculation from the part &amp;lsquo;../../post/get-to-does-the-right-thing&amp;rsquo;that writes it somewhere. The outer method may just be named &lt;code>...AndRecordYield...()&lt;/code>. So I now have one inner part &amp;lsquo;../../post/get-to-does-the-right-thing&amp;rsquo;named &lt;code>...AndCalculateYield...()&lt;/code> and another named &lt;code>...AndRecordYieldToService()&lt;/code>. The methods are smaller so it becomes more obvious how to be specific in their names.&lt;/li>
&lt;li>Inline Method the outer method. Now all call sites use the 3 methods directly and you have split out the functionality.&lt;/li>
&lt;/ol>
&lt;h3 id="encapsulation">Encapsulation&lt;/h3>
&lt;p>Another common case is to want to encapsulate something. This usually entails not just removing a clause from the name, but actually encapsulating the behavior so callers can&amp;rsquo;t see the effect. The usual problem is that the behavior is performed on one of the parameters.&lt;/p>
&lt;p>An example is the handling of the local cache in &lt;code>parseXmlAndStoreFlightToDatabaseAndLocalCacheAndShowOnScreenIfVisible()&lt;/code>. I&amp;rsquo;d like to encapsulate that cache and use it as a read-through cache just for performance.&lt;/p>
&lt;p>The solution is to find some sequence of refactorings to shift that parameter to be a field. Sometimes this involves creating a new class, splitting a class, or moving the method we are working with to a different class. It also usually involves changing object lifetime and removing references to the value from all callers of the method, often several layers up the stack.&lt;/p>
&lt;p>The easiest way to do this is typically to refactor until the method uses everything via a field instead of a parameter, then use the auto-fix to remove unused parameter, then go up the call-stacks and continue removing unused parameter as far as you can.&lt;/p>
&lt;p>Here is one common sequence, used when we start with a static method.&lt;/p>
&lt;ol>
&lt;li>Use Introduce Parameter Object. Select just the one parameter you want to encapsulate. Name the class &lt;code>Applesauce&lt;/code> and the parameter self.&lt;/li>
&lt;li>Use Convert To Instance Method on the static. Select the parameter you just introduced.&lt;/li>
&lt;li>Improve the class name (&lt;code>Applesauce&lt;/code>) to at least the Honest level.&lt;/li>
&lt;li>Go to the caller of the method. Select the creation of the new type. Introduce parameter to push it up to the caller&amp;rsquo;s caller.&lt;/li>
&lt;li>Convert any other uses of the parameter you are encapsulating to use the field off the new class.&lt;/li>
&lt;li>When the last usage is gone, use the Autofix for remove unused parameter to remove the now-encapsulated field.&lt;/li>
&lt;li>Select any usage of the public field in the calling method and Extract Method the related statements / expression.&lt;/li>
&lt;li>Convert to Static on the extracted method, then Convert to Instance Method to move it to the new type.&lt;/li>
&lt;li>Repeat 7 &amp;amp; 8 until the calling method no longer uses the field we are encapsulating.&lt;/li>
&lt;li>Walk up the stack to the caller of this method. Repeat from step 4. Stop when you get to the initial fetch / creation of the value you are encapsulating.&lt;/li>
&lt;li>Move that fetch / creation to be a factory method on the new type (via Extract, Make Static, Convert to Instance).&lt;/li>
&lt;li>Repeat from step 4 for any other callers of your original method.&lt;/li>
&lt;li>At this point the only references to the value you are encapsulating will be within your new class. The only users of the constructor that takes that value will be factory methods / other constructors.&lt;/li>
&lt;li>Convert the constructor to private.&lt;/li>
&lt;li>Inline the public property to access the value you are encapsulating. Now all the class methods will just use the field.&lt;/li>
&lt;/ol>
&lt;p>The recipe is long, but each step takes 1-2 seconds with proper tooling. No step requires editing code. You can encapsulate even a highly-used value in 2-10 minutes with practice.&lt;/p>
&lt;p>You can also encapsulate multiple related values at once. And a variation can be used when you want to split a class or handle similar cases.&lt;/p>
&lt;h2 id="breaking-up-god-classes">Breaking up God Classes&lt;/h2>
&lt;p>On the surface, breaking up a God Class appears to mean executing the Split Class refactoring many times. In practice, however, it’s a lot more complicated than that. God Classes are problematic not only for the methods of the class but also cause a number of common antipatterns in all the code around them. These two problem areas - the class and the surrounding methods - tend to reinforce each other. It is very difficult to fix either while the other remains broken.&lt;/p>
&lt;p>Here are some of the common problems:&lt;/p>
&lt;ol>
&lt;li>The God Class attracts related data. This steals data from surrounding methods, creating utility classes and primitive obsession.&lt;/li>
&lt;li>The God class becomes the obvious place for responsibilities related to its data. This makes it hard to see and start other classes, so the surrounding code becomes unclustered.&lt;/li>
&lt;li>The God Class becomes a point of coupling between unrelated parts of the system. They start to account for this coupling with special case logic making it difficult to separate them.&lt;/li>
&lt;li>Different responsibilities on the God Class share fields, making it hard to pull them apart.&lt;/li>
&lt;li>Data gets passed off the God Class via primitive parameters, creating data aliasing issues, some of which are intentional and must be maintained.&lt;/li>
&lt;/ol>
&lt;p>That’s why people end up rewriting their God Classes away.&lt;/p>
&lt;p>The largest Change Series in Code by Refactoring, &lt;a href="https://www.digdeeproots.com/legacy/fix-god-classes/">Fix God Classes&lt;/a>, provides an incremental approach. This can be combined with the Fix Utility Classes Change Series if your codebase has both antipatterns snarled together. The techniques from these Change Series will address the above 4 problems plus several more.&lt;/p>
&lt;h2 id="adopt-now">Adopt Now&lt;/h2>
&lt;p>Help your team adopt Naming as a Process now!&lt;/p>
&lt;p>&lt;a href="https://learn.digdeeproots.com/habit/naming-as-a-process/">See How it Works&lt;/a>&lt;/p>
&lt;h2 id="read-more">Read More&lt;/h2>
&lt;p>Next up: &lt;a href="https://www.digdeeproots.com/articles/naming-is-a-process-does-the-right-thing-to-intent/">reveal the intent&lt;/a> of each chunk.&lt;/p>
&lt;p>Or read the whole &lt;a href="https://www.digdeeproots.com/articles/on/naming-as-a-process/">Naming as a Process blog series&lt;/a>.&lt;/p></description></item><item><title>Articles: Get to Intent Revealing (Article 6)</title><link>/articles/naming-process/get-to-intent-revealing/</link><pubDate>Sat, 12 Oct 2019 00:00:00 +0000</pubDate><guid>/articles/naming-process/get-to-intent-revealing/</guid><description>
&lt;p>Every improvement in our name until now has focused on what our class/method/variable does. We made it honest and then we made it do exactly what we want. The name is both correct and clear.&lt;/p>
&lt;p>But it is awkward.&lt;/p>
&lt;p>We want to use this name to understand calling methods. It doesn&amp;rsquo;t yet serve that purpose. The name describes the thing. It doesn&amp;rsquo;t tell us why we care.&lt;/p>
&lt;p>That makes us stumble when reading the caller. We want the names to tell us the purpose of each subcomponent. But right now the name tells us what it does—implementation when we want behavior/intent.&lt;/p>
&lt;p>Every time we read a caller, we have to consider whether that implementation will give us our desired intent. That takes mental energy we could better spend elsewhere.&lt;/p>
&lt;h3 id="part-1-look-at-the-calling-methods--use-sites">Part 1: Look at the calling methods / use sites&lt;/h3>
&lt;p>We&amp;rsquo;ve gotten as far as we can looking at our target to gain insights. Now we need to include the insights from its context.&lt;/p>
&lt;p>Read through all the places where this thing is used. Understand it in the flow of other classes and method calls. What happens before, after, or with it?&lt;/p>
&lt;p>Most likely the other names around this one will suck too. You need to improve them before you gain any insight. Sometimes insight will happen if the other parts are Honest, but you probably need to get to at least Completely Honest.&lt;/p>
&lt;p>When you see all the context items at the Completely Honest level, you may realize that your target actually doesn&amp;rsquo;t Do the Right Thing. This is rare but it does happen. Fix it.&lt;/p>
&lt;h3 id="part-2-look-for-the-codes-purpose">Part 2: Look for the code&amp;rsquo;s purpose&lt;/h3>
&lt;p>As you start to examine the use contexts you will start to see a flow. The target is one step in a larger orchestration. It has a purpose. That purpose is usually at a higher level of abstraction.&lt;/p>
&lt;p>Rename the thing to state this purpose. Some common purposes are:&lt;/p>
&lt;p>&lt;strong>Methods:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>What it accomplishes (post-condition), regardless of starting state or process.&lt;/li>
&lt;li>Transformation it makes, regardless of beginning or ending states.&lt;/li>
&lt;li>Business process it replaces.&lt;/li>
&lt;li>Core responsibility the method takes on.&lt;/li>
&lt;li>What the method promises to allow callers to safely ignore.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Classes:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>The common responsibility of its methods.&lt;/li>
&lt;li>What the class is in the real world (Whole Value).&lt;/li>
&lt;li>The responsibility that calling context is delegating to the class and assuming the class will take care of. What the caller wants to ignore.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Variables:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>How this instance differs from other instances of the same type.&lt;/li>
&lt;li>The purpose the context has for this instance. How it is used.&lt;/li>
&lt;/ul>
&lt;h3 id="part-3-write-down-the-purpose-by-renaming-the-target">Part 3: Write down the purpose by renaming the target&lt;/h3>
&lt;p>In our running example, &lt;code>storeFlightToDatabaseAndShowOnScreenIfVisible(flight)&lt;/code> becomes &lt;code>beginTrackingFlight(flight)&lt;/code>. The first name tells us what our method does. The second tells us why we care.&lt;/p>
&lt;p>We don&amp;rsquo;t need to know what tracking a flight entails. We just need to know that this method will take care of initiating that process for us.&lt;/p>
&lt;p>We would expect to see a &lt;code>stopTrackingFlight(flight)&lt;/code> nearby. And perhaps some query methods to find information about flights that are being tracked.&lt;/p>
&lt;h2 id="play-it-again">Play it again&lt;/h2>
&lt;p>Now repeat this step for another calling context. Your insight may be the same or your insightful name might be jarring in the other context. Often multiple callers are using the same code because of what it happens to do, not because of its purpose.&lt;/p>
&lt;p>When this happens, create two methods that share an implementation. To the outside world, they are different things because they express different intent. It just happens that to a computer they do the same thing…for now.&lt;/p>
&lt;h2 id="refactoring-methods-to-share-implementation">Refactoring methods to share implementation&lt;/h2>
&lt;p>Do the following:&lt;/p>
&lt;ol>
&lt;li>Extract method the entire body of the method.&lt;/li>
&lt;li>Rename the extracted (inner) method to the name you had that Does the Right Thing (which you can see in source history).&lt;/li>
&lt;li>Duplicate the outer method and edit its name to unique nonsense (do not refactor; you don&amp;rsquo;t want to update callers).&lt;/li>
&lt;li>Rename the unique nonsense to the new purpose.&lt;/li>
&lt;li>Edit the call site to use the method with the new purpose.&lt;/li>
&lt;/ol>
&lt;p>The reason we hand-edit to nonsense and then rename is so that our tool can catch errors. Hand-editing code is dangerous and something I tend to avoid.&lt;/p>
&lt;p>I could duplicate a name or create aliasing problems, especially in the presence of inheritance or global functions with imported namespaces. But these are all problems that the rename refactoring checks for. By hand-editing to unique nonsense, I reduce the chance of making a mistake. And then renaming to the final name ensures that I don&amp;rsquo;t introduce one at that point.&lt;/p>
&lt;h2 id="refactoring-classes-to-share-implementation">Refactoring classes to share implementation&lt;/h2>
&lt;p>For a class, the recipe depends on how your IDE does Split Class.&lt;/p>
&lt;h3 id="the-easy-way-use-tools">The easy way: use tools&lt;/h3>
&lt;p>If Split Class supports delegation:&lt;/p>
&lt;ol>
&lt;li>Split Class and select everything. Choose the option to have all callers use the old type and create delegating members.&lt;/li>
&lt;li>Rename the inner type to the name you had after Doing the Right Thing.&lt;/li>
&lt;li>Copy the file for the outer type (assuming class-per-file).&lt;/li>
&lt;li>Hand-change the class name &amp;amp; constructors in the copied file to something guaranteed unique. Nonsense is good here.&lt;/li>
&lt;li>Rename the copied class to the new purpose.&lt;/li>
&lt;li>Update the construction site to instantiate the new class.&lt;/li>
&lt;li>Follow the compile errors, applying the auto-fix each time to change the type of the variable.&lt;/li>
&lt;/ol>
&lt;h3 id="the-hard-way-use-a-shim">The hard way: use a shim&lt;/h3>
&lt;p>If Split Class doesn&amp;rsquo;t support delegation:&lt;/p>
&lt;ol>
&lt;li>Create a new class with a unique nonsense name, a single private field of the old type and constructors that match the old type. Use auto-generate members to create delegating members.&lt;/li>
&lt;li>Rename the old class back to its Does The Right Thing name to make sure that doesn&amp;rsquo;t cause conflicts.&lt;/li>
&lt;li>Undo the rename refactoring (it was just a test).&lt;/li>
&lt;li>Hand-edit the name of the outer class to the name the inner class has (the Intent name for the other context).&lt;/li>
&lt;li>Hand-edit the inner class to the Does the Right Thing name.&lt;/li>
&lt;li>Update the type and construction of the field in the outer class to use the correct type.&lt;/li>
&lt;li>At this point, all call sites will now be using the outer class via the purpose-based name.&lt;/li>
&lt;li>Pick up from step 3 in the recipe that assumed Split Class that supports delegation.&lt;/li>
&lt;/ol>
&lt;p>This recipe uses a common mini-recipe: introduce a new name for an extracted thing but leave all users using the outer thing.&lt;/p>
&lt;p>If we can&amp;rsquo;t extract the inner thing, then we can get the same result by creating a new outer thing as a shim and then hand-editing the names (not updating call site) to slip it into place.&lt;/p>
&lt;p>It also uses a common refactoring test strategy. The most useful part of refactorings is not that they change your code, it is that they tell you what code changes are safe. Sometimes a refactoring won&amp;rsquo;t do exactly what you want, but you can still use its analysis to verify that the thing you want to do is safe.&lt;/p>
&lt;p>We do and undo a rename refactoring to test whether our new names will create any conflicts, even though we execute the name changes by hand so that we can put the shim into place.&lt;/p>
&lt;h2 id="warning-you-can-get-nonsense">Warning: you can get nonsense&lt;/h2>
&lt;p>Naming by Intent is the easiest one to screw up. If you screw it up you will get a nonsense name. You won&amp;rsquo;t notice; the name will make sense to you right now because you have the full context. But it will be nonsense the next time you try to use it.&lt;/p>
&lt;p>The problem is that this step is intentionally information-losing. We are replacing some of the information about what our thing does with information about why you care to use the thing. We are asking potential users to trust us. And we have to earn that trust. We earn it by using consistently clear names and code that &lt;strong>Does the Right Things&lt;/strong>.&lt;/p>
&lt;h2 id="ways-to-get-nonsense">Ways to get nonsense&lt;/h2>
&lt;p>An extremely popular way to get nonsense is to name a thing by when it is used, rather than why it is used. This gets us right back to calling something &lt;code>preLoad()&lt;/code>. One variation on this is to name a method by its initial condition. Ignore initial conditions in method names; they always end in broken abstractions.&lt;/p>
&lt;p>Another popular route to nonsense is to create a new concept that is never used anywhere else. One-off abstractions are noise. Create your abstraction by looking at many named entities and use it uniformly.&lt;/p>
&lt;p>But perhaps the most popular route to nonsense is to use a CS-y term. The domain of software engineering does not belong in your names unless you are writing a programming language. Even then, domain-specific languages are easier to read.&lt;/p>
&lt;p>To avoid nonsense be specific about the context. Clearly state why someone would want to do the things that this class/method is doing. Keep any parts of the Complete and Honest name that make it more obvious when you want to use this thing. Drop the rest.&lt;/p>
&lt;h2 id="adopt-now">Adopt Now&lt;/h2>
&lt;p>Help your team adopt Naming as a Process now!&lt;/p>
&lt;p>&lt;a href="https://learn.digdeeproots.com/habit/naming-as-a-process/">See How it Works&lt;/a>&lt;/p>
&lt;h2 id="read-more">Read More&lt;/h2>
&lt;p>Next up: see how our intention-revealing names &lt;a href="https://www.digdeeproots.com/articles/naming-is-a-process-intent-to-domain-abstraction/">make the right Domain Abstractions obvious&lt;/a>.&lt;/p>
&lt;p>Or read the whole &lt;a href="https://www.digdeeproots.com/articles/on/naming-as-a-process/">Naming as a Process blog series&lt;/a>.&lt;/p></description></item><item><title>Articles: Get to Domain Abstraction (Article 7)</title><link>/articles/naming-process/get-to-domain-abstraction/</link><pubDate>Fri, 11 Oct 2019 00:00:00 +0000</pubDate><guid>/articles/naming-process/get-to-domain-abstraction/</guid><description>
&lt;p>Finally we are ready for the most important step in naming. This step is why all of evolutionary design really comes down to &amp;ldquo;name things well. Continuously.&amp;rdquo; It is time to correct the domain abstractions we are using and adjust the names.&lt;/p>
&lt;p>We currently have a set of names used together. Each one expresses Intent individually. Responsibilities are factored into the right places (each Does the Right Thing). But taken together, the names are a mishmash of ideas. Each expresses itself and its context well, but they don&amp;rsquo;t create a shared context.&lt;/p>
&lt;blockquote>
&lt;p>A domain abstraction is just a shared context for some set of code.&lt;/p>
&lt;/blockquote>
&lt;p>At this point, the insights we seek are Whole Values. We want to find generative domain patterns. Concepts that, once they are in place, make the missing code as obvious as the code that is already written.&lt;/p>
&lt;p>We won&amp;rsquo;t necessarily write the missing code yet—we could be wrong about the domain abstraction we see—but we will leave the code in a state where it is obvious where and how to add this code if we need it.&lt;/p>
&lt;p>The fundamental process we will do at this step is to find Primitive Obsession, have an insight about a missing Whole Value, and write it down. We will do this mostly mechanically as we want to be able to have insights in code where we don&amp;rsquo;t yet see the unifying concept.&lt;/p>
&lt;h2 id="finding-primitive-obsession-mechanically">Finding Primitive Obsession mechanically&lt;/h2>
&lt;p>We are looking for Primitive Obsession: anywhere that we are trying to describe actions in a high-level domain entirely using concepts in a low-level domain. For example, we might pass around a social security number as a &lt;code>String&lt;/code>, rather than as a &lt;code>SocialSecurityNumber&lt;/code>. Similarly, we might talk about &lt;code>Set&amp;lt;Cards&amp;gt;&lt;/code>, rather than a &lt;code>PlayingCardDeck&lt;/code>.&lt;/p>
&lt;p>It is entirely possible to spot these based on your own intuition. Use that! However, Primitive Obsession also causes common antipatterns in code. You can look for those in order to learn to spot new kinds of Primitive Obsession.&lt;/p>
&lt;h3 id="part-1-look-for-sets-of-methods-or-classes-that-share-some-similarity">Part 1: Look for sets of methods or classes that share some similarity&lt;/h3>
&lt;p>Here are some of the common patterns I look for. Each identifies some primitive that I am obsessing over.&lt;/p>
&lt;p>&lt;strong>In sets of classes:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Tight interdependencies with few connections outside the set.&lt;/li>
&lt;li>Several methods in one class that use public getters from another.&lt;/li>
&lt;li>Classes with similar names:
&lt;ul>
&lt;li>&lt;code>Thing&lt;/code> / &lt;code>ThingIsValid&lt;/code>,&lt;/li>
&lt;li>Repeated prefixes or suffixes: &lt;code>-Transform&lt;/code>, &lt;code>-Traversal&lt;/code>, &lt;code>Tree-&lt;/code>, &lt;code>Tail-&lt;/code>.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Classes with CSy or grab-bag names:
&lt;ul>
&lt;li>&lt;code>-Manager&lt;/code>,&lt;/li>
&lt;li>&lt;code>-Transform&lt;/code>.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Names that end with -er, indicating an action rather than a result / object.&lt;/li>
&lt;li>Feature envy: obsessing over the methods and properties of another object and calling it all the time.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>In sets of methods:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Sets of methods that take the same set of parameters.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Sets of methods that each use the same subset of an object&amp;rsquo;s fields.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Methods with similar names:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;code>begin&lt;/code> / &lt;code>end&lt;/code> / see progress / poll for data,&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>create&lt;/code> / &lt;code>read&lt;/code> / &lt;code>update&lt;/code> / &lt;code>destroy&lt;/code>,&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>source&lt;/code> / &lt;code>sink&lt;/code> / &lt;code>transform&lt;/code>,&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Names which contain near-synonyms.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>Chunks of methods which obsess over some variable or small set of variables for several lines (many operations on the same data).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Methods which are often called together (especially common in error handling or creation logic).&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Common phrases in the name without a matching noun in the system.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Fields &amp;amp; parameters:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Names that narrow what the thing is, because the variable&amp;rsquo;s type name cannot (&lt;code>firstName&lt;/code>, &lt;code>lastName&lt;/code>, &lt;code>SocialSecurityNumber&lt;/code>—all on parameters of type String).&lt;/li>
&lt;li>Names that narrow or interpret allowed values (&lt;code>rangeInMeters&lt;/code>, &lt;code>hardwareModeFlags&lt;/code>—both on fields of type int).&lt;/li>
&lt;/ul>
&lt;p>Each of these indicates that something is missing in your set of domain abstractions. Other code is coddling that missing abstraction.&lt;/p>
&lt;p>Each of these also indicates code that is using an overly-general concept where something more explicit and single-purpose would do.&lt;/p>
&lt;h3 id="part-2-look-for-a-primitive-and-the-domain-concept-that-would-replace-it">Part 2: Look for a primitive and the domain concept that would replace it&lt;/h3>
&lt;p>Every time we see one of the above, we know something is missing. Our goal is to figure out what is missing and create it. This comes in two steps. First we name the primitive, then we name the thing we should use instead.&lt;/p>
&lt;p>We don&amp;rsquo;t need to rename the primitive in the code. We&amp;rsquo;re about to replace it. Instead we write it down on a notecard or whiteboard. State precisely which primitive we see and what obsessive behaviors we see the code doing over it.&lt;/p>
&lt;h3 id="part-3-write-down-by-adding-new-whole-value-that-matters">Part 3: Write down by adding new Whole Value that matters&lt;/h3>
&lt;p>Now we want to write our insight down into code. We need to do the following:&lt;/p>
&lt;ol>
&lt;li>Break the specific concept out of the general concept.&lt;/li>
&lt;li>Examine each piece of coddling code.&lt;/li>
&lt;li>Break the part &amp;lsquo;../../post/get-to-domain-abstraction&amp;rsquo;that is related to the new concept out of its context.&lt;/li>
&lt;li>Move the related part &amp;lsquo;../../post/get-to-domain-abstraction&amp;rsquo;to the new concept.&lt;/li>
&lt;/ol>
&lt;p>The first 3 steps use refactorings that we already used in earlier phases. Break a concept up by moving from missing to nonsense, then climb the naming levels as desired.&lt;/p>
&lt;p>Step 4 uses:&lt;/p>
&lt;ul>
&lt;li>Move Method / Class&lt;/li>
&lt;li>Convert to Instance Method&lt;/li>
&lt;li>Convert to Static&lt;/li>
&lt;li>Convert to Extension Method (if in C#)&lt;/li>
&lt;li>Rename&lt;/li>
&lt;/ul>
&lt;p>The most common form of rename is to intentionally combine code chunks.&lt;/p>
&lt;p>When a primitive has been running around the system for a while, often multiple pieced of code wanted to do the same operation to that primitive. The operation was small (often a 1-line loop with an accumulator variable or a simple conditional). So they just duplicated code inline.&lt;/p>
&lt;p>In step 3 we extracted these duplicate chunks into tiny methods. We gave each a good name based on its context (an intention-level name).&lt;/p>
&lt;p>In 4 we:&lt;/p>
&lt;ol>
&lt;li>Move them all to the new class.&lt;/li>
&lt;li>Use non-overlapping names so that we ensure zero behavior change.&lt;/li>
&lt;li>Sort together those with identical implementation.&lt;/li>
&lt;li>Examine pairs with identical implementation to see if they also share intent (not all duplicates have the same intent, especially when we are adding a missing domain abstraction).&lt;/li>
&lt;li>Any time we find a pair with same implementation and intent, we rename whichever has the less-revealing name to match the name for the other.&lt;/li>
&lt;li>Then delete one, leaving the callers sharing code.&lt;/li>
&lt;li>Repeat until each pair that shares implementation doesn&amp;rsquo;t share intent.&lt;/li>
&lt;/ol>
&lt;p>It is also common to find pairs that share intent but not implementation. These could be bugs (someone updated one use of the primitive but missed another). They could also be features (the intent is nuanced).&lt;/p>
&lt;p>When you find two chunks with similar intent but different implementation:&lt;/p>
&lt;ol>
&lt;li>Rename them to be very similar.
&lt;ul>
&lt;li>Use a common prefix followed by something that distinguishes the difference.&lt;/li>
&lt;li>The difference will be implementation, not intent / domain-relevant. That is a smell but better than we had before.&lt;/li>
&lt;li>We can later address that smell by going through the naming process again. Finish this pass first.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>Write a pair of tests, one for each chunk. Describe both the common part (with a shared assertion method) and the difference (with two clear, separate asserts).&lt;/li>
&lt;li>Optional: combine the two methods into one method with a discriminator variable.&lt;/li>
&lt;/ol>
&lt;p>The last step can make things either more or less clear. It can hide the code smell and reduce the probability of fixing, but it can also create a new concept (the discriminator variable itself) which can grow into a valid domain abstraction.&lt;/p>
&lt;p>For details on how, see my gist &lt;a href="https://gist.github.com/arlobelshee/25a17ce7676b807c1dde/3325da7067686e13b9771658f9fd9499c6d03841">Combine 2 methods into one with a discriminator variable&lt;/a> (I&amp;rsquo;m combining two slightly different implementations of &lt;code>Car.Drive()&lt;/code>).&lt;/p>
&lt;ul>
&lt;li>The history shows a complete set of refactorings (17 steps) to implement the re-design without ever violating safety.&lt;/li>
&lt;li>I have tests only to show what happens to call sites. I never relied on tests to verify any step.&lt;/li>
&lt;li>I would be equally comfortable (and safe) performing this on entirely untested code with thousands of call sites.&lt;/li>
&lt;/ul>
&lt;h2 id="and-thats-it">And that&amp;rsquo;s it!&lt;/h2>
&lt;p>We identified our domain abstraction and wrote it down. At this point our naming is done.&lt;/p>
&lt;p>In the real world it probably took me a week or so to get through this whole process (at a total time cost of 30 minutes spread across that week). I find missing names one at a time, create them, and get them up to the honest level. After doing that 4-6 times in one area area I upgrade each of those names up to does the right thing (through complete on the way). After I do that 2-3 times the intent becomes clear and I upgrade the names.&lt;/p>
&lt;p>And every so often I see primitives lying around or duplicate sequences of statements that operate on the same variables. When all the names around are intent-revealing, the missing Whole Value becomes obvious. It often requires 2-5 flurries of creating intent-based names before a whole area is intent-revealing.&lt;/p>
&lt;p>I introduce a new domain abstraction. Usually, I introduce 3-5 of them in a single quick flurry. The code rapidly changes across the project to use the new abstraction in about 60% of the applicable cases. Then slow change happens over another week or two as the abstraction proves to be valuable. It attracts new operations and cleans up the other applicable cases.&lt;/p>
&lt;h2 id="adopt-now">Adopt Now&lt;/h2>
&lt;p>Help your team adopt Naming as a Process now!&lt;/p>
&lt;p>&lt;a href="https://learn.digdeeproots.com/habit/naming-as-a-process/">See How it Works&lt;/a>&lt;/p>
&lt;h2 id="read-more">Read More&lt;/h2>
&lt;p>Next up: learn how to &lt;a href="https://www.digdeeproots.com/articles/naming-as-a-process-learning-path/">apply this whole approach in short steps that each provide value and can be mastered&lt;/a>.&lt;/p>
&lt;p>Or read the whole &lt;a href="https://www.digdeeproots.com/articles/on/naming-as-a-process/">Naming as a Process blog series&lt;/a>.&lt;/p></description></item><item><title>Articles: A Learning Path (Article 8)</title><link>/articles/naming-process/naming-as-a-process-learning-path/</link><pubDate>Thu, 10 Oct 2019 00:00:00 +0000</pubDate><guid>/articles/naming-process/naming-as-a-process-learning-path/</guid><description>
&lt;p>Is your naming process effective for working with others?&lt;/p>
&lt;p>There are two hard problems that we face constantly.&lt;/p>
&lt;ul>
&lt;li>Naming&lt;/li>
&lt;li>Cache invalidation&lt;/li>
&lt;li>Off by 1 errors&lt;/li>
&lt;/ul>
&lt;p>With naming being such a nemesis, it would be valuable to have techniques to make it easier. Naming as a Process describes those techniques.&lt;/p>
&lt;p>&lt;img src="images/7_stages_of_naming_small.png" alt="7 stages of naming">&lt;/p>
&lt;p>And (4 years later) I re-wrote &lt;a href="https://www.digdeeproots.com/articles/on/naming-as-a-process/">my blog series&lt;/a> and added a summary and learning path (this post) to adopt naming as a process. Why did it take me 4 years to write?&lt;/p>
&lt;p>My significant blockers were:&lt;/p>
&lt;ol>
&lt;li>I needed to iterate and improve the steps; &lt;/li>
&lt;li>I realized how disciplined refactoring grounds the naming process and needing to figure out how to teach just enough of it; and&lt;/li>
&lt;li>I needed a series of on-the-job practice guides to really help people learn the process.&lt;/li>
&lt;/ol>
&lt;p>So, 4 years later I return to you with a very grounded and practiced way to adopt naming as a process.&lt;/p>
&lt;h2 id="names-go-through-7-steps-but-the-process-is-really-3-phases">Names Go Through 7 steps, but the Process is Really 3 Phases&lt;/h2>
&lt;p>One of the many nuances I learned in those four years is that the 7-step naming process actually breaks down in three major phases, the first one being the one you can learn now.&lt;/p>
&lt;p>.clear { clear: both; } .side-icon figure { margin: 0 0 1em 0; }&lt;/p>
&lt;p>&lt;img src="images/NamingPage-Phase1.png" alt="">&lt;/p>
&lt;p>The first phase is simply getting realizations about what the code does. Based on those insights, you would then record that information into a name. This includes the steps from Missing or Misleading through Nonsense, Honest, and Honest and Complete. The only refactorings you need are extract method and rename. The learning path provided in this post will guide you through it.&lt;/p>
&lt;p>&lt;img src="images/NamingPage-Phase2.png" alt="">&lt;/p>
&lt;p>The second phase is using those names to guide correct chunking. Of the seven stages of naming, this contains the &lt;em>Do the Right Thing&lt;/em> step. The only concept is to refactor the structure to match the name. However, which structural refactorings you need depends on your context. Deep Roots, my company built to eliminate technical waste through refactoring habit shifts, offers 60+ potential habits that developers might need to perform that step. However, knowing &lt;em>which&lt;/em> of those steps to learn requires coaching guidance.&lt;/p>
&lt;p>&lt;img src="images/NamingPage-Phase3.png" alt="">&lt;/p>
&lt;p>The third and final phase is using the chunks to guide the right design. Frankly, the combination of the first two phases represents all the &lt;em>new&lt;/em> information and behavior shifts. However, this final phase uses your structural and naming refactorings for a new purpose. There is little to learn here, just lots of practice.&lt;/p>
&lt;h2 id="lets-learn-phase-one">Let’s Learn Phase One!&lt;/h2>
&lt;p>The naming blog series gave you a sequential process, but that does not mean that’s the order to learn it. We wouldn’t teach our children how to cook by having them create a menu, go shopping, and then all the steps involved with cooking the meal. We would teach them some micro-steps within the cooking process to give them a context of the overall structure, such as how to measure ingredients or identify easy recipes. Once they master cooking a dish we would add on the up-front activities.&lt;/p>
&lt;p>The following sequence ensures each micro-step is easy to learn and provides immediate value. This is &lt;strong>not&lt;/strong> the same as the order a name goes through.&lt;/p>
&lt;ol>
&lt;li>Mob for awareness. Try out all the parts together, preferably with a skilled guide.&lt;/li>
&lt;li>Start with Step 2 of the naming process (yes, skip and ignore step 1 for now): making an honest name. This step is useful on its own, and you have plenty of bad names available to work with.&lt;/li>
&lt;li>Now add Step 1 of the naming process: using obvious nonsense. This splits one activity out of step 2, making the process easier.&lt;/li>
&lt;li>Finally go on to Step 3 of the naming process: being completely honest (eventually). This gives you an iterative way to build on step 2 and eventually get a good name.&lt;/li>
&lt;li>Phase 1 mindshift: put insights into names. This brings the techniques together and makes it easy to pick up from your colleague’s partial progress.&lt;/li>
&lt;/ol>
&lt;p>While you are welcome to try this out on your own, Deep Roots has also &lt;a href="https://www.digdeeproots.com/legacy/">created a legacy code mastery workshop&lt;/a> that includes &lt;em>Naming as a Process&lt;/em>.&lt;/p>
&lt;h3 id="mob-for-awareness">Mob for awareness&lt;/h3>
&lt;p>Get together as a mob with a long method. Your goal is to get the entire method to be Honest, and some to be well on the way towards Honest and Complete. Your second goal is to do this in as many commits as you can, where each is a legitimate improvement of some name. Timebox for an hour, and do a quick retrospective at the end.&lt;/p>
&lt;p>The mob will give you awareness of the whole process. You will also work through several problems together that would otherwise stump you for an hour when alone. You won’t learn anything well enough to apply it on your own, but you will get a feel for the flow.&lt;/p>
&lt;p>Tips:&lt;/p>
&lt;ul>
&lt;li>Set up a good mobbing environment.&lt;/li>
&lt;li>Keep the mob flowing. Don’t stop to discuss. Just try something. If it doesn’t work, revert.&lt;/li>
&lt;li>Be explicit about the goal. You are trying out a new way of working with names so don’t expect to make any progress on a story.&lt;/li>
&lt;/ul>
&lt;h3 id="shift-1-get-to-honest">Shift 1: Get to Honest&lt;/h3>
&lt;p>After applying this shift you will know which names you can’t trust, so you will have some names that you &lt;em>can&lt;/em> trust. This will speed up your story development.&lt;/p>
&lt;p>Your goal is to develop a habit of &lt;a href="https://www.digdeeproots.com/articles/get-to-honest/">noticing when a name is not trustworthy, and then making it trustworthy&lt;/a>. Even if it is not very informative, it should explicitly state what it is informing you about and whether there are things it is not informing you about.&lt;/p>
&lt;h3 id="shift-2-get-to-obvious-nonsense">Shift 2: Get to Obvious Nonsense&lt;/h3>
&lt;p>This shift will speed up your ability to extract useful code chunks from long methods, resulting in much faster productivity on stories that touch long methods.&lt;/p>
&lt;p>The target habit is to &lt;a href="https://www.digdeeproots.com/articles/get-to-obvious-nonsense/">identify one separable chunk and pull it out without delaying to figure out what to call it&lt;/a>. Simply dividing the work allows you to apply your whole brain to each part of the task.&lt;/p>
&lt;p>You will also identify misleading names and immediately turn them into obvious nonsense without the delay to understand them. This will let you quickly fix a common code trap without getting sidetracked, reducing the number of bugs you write.&lt;/p>
&lt;h3 id="shift-3-get-to-completely-honest-by-adding-knowns">Shift 3: Get to Completely Honest by Adding Knowns&lt;/h3>
&lt;p>Applying this shift over time will decrease the time it takes for each story. You will need to read less code because each name will tell you everything you need to know.&lt;/p>
&lt;p>The target habit is to &lt;a href="https://www.digdeeproots.com/articles/get-to-completely-honest/">iteratively build knowledge into names by adding one clause at a time&lt;/a> (Section: Expand the Known). Because each step is better than before, you can check in and move on at any time. This allows you to discover names as you need them and avoids ratholing during refactoring.&lt;/p>
&lt;h3 id="shift-4-get-to-completely-honest-by-narrowing-unknowns">Shift 4: Get to Completely Honest by Narrowing Unknowns&lt;/h3>
&lt;p>Applying this shift will allow you to quickly identify code that you won&amp;rsquo;t have to read any further.&lt;/p>
&lt;p>This shift is within the same naming stage of getting to completely honest, but doing it by narrowing what you &lt;em>don&amp;rsquo;t&lt;/em> know instead of adding what you &lt;em>do&lt;/em> know (Shift 3).&lt;/p>
&lt;p>The target habit is the same as Shift 3, where you &lt;a href="https://www.digdeeproots.com/articles/get-to-completely-honest/">iteratively build knowledge into names by adding one clause at a time&lt;/a> (Section: Narrow the Unknown). However, this time you&amp;rsquo;re narrowing what you don&amp;rsquo;t know.&lt;/p>
&lt;h3 id="the-aha-putting-insights-into-names">The Aha: Putting Insights into Names&lt;/h3>
&lt;p>This mindset makes the four shifts become sustainable. It will allow you to stop refactoring more quickly, while colleagues pick up from where you left off as needed.&lt;/p>
&lt;ul>
&lt;li>You quickly assess the current state of a name &lt;/li>
&lt;li>You take the minimum steps to get the name to meet your need for the current story&lt;/li>
&lt;li>You leave the name in an incomplete state that will be extended by the next person&lt;/li>
&lt;li>Your team’s adoption of this ability improves the names exactly as much as needed without anyone doing rework&lt;/li>
&lt;/ul>
&lt;h2 id="applying-phase-one-every-day">Applying Phase One Every Day&lt;/h2>
&lt;p>Incremental naming to get to completely honest names is wonderful! However, it can be hard to sustain if that is all you learn. We need an equally incremental coding approach that works at the team level. Deep Roots calls that the Insight Loop.&lt;/p>
&lt;p>The Insight Loop consists of three habits that support each other:&lt;/p>
&lt;ol>
&lt;li>Start Refactoring Safely&lt;/li>
&lt;li>Naming is a Process&lt;/li>
&lt;li>Know When to Stop&lt;/li>
&lt;/ol>
&lt;p>The Insight Loop gives a team a structured, consistent way to see and make one design improvement or functionality improvement at a time. Implementing this will allow a team to consistently apply Naming as a Process forever.&lt;/p>
&lt;h2 id="how-can-we-do-phase-two">How Can We Do Phase Two?&lt;/h2>
&lt;p>Phase One is a set of practices that you &lt;em>can&lt;/em> do — yes, it’s much more sustainable with our &lt;a href="https://www.digdeeproots.com/legacy/">workshop&lt;/a>, but you are able to implement Phase One both alone and without help.&lt;/p>
&lt;p>Why can’t we keep going like this? Because Phase One is an approach that universally works across all code design flaws and work contexts. That&amp;rsquo;s not true for later phases.&lt;/p>
&lt;p>The next phase for naming completely depends on the specific problems you have in your code. We simply don’t know which of the many habits are needed for your context, so can&amp;rsquo;t offer the self-directed option, let alone a blog series.&lt;/p>
&lt;p>However, you can build a customized learning path for your team’s codebase using our broader habit catalog. &lt;a href="mailto:sales@digdeeproots.com?subject=I'm%20curious%20about%20custom%20habits">Email us to learn more about our customization options&lt;/a>.&lt;/p>
&lt;h2 id="what-is-this-phase-three-thing-then">What is this Phase Three Thing Then?&lt;/h2>
&lt;p>Quite simply, it’s the final phase that names go through. It doesn’t require any new skills; you just combine all the skills you learned in the first two phases to address a new problem.&lt;/p>
&lt;p>Phase Three appears to include significant additional design skills. In truth, however, mastery of the disciplined refactorings and incremental design approach that you learned in the first two phases will make it easy for you to teach yourself design concepts as you need them. While this does not require any fundamentally new concept or consulting, there is no passing GO (skipping Phase Two) in order to get here!&lt;/p>
&lt;h2 id="adopt-now">Adopt Now&lt;/h2>
&lt;p>Help your team adopt Naming as a Process now!&lt;/p>
&lt;p>&lt;a href="https://www.digdeeproots.com/legacy/">See How it Works&lt;/a>&lt;/p></description></item></channel></rss>