this post was submitted on 24 Apr 2024
61 points (98.4% liked)

Programmer Humor

19623 readers
411 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 

Hey folks! I think this request is right up this comm's alley. I'm sure that we all know bogo sort but, what other terrible/terribly inefficient algorithms, software architecture, or design choices have you been horrified/amused by?

I, sadly, lost a great page of competing terrible sorting algorithms, but I'll lead with JDSL as a terrible (and terribly inefficient) software architecture and design. The TL;DR is that a fresh CS guy got an internship at a company that based its software offering around a custom, DSL based on JSON that used a svn repo to store all functions in different commits. The poor intern had a bad time due to attempting to add comments to the code, resulting in customer data loss.

you are viewing a single comment's thread
view the rest of the comments
[–] sus@programming.dev 12 points 7 months ago* (last edited 7 months ago)

slow inverse square root:

float slowinvsqrt(float x)
{
    const long accuracy = 100000000;    // larger number = better accuracy
    if (x <= 0.0f) {
        return NAN;
    }
    if (x == 1.0f) {
        return 1.0f;
    }
    if (x < 1.0f) {
        return 1.0f / slowinvsqrt(1.0f/x);
    }

    int max_power = log(accuracy) / log(x);
    long pow1 = pow(x, max_power - 1);
    long pow2 = pow(x, max_power);
    double current = 1.0;
    double previous = 1.0;

    for (long i = 0; i<10*accuracy; i++) {
        current = sin(current);
        if (i == pow1) {
            previous = current;
        }
        if (i == pow2) {
            return current / previous;
        }
    }
}