Code That Made Me Cry, #CTMMC™

95% of all code makes me cry. The other 5% are white space.

Range Checking (PHP, #6 / 50)

function minutes ($minutes) {
        if ($minutes < 8 ) $minutes = 0;
        elseif ($minutes > 7 && $minutes < 23) $minutes = 15;
        elseif ($minutes > 22 && $minutes < 38) $minutes = 30;
        elseif ($minutes > 37 && $minutes < 53) $minutes = 45;
        else $minutes = 0;
        return $minutes;
}        

This coder has split hours in chunks of 15 minutes. Then his manager arrives and tells them to make chunks of 10 minutes. Then 20 minutes. Then 30, 6, 5 minutes. How often will they manually pre-calculate the ranges within an hour??

Source: https://sheriframadan.com/2011/04/why-programmers-write-bad-code/

comments powered by Disqus

Submit your own Code That Made You Cry

Send us your own example of code that made you cry! Please include:

Send the above to ctmmc@datageekery.com. All accepted submissions will be licensed as CC BY-SA 3.0. Submit only code of a compatible license.

Note that we may choose not to publish some submissions if we feel they're not appropriate. We hope you understand.

Don't let your SQL code make you cry!

Use jOOQ, instead of JDBC.

jOOQ generates Java code from your database and lets you build typesafe SQL queries through its fluent API.

Don't let your SQL code make you cry! Get back in control of your SQL with jOOQ.