Auto-publish on Mon 11 Aug 18:40:16 BST 2025
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2025-08-10 Sun 22:23 -->
|
||||
<!-- 2025-08-11 Mon 18:40 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Clean Code: Chapter 1 Notes</title>
|
||||
@@ -224,16 +224,16 @@
|
||||
<h2>Table of Contents</h2>
|
||||
<div id="text-table-of-contents" role="doc-toc">
|
||||
<ul>
|
||||
<li><a href="#org2f555c6">Chapter 1: Clean Code</a></li>
|
||||
<li><a href="#orge23713a">Chapter 1: Clean Code</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
Link to <a href="clean-code-chapter-2.html">Chapter 2</a>
|
||||
</p>
|
||||
<div id="outline-container-org2f555c6" class="outline-2">
|
||||
<h2 id="org2f555c6">Chapter 1: Clean Code</h2>
|
||||
<div class="outline-text-2" id="text-org2f555c6">
|
||||
<div id="outline-container-orge23713a" class="outline-2">
|
||||
<h2 id="orge23713a">Chapter 1: Clean Code</h2>
|
||||
<div class="outline-text-2" id="text-orge23713a">
|
||||
<p>
|
||||
Referenced Items:
|
||||
</p>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||
<head>
|
||||
<!-- 2025-08-10 Sun 22:23 -->
|
||||
<!-- 2025-08-11 Mon 18:40 -->
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Clean Code: Chapter 2 Notes</title>
|
||||
@@ -224,22 +224,22 @@
|
||||
<h2>Table of Contents</h2>
|
||||
<div id="text-table-of-contents" role="doc-toc">
|
||||
<ul>
|
||||
<li><a href="#orgf854a65">Chapter 2: Meaningful Names</a>
|
||||
<li><a href="#orgb686bd7">Chapter 2: Meaningful Names</a>
|
||||
<ul>
|
||||
<li><a href="#org364c14f">Use intention revealing names:</a></li>
|
||||
<li><a href="#org51ebb75">Avoid disinformation</a></li>
|
||||
<li><a href="#orga42c8d8">Make Meaningful Distinctions</a></li>
|
||||
<li><a href="#org73af170">Use Pronouncable Names</a></li>
|
||||
<li><a href="#org417e423">Use Searchable Names</a></li>
|
||||
<li><a href="#org5ea3161">Avoid Encodings</a></li>
|
||||
<li><a href="#orgd2ecf49">Avoid Mental Mappings</a></li>
|
||||
<li><a href="#orge157282">Class Names</a></li>
|
||||
<li><a href="#org4d51074">Method Names</a></li>
|
||||
<li><a href="#org49e40f7">Don't be cute/Don't use puns</a></li>
|
||||
<li><a href="#orge6fd9a6">Pick one word per concept</a></li>
|
||||
<li><a href="#orgdd3b07c">Solution Domain Names and Problem Domain Names</a></li>
|
||||
<li><a href="#org4f96def">Add Meaningful Context</a></li>
|
||||
<li><a href="#org6dc9178">Don't add gratuitous context</a></li>
|
||||
<li><a href="#org1b69c97">Use intention revealing names:</a></li>
|
||||
<li><a href="#org6d2fa23">Avoid disinformation</a></li>
|
||||
<li><a href="#orga928fc1">Make Meaningful Distinctions</a></li>
|
||||
<li><a href="#orga58d228">Use Pronouncable Names</a></li>
|
||||
<li><a href="#org8389eee">Use Searchable Names</a></li>
|
||||
<li><a href="#org7db8231">Avoid Encodings</a></li>
|
||||
<li><a href="#org3808e9b">Avoid Mental Mappings</a></li>
|
||||
<li><a href="#org505eeb0">Class Names</a></li>
|
||||
<li><a href="#org0e4f11d">Method Names</a></li>
|
||||
<li><a href="#orgf289be2">Don't be cute/Don't use puns</a></li>
|
||||
<li><a href="#org7235596">Pick one word per concept</a></li>
|
||||
<li><a href="#orgd8c6d85">Solution Domain Names and Problem Domain Names</a></li>
|
||||
<li><a href="#orgc2adbc1">Add Meaningful Context</a></li>
|
||||
<li><a href="#orgac0d077">Don't add gratuitous context</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -248,13 +248,13 @@
|
||||
<p>
|
||||
Link to <a href="clean-code-chapter-1.html">Chapter 1</a>
|
||||
</p>
|
||||
<div id="outline-container-orgf854a65" class="outline-2">
|
||||
<h2 id="orgf854a65">Chapter 2: Meaningful Names</h2>
|
||||
<div class="outline-text-2" id="text-orgf854a65">
|
||||
<div id="outline-container-orgb686bd7" class="outline-2">
|
||||
<h2 id="orgb686bd7">Chapter 2: Meaningful Names</h2>
|
||||
<div class="outline-text-2" id="text-orgb686bd7">
|
||||
</div>
|
||||
<div id="outline-container-org364c14f" class="outline-3">
|
||||
<h3 id="org364c14f">Use intention revealing names:</h3>
|
||||
<div class="outline-text-3" id="text-org364c14f">
|
||||
<div id="outline-container-org1b69c97" class="outline-3">
|
||||
<h3 id="org1b69c97">Use intention revealing names:</h3>
|
||||
<div class="outline-text-3" id="text-org1b69c97">
|
||||
<p>
|
||||
Names should reveal intent, there is no revelation in naming an integer <code>d</code>, intending it stands for days. Instead, you should use the following names:
|
||||
</p>
|
||||
@@ -267,17 +267,17 @@ Names should reveal intent, there is no revelation in naming an integer <code>d<
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-org51ebb75" class="outline-3">
|
||||
<h3 id="org51ebb75">Avoid disinformation</h3>
|
||||
<div class="outline-text-3" id="text-org51ebb75">
|
||||
<div id="outline-container-org6d2fa23" class="outline-3">
|
||||
<h3 id="org6d2fa23">Avoid disinformation</h3>
|
||||
<div class="outline-text-3" id="text-org6d2fa23">
|
||||
<p>
|
||||
Don't postfix the word 'list' to the name 'accounts' unless it's actually a list. This is because the reader will <i>assume</i> the data type of accountsList is indeed a list, instead choose a name like <code>accountsGroup</code>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-orga42c8d8" class="outline-3">
|
||||
<h3 id="orga42c8d8">Make Meaningful Distinctions</h3>
|
||||
<div class="outline-text-3" id="text-orga42c8d8">
|
||||
<div id="outline-container-orga928fc1" class="outline-3">
|
||||
<h3 id="orga928fc1">Make Meaningful Distinctions</h3>
|
||||
<div class="outline-text-3" id="text-orga928fc1">
|
||||
<p>
|
||||
While it is possible to name by being disinformative, it is also possible to name being non informative. Consider:
|
||||
</p>
|
||||
@@ -302,18 +302,18 @@ Furthermore, noise words are redundant. We should never use the word <code>varia
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-org73af170" class="outline-3">
|
||||
<h3 id="org73af170">Use Pronouncable Names</h3>
|
||||
<div class="outline-text-3" id="text-org73af170">
|
||||
<div id="outline-container-orga58d228" class="outline-3">
|
||||
<h3 id="orga58d228">Use Pronouncable Names</h3>
|
||||
<div class="outline-text-3" id="text-orga58d228">
|
||||
<p>
|
||||
This is quite straightforward. Do not use a name like <code>genymdhms</code> to refer to generation date, year, month, day, hour, minute,
|
||||
and second. Instead use <code>generationTimeStamp</code>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-org417e423" class="outline-3">
|
||||
<h3 id="org417e423">Use Searchable Names</h3>
|
||||
<div class="outline-text-3" id="text-org417e423">
|
||||
<div id="outline-container-org8389eee" class="outline-3">
|
||||
<h3 id="org8389eee">Use Searchable Names</h3>
|
||||
<div class="outline-text-3" id="text-org8389eee">
|
||||
<p>
|
||||
In modern IDE's, it is still quite difficult to search for single-lettered variables. The writer states a personal preference of using single-letter names only as local variables and inside short methods. The following principle is given:
|
||||
</p>
|
||||
@@ -323,42 +323,42 @@ In modern IDE's, it is still quite difficult to search for single-lettered varia
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-org5ea3161" class="outline-3">
|
||||
<h3 id="org5ea3161">Avoid Encodings</h3>
|
||||
<div class="outline-text-3" id="text-org5ea3161">
|
||||
<div id="outline-container-org7db8231" class="outline-3">
|
||||
<h3 id="org7db8231">Avoid Encodings</h3>
|
||||
<div class="outline-text-3" id="text-org7db8231">
|
||||
<p>
|
||||
Don't prefix variables with letters like m_ as was done in the past. Do not type encode as well, an example of this is: <code>PhoneNumber phoneString;</code> we can see the reader being misled into thinking the phone number is a String.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-orgd2ecf49" class="outline-3">
|
||||
<h3 id="orgd2ecf49">Avoid Mental Mappings</h3>
|
||||
<div class="outline-text-3" id="text-orgd2ecf49">
|
||||
<div id="outline-container-org3808e9b" class="outline-3">
|
||||
<h3 id="org3808e9b">Avoid Mental Mappings</h3>
|
||||
<div class="outline-text-3" id="text-org3808e9b">
|
||||
<p>
|
||||
Clarity is king, don't use a name for a variable that only you know what it stands for. For example: using the letter r as the lower-cased version of the url with the host and scheme
|
||||
removed. That's being smart, not professional.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-orge157282" class="outline-3">
|
||||
<h3 id="orge157282">Class Names</h3>
|
||||
<div class="outline-text-3" id="text-orge157282">
|
||||
<div id="outline-container-org505eeb0" class="outline-3">
|
||||
<h3 id="org505eeb0">Class Names</h3>
|
||||
<div class="outline-text-3" id="text-org505eeb0">
|
||||
<p>
|
||||
<div class="epigraph"><blockquote>Classes and objects should have noun or noun phrase names like Customer, WikiPage, Account, and AddressParser. Avoid words like Manager, Processor, Data, or Info in the name of a class. A class name should not be a verb</blockquote></div>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-org4d51074" class="outline-3">
|
||||
<h3 id="org4d51074">Method Names</h3>
|
||||
<div class="outline-text-3" id="text-org4d51074">
|
||||
<div id="outline-container-org0e4f11d" class="outline-3">
|
||||
<h3 id="org0e4f11d">Method Names</h3>
|
||||
<div class="outline-text-3" id="text-org0e4f11d">
|
||||
<p>
|
||||
Methods should have verb or verb phrase names.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-org49e40f7" class="outline-3">
|
||||
<h3 id="org49e40f7">Don't be cute/Don't use puns</h3>
|
||||
<div class="outline-text-3" id="text-org49e40f7">
|
||||
<div id="outline-container-orgf289be2" class="outline-3">
|
||||
<h3 id="orgf289be2">Don't be cute/Don't use puns</h3>
|
||||
<div class="outline-text-3" id="text-orgf289be2">
|
||||
<p>
|
||||
Do not use names that are only understandable to people whom you share jokes etc with. Furthermore, do not use colloquialism and slang in names.
|
||||
</p>
|
||||
@@ -368,17 +368,17 @@ Do not use names that are only understandable to people whom you share jokes etc
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-orge6fd9a6" class="outline-3">
|
||||
<h3 id="orge6fd9a6">Pick one word per concept</h3>
|
||||
<div class="outline-text-3" id="text-orge6fd9a6">
|
||||
<div id="outline-container-org7235596" class="outline-3">
|
||||
<h3 id="org7235596">Pick one word per concept</h3>
|
||||
<div class="outline-text-3" id="text-org7235596">
|
||||
<p>
|
||||
If you have multiple choices for naming a concept, use one and stick with it. For instance if your options are fetch, get and retrieve, use one and stick with it throughout.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-orgdd3b07c" class="outline-3">
|
||||
<h3 id="orgdd3b07c">Solution Domain Names and Problem Domain Names</h3>
|
||||
<div class="outline-text-3" id="text-orgdd3b07c">
|
||||
<div id="outline-container-orgd8c6d85" class="outline-3">
|
||||
<h3 id="orgd8c6d85">Solution Domain Names and Problem Domain Names</h3>
|
||||
<div class="outline-text-3" id="text-orgd8c6d85">
|
||||
<p>
|
||||
Where possible use solution domain names, as the people that are going to be reading the code are programmers. Therefore, do not shy away from using CS terms, algorithm names, math names and so forth.
|
||||
</p>
|
||||
@@ -388,17 +388,17 @@ However when it is not possible to use solution domain names (in other words, wh
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-org4f96def" class="outline-3">
|
||||
<h3 id="org4f96def">Add Meaningful Context</h3>
|
||||
<div class="outline-text-3" id="text-org4f96def">
|
||||
<div id="outline-container-orgc2adbc1" class="outline-3">
|
||||
<h3 id="orgc2adbc1">Add Meaningful Context</h3>
|
||||
<div class="outline-text-3" id="text-orgc2adbc1">
|
||||
<p>
|
||||
Enclose names with well-named classes, functions, or namespaces. When all else fails, then prefix with something that provides more context.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outline-container-org6dc9178" class="outline-3">
|
||||
<h3 id="org6dc9178">Don't add gratuitous context</h3>
|
||||
<div class="outline-text-3" id="text-org6dc9178">
|
||||
<div id="outline-container-orgac0d077" class="outline-3">
|
||||
<h3 id="orgac0d077">Don't add gratuitous context</h3>
|
||||
<div class="outline-text-3" id="text-orgac0d077">
|
||||
<p>
|
||||
Shorter names are better than longer ones, generally. This is so long as the context and intent is clear. Don't add redundant or irrelevant additions to the name in the for the sake of 'context'.
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user