619 lines
21 KiB
HTML
619 lines
21 KiB
HTML
<?xml version="1.0" encoding="utf-8"?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||
"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-09-26 Fri 15:56 -->
|
||
<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 4 Notes</title>
|
||
<meta name="generator" content="Org Mode" />
|
||
<style type="text/css">
|
||
#content { max-width: 60em; margin: auto; }
|
||
.title { text-align: center;
|
||
margin-bottom: .2em; }
|
||
.subtitle { text-align: center;
|
||
font-size: medium;
|
||
font-weight: bold;
|
||
margin-top:0; }
|
||
.todo { font-family: monospace; color: red; }
|
||
.done { font-family: monospace; color: green; }
|
||
.priority { font-family: monospace; color: orange; }
|
||
.tag { background-color: #eee; font-family: monospace;
|
||
padding: 2px; font-size: 80%; font-weight: normal; }
|
||
.timestamp { color: #bebebe; }
|
||
.timestamp-kwd { color: #5f9ea0; }
|
||
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
|
||
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
|
||
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
|
||
.underline { text-decoration: underline; }
|
||
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
|
||
p.verse { margin-left: 3%; }
|
||
pre {
|
||
border: 1px solid #e6e6e6;
|
||
border-radius: 3px;
|
||
background-color: #f2f2f2;
|
||
padding: 8pt;
|
||
font-family: monospace;
|
||
overflow: auto;
|
||
margin: 1.2em;
|
||
}
|
||
pre.src {
|
||
position: relative;
|
||
overflow: auto;
|
||
}
|
||
pre.src:before {
|
||
display: none;
|
||
position: absolute;
|
||
top: -8px;
|
||
right: 12px;
|
||
padding: 3px;
|
||
color: #555;
|
||
background-color: #f2f2f299;
|
||
}
|
||
pre.src:hover:before { display: inline; margin-top: 14px;}
|
||
/* Languages per Org manual */
|
||
pre.src-asymptote:before { content: 'Asymptote'; }
|
||
pre.src-awk:before { content: 'Awk'; }
|
||
pre.src-authinfo::before { content: 'Authinfo'; }
|
||
pre.src-C:before { content: 'C'; }
|
||
/* pre.src-C++ doesn't work in CSS */
|
||
pre.src-clojure:before { content: 'Clojure'; }
|
||
pre.src-css:before { content: 'CSS'; }
|
||
pre.src-D:before { content: 'D'; }
|
||
pre.src-ditaa:before { content: 'ditaa'; }
|
||
pre.src-dot:before { content: 'Graphviz'; }
|
||
pre.src-calc:before { content: 'Emacs Calc'; }
|
||
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
|
||
pre.src-fortran:before { content: 'Fortran'; }
|
||
pre.src-gnuplot:before { content: 'gnuplot'; }
|
||
pre.src-haskell:before { content: 'Haskell'; }
|
||
pre.src-hledger:before { content: 'hledger'; }
|
||
pre.src-java:before { content: 'Java'; }
|
||
pre.src-js:before { content: 'Javascript'; }
|
||
pre.src-latex:before { content: 'LaTeX'; }
|
||
pre.src-ledger:before { content: 'Ledger'; }
|
||
pre.src-lisp:before { content: 'Lisp'; }
|
||
pre.src-lilypond:before { content: 'Lilypond'; }
|
||
pre.src-lua:before { content: 'Lua'; }
|
||
pre.src-matlab:before { content: 'MATLAB'; }
|
||
pre.src-mscgen:before { content: 'Mscgen'; }
|
||
pre.src-ocaml:before { content: 'Objective Caml'; }
|
||
pre.src-octave:before { content: 'Octave'; }
|
||
pre.src-org:before { content: 'Org mode'; }
|
||
pre.src-oz:before { content: 'OZ'; }
|
||
pre.src-plantuml:before { content: 'Plantuml'; }
|
||
pre.src-processing:before { content: 'Processing.js'; }
|
||
pre.src-python:before { content: 'Python'; }
|
||
pre.src-R:before { content: 'R'; }
|
||
pre.src-ruby:before { content: 'Ruby'; }
|
||
pre.src-sass:before { content: 'Sass'; }
|
||
pre.src-scheme:before { content: 'Scheme'; }
|
||
pre.src-screen:before { content: 'Gnu Screen'; }
|
||
pre.src-sed:before { content: 'Sed'; }
|
||
pre.src-sh:before { content: 'shell'; }
|
||
pre.src-sql:before { content: 'SQL'; }
|
||
pre.src-sqlite:before { content: 'SQLite'; }
|
||
/* additional languages in org.el's org-babel-load-languages alist */
|
||
pre.src-forth:before { content: 'Forth'; }
|
||
pre.src-io:before { content: 'IO'; }
|
||
pre.src-J:before { content: 'J'; }
|
||
pre.src-makefile:before { content: 'Makefile'; }
|
||
pre.src-maxima:before { content: 'Maxima'; }
|
||
pre.src-perl:before { content: 'Perl'; }
|
||
pre.src-picolisp:before { content: 'Pico Lisp'; }
|
||
pre.src-scala:before { content: 'Scala'; }
|
||
pre.src-shell:before { content: 'Shell Script'; }
|
||
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
|
||
/* additional language identifiers per "defun org-babel-execute"
|
||
in ob-*.el */
|
||
pre.src-cpp:before { content: 'C++'; }
|
||
pre.src-abc:before { content: 'ABC'; }
|
||
pre.src-coq:before { content: 'Coq'; }
|
||
pre.src-groovy:before { content: 'Groovy'; }
|
||
/* additional language identifiers from org-babel-shell-names in
|
||
ob-shell.el: ob-shell is the only babel language using a lambda to put
|
||
the execution function name together. */
|
||
pre.src-bash:before { content: 'bash'; }
|
||
pre.src-csh:before { content: 'csh'; }
|
||
pre.src-ash:before { content: 'ash'; }
|
||
pre.src-dash:before { content: 'dash'; }
|
||
pre.src-ksh:before { content: 'ksh'; }
|
||
pre.src-mksh:before { content: 'mksh'; }
|
||
pre.src-posh:before { content: 'posh'; }
|
||
/* Additional Emacs modes also supported by the LaTeX listings package */
|
||
pre.src-ada:before { content: 'Ada'; }
|
||
pre.src-asm:before { content: 'Assembler'; }
|
||
pre.src-caml:before { content: 'Caml'; }
|
||
pre.src-delphi:before { content: 'Delphi'; }
|
||
pre.src-html:before { content: 'HTML'; }
|
||
pre.src-idl:before { content: 'IDL'; }
|
||
pre.src-mercury:before { content: 'Mercury'; }
|
||
pre.src-metapost:before { content: 'MetaPost'; }
|
||
pre.src-modula-2:before { content: 'Modula-2'; }
|
||
pre.src-pascal:before { content: 'Pascal'; }
|
||
pre.src-ps:before { content: 'PostScript'; }
|
||
pre.src-prolog:before { content: 'Prolog'; }
|
||
pre.src-simula:before { content: 'Simula'; }
|
||
pre.src-tcl:before { content: 'tcl'; }
|
||
pre.src-tex:before { content: 'TeX'; }
|
||
pre.src-plain-tex:before { content: 'Plain TeX'; }
|
||
pre.src-verilog:before { content: 'Verilog'; }
|
||
pre.src-vhdl:before { content: 'VHDL'; }
|
||
pre.src-xml:before { content: 'XML'; }
|
||
pre.src-nxml:before { content: 'XML'; }
|
||
/* add a generic configuration mode; LaTeX export needs an additional
|
||
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
|
||
pre.src-conf:before { content: 'Configuration File'; }
|
||
|
||
table { border-collapse:collapse; }
|
||
caption.t-above { caption-side: top; }
|
||
caption.t-bottom { caption-side: bottom; }
|
||
td, th { vertical-align:top; }
|
||
th.org-right { text-align: center; }
|
||
th.org-left { text-align: center; }
|
||
th.org-center { text-align: center; }
|
||
td.org-right { text-align: right; }
|
||
td.org-left { text-align: left; }
|
||
td.org-center { text-align: center; }
|
||
dt { font-weight: bold; }
|
||
.footpara { display: inline; }
|
||
.footdef { margin-bottom: 1em; }
|
||
.figure { padding: 1em; }
|
||
.figure p { text-align: center; }
|
||
.equation-container {
|
||
display: table;
|
||
text-align: center;
|
||
width: 100%;
|
||
}
|
||
.equation {
|
||
vertical-align: middle;
|
||
}
|
||
.equation-label {
|
||
display: table-cell;
|
||
text-align: right;
|
||
vertical-align: middle;
|
||
}
|
||
.inlinetask {
|
||
padding: 10px;
|
||
border: 2px solid gray;
|
||
margin: 10px;
|
||
background: #ffffcc;
|
||
}
|
||
#org-div-home-and-up
|
||
{ text-align: right; font-size: 70%; white-space: nowrap; }
|
||
textarea { overflow-x: auto; }
|
||
.linenr { font-size: smaller }
|
||
.code-highlighted { background-color: #ffff00; }
|
||
.org-info-js_info-navigation { border-style: none; }
|
||
#org-info-js_console-label
|
||
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
|
||
.org-info-js_search-highlight
|
||
{ background-color: #ffff00; color: #000000; font-weight: bold; }
|
||
.org-svg { }
|
||
</style>
|
||
|
||
<link rel="stylesheet" href="/assets/styles/style.css" />
|
||
<link rel="stylesheet" href="/assets/styles/bigger-picture.min.css" />
|
||
|
||
<script src="/assets/scripts/script.js" defer></script>
|
||
<script src="/assets/scripts/bigger-picture.min.js" defer></script>
|
||
<script src="/assets/scripts/svg-pan-zoom.min.js" defer></script>
|
||
<script src="/assets/scripts/gallery-init.js" defer></script>
|
||
</head>
|
||
<body>
|
||
<div id="preamble" class="status">
|
||
|
||
<div class="banner-header">
|
||
<a href="/"> <img src="/assets/images/gr.png" alt="Site Logo" class="banner-logo" /> </a>
|
||
<nav>
|
||
<a href="/">Home | </a>
|
||
<a href="/posts/posts-list.html">Posts | </a>
|
||
<a href="/blogs/blogs-list.html">Blogs | </a>
|
||
<a href="/contact.html">Contact</a>
|
||
</nav>
|
||
<button class="theme-toggle" id="theme-toggle" type="button" aria-label="Toggle dark mode">🌗 Theme</button>
|
||
</div>
|
||
<div id="updated">Updated: 2025-08-28 Thu 16:52</div>
|
||
</div>
|
||
<div id="content" class="content">
|
||
<h1 class="title">Clean Code: Chapter 4 Notes</h1>
|
||
<div class="filetags"><a href="/categories.html"> <span class="post-tag">books</span> </a> <a href="/categories.html"> <span class="post-tag">notes</span> </a></div>
|
||
|
||
<div id="table-of-contents" role="doc-toc">
|
||
<h2>Table of Contents</h2>
|
||
<div id="text-table-of-contents" role="doc-toc">
|
||
<ul>
|
||
<li><a href="#org3b3a86a">Chapter 4: Comments</a>
|
||
<ul>
|
||
<li><a href="#org563b20a">Comments Do Not Make Up for Bad Code</a></li>
|
||
<li><a href="#orgbb15258">Good Comments</a>
|
||
<ul>
|
||
<li><a href="#orgc8daf95">Legal Comments</a></li>
|
||
<li><a href="#org5f86e2c">Informative Comments</a></li>
|
||
<li><a href="#org9c9a43a">Explanation of Intent</a></li>
|
||
<li><a href="#org132954b">Clarification</a></li>
|
||
<li><a href="#org2bc9356">Warning of Consequences</a></li>
|
||
<li><a href="#org29e7534"><span class="todo TODO">TODO</span> Comments</a></li>
|
||
<li><a href="#org8f96c61">Amplification</a></li>
|
||
<li><a href="#orgf0eacd6">Javadocs in Public APIs</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="#orgeceeef2">Bad Comments</a>
|
||
<ul>
|
||
<li><a href="#org8948eeb">Don’t Use a Comment When You Can Use a Function or Variable</a></li>
|
||
<li><a href="#org9dd57c3">Position Markers</a></li>
|
||
<li><a href="#org27ce2f1">Closing Brace Comments</a></li>
|
||
<li><a href="#orgec579fa">Attributions and Bylines</a></li>
|
||
<li><a href="#org5ae47be">Commented Out Code</a></li>
|
||
<li><a href="#orgfe581e3">HTML Comments</a></li>
|
||
<li><a href="#org458bb98">Nonlocal Information</a></li>
|
||
<li><a href="#org6d8a526">Too Much Information</a></li>
|
||
<li><a href="#org99e4520">Inobvious Connection</a></li>
|
||
<li><a href="#org856f330">Function Headers</a></li>
|
||
<li><a href="#org080d921">Javadocs in Nonpublic Code</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<p>
|
||
Link to <a href="clean-code-chapter-3.html">Chapter 3</a> | Link to <a href="clean-code-chapter-5.html">Chapter 5</a>
|
||
</p>
|
||
<div id="outline-container-org3b3a86a" class="outline-2">
|
||
<h2 id="org3b3a86a">Chapter 4: Comments</h2>
|
||
<div class="outline-text-2" id="text-org3b3a86a">
|
||
<p>
|
||
Comments are a necessary evil—they exist because code fails to express intent clearly.
|
||
</p>
|
||
|
||
<p>
|
||
Outdated comments are dangerous; they can mislead more than help.
|
||
</p>
|
||
|
||
<p>
|
||
Strive to write code that explains itself; comments should be minimised.
|
||
</p>
|
||
|
||
<p>
|
||
Truth is always in the code, not in the comments.
|
||
</p>
|
||
</div>
|
||
<div id="outline-container-org563b20a" class="outline-3">
|
||
<h3 id="org563b20a">Comments Do Not Make Up for Bad Code</h3>
|
||
<div class="outline-text-3" id="text-org563b20a">
|
||
<p>
|
||
Don’t use comments to excuse messy, unclear code. Clean the code instead.
|
||
</p>
|
||
|
||
<p>
|
||
Clear, expressive code with few comments > cluttered code with many comments.
|
||
</p>
|
||
|
||
<div class="org-src-container">
|
||
<pre class="src src-java">
|
||
<span class="org-comment-delimiter">// </span><span class="org-comment">Check to see if the employee is eligible for full benefits
|
||
</span><span class="org-keyword">if</span> ((employee.flags & HOURLY_FLAG) && (employee.age > 65))
|
||
|
||
<span class="org-comment-delimiter">// </span><span class="org-comment">Better:
|
||
</span><span class="org-keyword">if</span> (employee.isEligibleForFullBenefits())
|
||
|
||
</pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-orgbb15258" class="outline-3">
|
||
<h3 id="orgbb15258">Good Comments</h3>
|
||
<div class="outline-text-3" id="text-orgbb15258">
|
||
<p>
|
||
Only write them when unavoidable. Such as in the following instances:
|
||
</p>
|
||
</div>
|
||
<div id="outline-container-orgc8daf95" class="outline-4">
|
||
<h4 id="orgc8daf95">Legal Comments</h4>
|
||
<div class="outline-text-4" id="text-orgc8daf95">
|
||
<p>
|
||
Sometimes required for copyright/licensing.
|
||
</p>
|
||
|
||
<p>
|
||
Keep them short; refer to standard licenses rather than embedding full legal text.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org5f86e2c" class="outline-4">
|
||
<h4 id="org5f86e2c">Informative Comments</h4>
|
||
<div class="outline-text-4" id="text-org5f86e2c">
|
||
<p>
|
||
Explain return values, formats, or patterns.
|
||
</p>
|
||
|
||
<p>
|
||
Prefer naming/structuring code to make such comments unnecessary.
|
||
</p>
|
||
|
||
<div class="org-src-container">
|
||
<pre class="src src-java">
|
||
<span class="org-comment-delimiter">// </span><span class="org-comment">format matched kk:mm:ss EEE, MMM dd, yyyy
|
||
</span><span class="org-type">Pattern</span> <span class="org-variable-name">timeMatcher</span> = Pattern.compile(<span class="org-string">"\\d*:\\d*:\\d* \\w*, \\w* \\d*, \\d*"</span>);
|
||
|
||
</pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org9c9a43a" class="outline-4">
|
||
<h4 id="org9c9a43a">Explanation of Intent</h4>
|
||
<div class="outline-text-4" id="text-org9c9a43a">
|
||
<p>
|
||
Describe why a certain approach was chosen.
|
||
</p>
|
||
|
||
<p>
|
||
Helps future maintainers understand reasoning behind code.
|
||
</p>
|
||
|
||
<div class="org-src-container">
|
||
<pre class="src src-java">
|
||
<span class="org-keyword">public</span> <span class="org-type">int</span> <span class="org-function-name">compareTo</span>(<span class="org-type">Object</span> <span class="org-variable-name">o</span>)
|
||
{
|
||
<span class="org-keyword">if</span>(o <span class="org-keyword">instanceof</span> WikiPagePath)
|
||
{ <span class="org-type">WikiPagePath</span> <span class="org-variable-name">p</span> = (<span class="org-type">WikiPagePath</span>) o;
|
||
<span class="org-type">String</span> <span class="org-variable-name">compressedName</span> = StringUtil.join(names, <span class="org-string">""</span>);
|
||
<span class="org-type">String</span> <span class="org-variable-name">compressedArgumentName</span> = StringUtil.join(p.names, <span class="org-string">""</span>);
|
||
<span class="org-keyword">return</span> compressedName.compareTo(compressedArgumentName);
|
||
}
|
||
<span class="org-keyword">return</span> 1; <span class="org-comment-delimiter">// </span><span class="org-comment">we are greater because we are the right type.
|
||
</span>}
|
||
|
||
</pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org132954b" class="outline-4">
|
||
<h4 id="org132954b">Clarification</h4>
|
||
<div class="outline-text-4" id="text-org132954b">
|
||
<p>
|
||
Translate obscure values into readable terms.
|
||
</p>
|
||
|
||
<p>
|
||
Useful when working with unchangeable APIs/libraries, but risky if incorrect.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org2bc9356" class="outline-4">
|
||
<h4 id="org2bc9356">Warning of Consequences</h4>
|
||
<div class="outline-text-4" id="text-org2bc9356">
|
||
<p>
|
||
Alert others about performance, thread-safety, or side effects.
|
||
</p>
|
||
|
||
<p>
|
||
For example, in code you can say:
|
||
</p>
|
||
|
||
<p>
|
||
<code>// SimpleDateFormat is not thread safe, so create each instance independently.</code>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org29e7534" class="outline-4">
|
||
<h4 id="org29e7534"><span class="todo TODO">TODO</span> Comments</h4>
|
||
<div class="outline-text-4" id="text-org29e7534">
|
||
<p>
|
||
Mark incomplete work or planned improvements.
|
||
</p>
|
||
|
||
<p>
|
||
Should be reviewed regularly; not an excuse for bad code.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org8f96c61" class="outline-4">
|
||
<h4 id="org8f96c61">Amplification</h4>
|
||
<div class="outline-text-4" id="text-org8f96c61">
|
||
<p>
|
||
Highlight the importance of seemingly small details.
|
||
</p>
|
||
|
||
<p>
|
||
<code>// the trim is real important. It removes starting spaces...</code>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-orgf0eacd6" class="outline-4">
|
||
<h4 id="orgf0eacd6">Javadocs in Public APIs</h4>
|
||
<div class="outline-text-4" id="text-orgf0eacd6">
|
||
<p>
|
||
Public APIs should have clear documentation.
|
||
</p>
|
||
|
||
<p>
|
||
Javadocs can also mislead. Keep them accurate and up-to-date.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-orgeceeef2" class="outline-3">
|
||
<h3 id="orgeceeef2">Bad Comments</h3>
|
||
<div class="outline-text-3" id="text-orgeceeef2">
|
||
<ul class="org-ul">
|
||
<li>Don't place a comment just because you feel like it.</li>
|
||
<li>Remove redundant comments.</li>
|
||
<li>Avoid misleading comments.</li>
|
||
<li>Don't mandate everything (not every function needs a Javadoc).</li>
|
||
<li>No need for journal comments, we have source control.</li>
|
||
<li>Remove noise comments.</li>
|
||
</ul>
|
||
</div>
|
||
<div id="outline-container-org8948eeb" class="outline-4">
|
||
<h4 id="org8948eeb">Don’t Use a Comment When You Can Use a Function or Variable</h4>
|
||
<div class="outline-text-4" id="text-org8948eeb">
|
||
<p>
|
||
Replace explanatory comments with expressive variable or function names.
|
||
</p>
|
||
|
||
<p>
|
||
Refactor code to remove comment redundancy.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org9dd57c3" class="outline-4">
|
||
<h4 id="org9dd57c3">Position Markers</h4>
|
||
<div class="outline-text-4" id="text-org9dd57c3">
|
||
<p>
|
||
Avoid decorative banners like <code>// Actions ///////////////////////</code>, they add clutter.
|
||
</p>
|
||
|
||
<p>
|
||
Use sparingly and only for meaningful grouping.
|
||
</p>
|
||
|
||
<p>
|
||
Overuse makes them blend into background noise.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org27ce2f1" class="outline-4">
|
||
<h4 id="org27ce2f1">Closing Brace Comments</h4>
|
||
<div class="outline-text-4" id="text-org27ce2f1">
|
||
<p>
|
||
Comments on closing braces (} // while) are unnecessary for small, well structured functions.
|
||
</p>
|
||
|
||
<p>
|
||
Prefer short, clear functions over brace markers.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-orgec579fa" class="outline-4">
|
||
<h4 id="orgec579fa">Attributions and Bylines</h4>
|
||
<div class="outline-text-4" id="text-orgec579fa">
|
||
<p>
|
||
Don’t add personal tags like <code>/* Added by Rick */</code>, use version control for authorship history.
|
||
</p>
|
||
|
||
<p>
|
||
Such comments become outdated and irrelevant over time.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org5ae47be" class="outline-4">
|
||
<h4 id="org5ae47be">Commented Out Code</h4>
|
||
<div class="outline-text-4" id="text-org5ae47be">
|
||
<p>
|
||
Never keep old code commented out; delete it and rely on version control history.
|
||
</p>
|
||
|
||
<p>
|
||
Commented-out code adds clutter and confuses future maintainers.
|
||
</p>
|
||
|
||
<div class="org-src-container">
|
||
<pre class="src src-java">
|
||
<span class="org-comment-delimiter">// </span><span class="org-comment">Old cruft that should be deleted:
|
||
</span><span class="org-comment-delimiter">//</span><span class="org-comment">hdrPos = bytePos;
|
||
</span><span class="org-comment-delimiter">//</span><span class="org-comment">dataPos = bytePos;
|
||
</span>
|
||
</pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-orgfe581e3" class="outline-4">
|
||
<h4 id="orgfe581e3">HTML Comments</h4>
|
||
<div class="outline-text-4" id="text-orgfe581e3">
|
||
<p>
|
||
Avoid HTML markup inside code comments, it makes them harder to read in the editor.
|
||
</p>
|
||
|
||
<p>
|
||
Let documentation tools (like Javadoc) handle formatting.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org458bb98" class="outline-4">
|
||
<h4 id="org458bb98">Nonlocal Information</h4>
|
||
<div class="outline-text-4" id="text-org458bb98">
|
||
<p>
|
||
Comments should describe nearby code only, not unrelated parts of the system.
|
||
</p>
|
||
|
||
<p>
|
||
Avoid embedding global/system details that the function can’t control.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org6d8a526" class="outline-4">
|
||
<h4 id="org6d8a526">Too Much Information</h4>
|
||
<div class="outline-text-4" id="text-org6d8a526">
|
||
<p>
|
||
Avoid long, unnecessary historical or technical explanations.
|
||
</p>
|
||
|
||
<p>
|
||
Keep only relevant context (e.g., “RFC 2045” reference is fine, not the full spec).
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org99e4520" class="outline-4">
|
||
<h4 id="org99e4520">Inobvious Connection</h4>
|
||
<div class="outline-text-4" id="text-org99e4520">
|
||
<p>
|
||
Ensure the relationship between comment and code is clear.
|
||
</p>
|
||
|
||
<p>
|
||
Don’t make readers guess what part of the code the comment refers to.
|
||
</p>
|
||
|
||
<div class="org-src-container">
|
||
<pre class="src src-java">
|
||
<span class="org-comment-delimiter">// </span><span class="org-comment">plus filter bytes ... but which part is “filter”?
|
||
</span><span class="org-keyword">this</span>.pngBytes = <span class="org-keyword">new</span> <span class="org-type">byte</span>[((<span class="org-keyword">this</span>.width + 1) * <span class="org-keyword">this</span>.height * 3) + 200];
|
||
|
||
</pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org856f330" class="outline-4">
|
||
<h4 id="org856f330">Function Headers</h4>
|
||
<div class="outline-text-4" id="text-org856f330">
|
||
<p>
|
||
Short, single purpose functions with good names don’t need header comments.
|
||
</p>
|
||
|
||
<p>
|
||
Let the function name explain the purpose.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div id="outline-container-org080d921" class="outline-4">
|
||
<h4 id="org080d921">Javadocs in Nonpublic Code</h4>
|
||
<div class="outline-text-4" id="text-org080d921">
|
||
<p>
|
||
Javadocs are useful for public APIs, but excessive formality in internal code is just noise.
|
||
</p>
|
||
|
||
<p>
|
||
Internal methods should be self explanatory without full doc comments.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div id="postamble" class="status">
|
||
<footer>
|
||
<div class="copyright-container">
|
||
<div class="copyright">
|
||
Copyright © 2022-2025 Zaine Qayyum. All rights reserved unless otherwise noted.</div></div>
|
||
<div class="generated">
|
||
Created with <a href="https://www.gnu.org/software/emacs/">Emacs</a> 30.1 (<a href="https://orgmode.org">Org</a> mode 9.7.11) on <a href="https://www.archlinux.org/">Arch</a> <a href="https://www.gnu.org">GNU</a>/<a href="https://www.kernel.org/">Linux</a>
|
||
</div>
|
||
</footer>
|
||
</div>
|
||
</body>
|
||
</html>
|