Every programmer knows these moments. You come across those few lines of code that make you think: "Whoops…". Or better: "Wat." Most often this code is the result of crazy deadlines or massive refactoring of other parts of the application – or just simple stupidity.
Sometimes this code is your own.
In order to share these great moments with you, I decided to start a series I'd like to call Crappy Code. Should you ever run into any code that you think could fit this category, feel free to send me a mail to crappycode(at)npruehs(dot)de.
Let's start right away with this little jewel: The first part of this series is about a piece of Python code that is ought to adapt the size of some buttons to the current display resolution.
This is the pure opposite of a resolution-independent UI. In fact this code has been taken from a game that was originally designed to be played with two resolutions, only: 1024×768 and 1280×800. Unfortunately, I got honored by the task to make the game look somehow good on laptops now, which – who'd have thought – includes other resolutions as well.
Second point: Where do all these strange numbers come from? What the frack is 0.352 * 0.95?
Another thing here is, the author has dublicated code just to insert a multiplication by 0.95. Well, thats one way to increase the number of lines of code.