|
|
|
Ask HN: What do you consider as “bad” code?
|
|
13 points
by JZN666
1607 days ago
|
|
My opinion about this constantly changes through my programming experience. Functions longer than 20 lines of code? Pffff, an algorithm/problem can be such complex in nutshell and decomposing a function solving it will be non-relevant (see any std library of PL). Mutable global state? Pfff, anything in software is based on that, the problem is using it properly in target architecture (ex. in micro-controllers global state usually manages analog/digital output, calling a function for this adds memory and time overhead especially in real-time systems). Copy-paste? Pfff, similar code != this code solves the same problem, sometimes it's easier to include a change in "copy-paste" code than deciding how to include this in boundaries of "reusable" parts (ex. for the first time there're two structures X = (A, B) and Y = (A, B) with similar logic but different domains, and then manager decides to include specific logic for Y working with B data). Now my general principle which distinguishes "good" code from "bad" one, is how good it resembles a model solving given problem. It can be a non-neccessary complexity of code (ex. instead of "if (isFinite(a)) { ... }" writing "if (a.toString() != "Inifinity" && a.toString() != "NaN") { ... }" when "a" is simply a number). And contrary not-enough complexity of code, relying on blind faith (famous XSS vulnerabilities, SQL injections in web apps are examples of that). |
|
Code that relies alot on pointless abstractions (aka. bad "signal to noise ratio").
Code with lots of microdependencies to perform really trivial tasks.
Code with premature "optimizations" (usually done before actual performance measurements).
Code sacrificing readability (and thus maintainability) to be overly clever or to do trivial optimizations (usually with little to no impact on overall performance).
And of course all the different ways to mess up comments, style and versioning (Yes, I consider the versioning part of the code):