https://wiki.klenwell.com/mediawiki/index.php?title=Code_Smells&feed=atom&action=history
Code Smells - Revision history
2024-03-29T14:06:22Z
Revision history for this page on the wiki
MediaWiki 1.32.1
https://wiki.klenwell.com/mediawiki/index.php?title=Code_Smells&diff=275&oldid=prev
Klenwell: /* Fluff Terms */
2020-10-22T00:09:17Z
<p><span dir="auto"><span class="autocomment">Fluff Terms</span></span></p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #222; text-align: center;">Revision as of 00:09, 22 October 2020</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l21" >Line 21:</td>
<td colspan="2" class="diff-lineno">Line 21:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Bad Variable Name</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Bad Variable Name</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">affiliated_exchange_disclosure_step_file_handling</del></div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">service_disclosure_step_file_handling</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Good Variable Name</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Good Variable Name</div></td></tr>
<tr><td class='diff-marker'>−</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del class="diffchange diffchange-inline">affiliated_letter_upload_step</del></div></td><td class='diff-marker'>+</td><td style="color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins class="diffchange diffchange-inline">service_disclosure_upload_step</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Bad Endpoint Path</div></td><td class='diff-marker'> </td><td style="background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div># Bad Endpoint Path</div></td></tr>
</table>
Klenwell
https://wiki.klenwell.com/mediawiki/index.php?title=Code_Smells&diff=274&oldid=prev
Klenwell: Created page with "== Overview == ''A code smell is a surface indication that usually corresponds to a deeper problem in the system.'' — [https://martinfowler.com/bliki/CodeSmell.html Mart..."
2020-10-21T20:52:07Z
<p>Created page with "== Overview == ''A code smell is a surface indication that usually corresponds to a deeper problem in the system.'' — [https://martinfowler.com/bliki/CodeSmell.html Mart..."</p>
<p><b>New page</b></p><div>== Overview ==<br />
''A code smell is a surface indication that usually corresponds to a deeper problem in the system.'' &mdash; [https://martinfowler.com/bliki/CodeSmell.html Martin Fowler]<br />
<br />
For a general list of common smells, see Jeff Atwood's [https://blog.codinghorror.com/code-smells/ article on code smells]. <br />
<br />
== Common Odors ==<br />
=== Dead Code ===<br />
Just delete it. Version control will allow you to bring it back from the grave. If you wish to save it for future reference, bookmark a commit where it can be found.<br />
<br />
=== Fluff Terms ===<br />
Fluff terms are those little redundant words that end up variable names or method names or even URLs. <br />
<br />
Examples:<br />
<br />
<pre><br />
# Bad Method Name<br />
accounts_information = user.accounts_information_from_service<br />
<br />
# Good Method Name<br />
service_accounts = user.accounts_from_service<br />
<br />
# Bad Variable Name<br />
affiliated_exchange_disclosure_step_file_handling<br />
<br />
# Good Variable Name<br />
affiliated_letter_upload_step<br />
<br />
# Bad Endpoint Path<br />
/api/v1/user/basic_info/:id<br />
<br />
# Good Endpoint Path<br />
/api/v1/user/:id<br />
</pre><br />
<br />
See also the [https://blog.codinghorror.com/code-smells/ Type Embedded in Name] smell cited by Jeff Atwood:<br />
<br />
''Avoid placing types in method names; it's not only redundant, but it forces you to change the name if the type changes.''<br />
<br />
For some good advice on naming methods, see [http://codelegance.com/semantic-method-naming/ Semantic Method Naming].<br />
<br />
=== Lurking Variables ===<br />
These are long or complex conditions or expressions that could be clarified with an [http://c2.com/ppr/temps.html#4 explaining temporary variable].<br />
<br />
See also this [https://softwareengineering.stackexchange.com/a/167780 StackExchange answer].<br />
<br />
=== Magic Values ===<br />
Magic values are unique or distinctive values buried in code. As [https://en.wikipedia.org/wiki/Magic_number_(programming)#Unnamed_numerical_constants Wikipedia states], "The use of unnamed magic [constants] in code obscures the developers' intent in choosing that value, increases opportunities for subtle errors (e.g. is every digit correct in 3.14159265358979323846 and is this equal to 3.14159?) and makes it more difficult for the program to be adapted and extended in the future."<br />
<br />
Prefer constants or configuration settings.<br />
<br />
=== Silent Errors ===<br />
Silenced or swallowed errors can be an intense source of pain when trying to debug an issue. This article covers the topic well and is strongly recommended:<br />
<br />
* https://realpython.com/the-most-diabolical-python-antipattern/<br />
<br />
Also understand the advantages of "failing fast":<br />
<br />
* https://en.wikipedia.org/wiki/Fail-fast#Hardware_and_software<br />
<br />
In short, when in active development, fail fast and loud.<br />
<br />
=== String Concatenation ===<br />
Prefer interpolation.<br />
<br />
For guidance in Ruby, see the [https://github.com/rubocop-hq/ruby-style-guide#strings Rubocop Ruby Style Guide].<br />
<br />
For PHP, prefer formatting with <tt>sprintf</tt>.<br />
<br />
<pre>// Bad<br />
$auth_url = $this->auth::INFS_OAUTH_URL . '?client_id=' . $this->auth->get_client_id() . '&response_type=code&scope=full';<br />
<br />
// Good<br />
$url_f = '%s?client_id=%s&response_type=code&scope=full';<br />
$auth_url = sprintf($url_f, $this->auth::INFS_OAUTH_URL, $this->auth->get_client_id());</pre><br />
<br />
=== Unguarded Nested Conditional Clauses ===<br />
See https://refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html.<br />
<br />
== Tests ==<br />
==== Ambiguous Tests ====<br />
Use <tt>expects</tt> pattern in test names and organize test methods around clear coherent, if not [http://www.betterspecs.org/#single singular], expectations.<br />
<br />
==== Disorganized Tests ====<br />
Use the [http://wiki.c2.com/?ArrangeActAssert AAA or AAAA pattern]:<br />
<br />
<pre># Arrange<br />
<br />
# Assume<br />
<br />
# Act<br />
<br />
# Assert</pre><br />
<br />
== Surprises ==<br />
Understand and apply the [https://en.wikipedia.org/wiki/Principle_of_least_astonishment Principle of Least Surprise (POLA)]. If a reasonable developer reading your code will be surprised or have a questions, you probably want to add a code comment.<br />
<br />
Related is the concept of [https://www.interaction-design.org/literature/book/the-glossary-of-human-computer-interaction/affordances affordances], popularized by Donald Norman in [https://en.wikipedia.org/wiki/The_Design_of_Everyday_Things The Design of Everyday Things]. It's also worth understanding as a developer.<br />
<br />
== Deodorizers ==<br />
* [https://github.com/rubocop-hq/rubocop Rubocop]<br />
* [https://github.com/squizlabs/PHP_CodeSniffer PHP CodeSniffer]<br />
<br />
== References ==<br />
* https://martinfowler.com/bliki/CodeSmell.html<br />
* https://blog.codinghorror.com/code-smells/<br />
* https://en.wikipedia.org/wiki/Code_smell</div>
Klenwell