Code is hard to read when you use tricky names with no semantics or rely on accidental language complexity.
TL;DR: Don't try to look too smart. Clean code emphasizes readability and simplicity.
Problems π
- Readability
- Maintainability
- Code Quality
- Premature Optimization
Solutions π
- Refactor the code
- Use good names
- Refactor tricky code
- Prefer clarity first
- Avoid hidden tricks
- Optimize only later with strong real evidence
Refactorings βοΈ
https://hackernoon.com/refactoring-005-replace-comment-with-function-name?embedable=true
Examples
- Optimized loops
Context π¬
You might feel the urge to show off your skills with complex tricks or cryptic names.
This makes your code harder to read, debug, and extend.
You must remember that you write code for humans, not machines.
Sample Code π
Wrong π«
function primeFactors(n) {
var f = [], i = 0, d = 2;
for (i = 0; n >= 2; ) {
if(n % d == 0) {
f[i++]=(d);
n /= d;
}
else {
d++;
}
}
return f;
}
Right π
function primeFactors(numberToFactor) {
var factors = [],
divisor = 2,
remainder = numberToFactor;
while(remainder>=2) {
if(remainder % divisor === 0) {
factors.push(divisor);
remainder = remainder / divisor;
}
else {
divisor++;
}
}
return factors;
}
Detection π
- [x]Semi-Automatic
Automatic detection is possible in some languages.
Look for warnings about complexity, bad names, post-increment variables, and similar patterns.
Exceptions π
- Optimized code for low-level operations.
Tags π·οΈ
- Complexity
Level π
- Intermediate
Why the Bijection Is Important πΊοΈ
When you keep a clear bijection between your program and the MAPPER.
Other developers and your future self can understand it quickly.
Clever tricks break this mapping and force future readers to guess instead of reading.
AI Generation π€
AI models sometimes generate clever one-liners or compressed solutions.
They might look smart but lack readability and semantics.
AI Detection π§²
AI assistants can rewrite clever code into readable code if you instruct them to prefer clarity to optimization.
Try Them! π
Remember: AI Assistants make lots of mistakes
Suggested Prompt: correct=Remove cleverness from code
Without Proper Instructions |
With Specific Instructions |
---|---|
Conclusion π
Clever developers write cryptic code to brag.
Smart developers write clean code.
Clear beats clever.
Relations π©ββ€οΈβπβπ¨
https://hackernoon.com/code-smell-02-dont-let-mysterious-numbers-rule-your-code
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-iv-7sc3w8n
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-ix-7rr33ol
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-ix-7rr33ol
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xvi
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xi-sit35t1
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-vii-8dk31x0
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-x-i7r34uj
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxxx
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-v-evj3zs9
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xix
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxix
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xliii
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxxvi
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xxvi
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-vii-8dk31x0
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-v-evj3zs9
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-v-evj3zs9
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-xiv
More Information π
https://ardalis.com/are-boolean-flags-on-methods-a-code-smell/?embedable=true
Also Known as
- Obfuscator
Credits π
Photo by NeONBRAND on Unsplash
Programming can be fun, so can cryptography; however they should not be combined.
Kreitzberg & Shneiderman
https://hackernoon.com/400-thought-provoking-software-engineering-quotes
This article is part of the CodeSmell Series.
https://hackernoon.com/how-to-find-the-stinky-parts-of-your-code-part-i-xqz3evd?embedable=true