Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Modeling paged and segmented memories is tricky business. -- P. J. Denning


devel / comp.lang.java.programmer / What Makes for Good Comments? (Part 2 of 4)

SubjectAuthor
o What Makes for Good Comments? (Part 2 of 4)Wayne

1
What Makes for Good Comments? (Part 2 of 4)

<tbq1b6$29ngf$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=436&group=comp.lang.java.programmer#436

  copy link   Newsgroups: comp.lang.java.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: wayne@nospam.invalid (Wayne)
Newsgroups: comp.lang.java.programmer
Subject: What Makes for Good Comments? (Part 2 of 4)
Date: Tue, 26 Jul 2022 20:36:53 -0400
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <tbq1b6$29ngf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Jul 2022 00:36:54 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="abd7aa2f3b09ccc69a866bc1ab9686ab";
logging-data="2416143"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/9Ghi6IExBlI0713EQ/CVAFcQogmLgpQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.0.3
Cancel-Lock: sha1:at7Rm4KRQ8oo1fPRQI8ERhmRww8=
Content-Language: en-US
 by: Wayne - Wed, 27 Jul 2022 00:36 UTC

Why Comments

Why comments refer to the reasons for writing the code in a particular way. A
why comment is for explaining a particular implementation decision or the
programmer’s intent, especially if it’s not the “obvious” design choice. If
the obvious choice is to use an int but you use a double or (even stranger) a
String, a why comment is useful.

There can be many reasons why some code was written in a non-obvious way. Some
examples include formulas that were rearranged to reduce round-off error or to
avoid overflow, code you are not allowed change, and code requiring
non-intuitive design for security reasons (say to eliminate side-channel
attacks). (A poor reason is trying for extra performance.)

Why comments are also used to document the reasons for the code, often listing
a reference to an issue (or ticket) in some issue-tracking system. Comments
for bug fixes generally go in the testing code, not the application code.
(When fixing bugs, you first add a failing test then fix the code. The bug fix
comment belongs with the test code.)

Here’s an example of a good why comment, adapted from Robert Martin’s Clean
Code (p. 59):

// The following trim is required, since it
// removes leading space that would cause the
// the item to be recognized as another list:
String listItemContent = match.group(3).trim();

(Some why comments are too long to mix with the code and can be kept in a
separate "design notes" text file.)

Feedback welcome!

--
Wayne

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor