Programming Horror

22 readers
1 users here now

Welcome to Programming Horror!

This is a place to share strange or terrible code you come across.

For more general memes about programming there's also Programmer Humor.

Looking for mods. If youre interested in moderating the community feel free to dm @Ategon@programming.dev

Rules

Credits

founded 1 year ago
MODERATORS
1
34
submitted 1 month ago* (last edited 1 month ago) by ptz@dubvee.org to c/programming_horror@programming.dev
 
 

With modern tools, you have to try very hard to do something stupid, because the tools (rightly) recognize you’re doing something stupid. [Andreas Karlsson] can speak to that first hand as he tried to get four billion if statements to compile.

You may ask what state space requires four billion comparisons to evaluate? The answer is easy: the range of an unsigned 32-bit integer. The whole endeavor started with a simple idea: what if instead of evaluating whether an integer is even or odd with a modulo or bit mask, you just did an if statement for every case? Small ranges like 0-10 are trivial to write out by hand, but you reach for more automated solutions as you pass 8 bits and move towards 16. [Andreas] wrote some Python that outputs a valid C program with all the comparisons. For 16 bits, the source only clocks in at 130k lines with the executable less than 2 MB.

Of course, scaling to 32 bits is a very different problem. The source file balloons to 330 GB, and most compilers barf at that point. Undeterred, [Andreas] modified the Python to output x86_64 assembly instead of C. Of course, the executable format of Windows (PE) only allows executables up to 4 GB, so a helper program mapped the 40 GB generated executable and jumped into it.

What’s incredible about this whole journey is how performant the program is. Even large numbers complete in a few seconds. Considering that it has to thrash 40 GB of an executable through memory, we can’t help but shake our heads at how even terrible solutions can work.

2
 
 
3
 
 

I have no idea how to title this post. Oh well.

A few years back I worked somewhere that had a large breach. Many practices changed in the wake of it. Developers actually had admin access prior to the change which was very nice. In an effort to restrict access but also let folks do their jobs they deployed some tool that would start all programs that "needed" admin access as an admin. This included cmd for the devs. So every time I opened cmd I had to be careful not to break something since there was no way to launch it without admin access after that change.

4
 
 

cross-posted from: https://lemm.ee/post/36467447

I am not allowed to credit the site that has this disaster. Its owner said "Nobody should see that"

5
 
 
6
12
C++23 has fixed space! (kbin.melroy.org)
submitted 6 months ago* (last edited 6 months ago) by Aatube@kbin.melroy.org to c/programming_horror@programming.dev
 
 
7
6
float as table id (twitter.com)
submitted 8 months ago* (last edited 8 months ago) by drsensor@programming.dev to c/programming_horror@programming.dev
 
 

8
 
 

I was looking through various RCON tools and found this. Someone does not like commit messages.

9
 
 

Jesus Christ, just add an if statement for even or odd!

10
 
 
11
 
 
12
 
 
13
 
 

what do i do in this position ?

14
15
 
 
16
17
18
 
 
19
 
 

no words

20
21
 
 
22
 
 
23
 
 
24
 
 
  • This file is over 20k lines long, and 400kB

  • It is nested over 10 levels deep in many places

  • There is no naming consistency. The original file used BEM, but now it switches randomly between whatever the devs felt like at the time. There are random contractions all over the place (eg, a parent container might have the class payment-items, but the children are p-item)

  • There is no style consistency. It switches randomly between kebab case, camel case, snake case, a mix of kebab and snake case (!!) or no case at all (just one long word with no separators). A parent element might use one case, but then the child element will use a different case for the exact same term

25
 
 
view more: next ›