this post was submitted on 06 Jan 2025
159 points (85.7% liked)

Programmer Humor

19903 readers
1847 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 2 years ago
MODERATORS
 
top 10 comments
sorted by: hot top controversial new old
[โ€“] [email protected] 38 points 2 days ago* (last edited 2 days ago) (1 children)
#include <vector>
#include <algorithm>

int main() {
    int a;
    std::vector<std::vector<int>> v;
    std::vector<std::vector<int>>::const_iterator it = std::find(v.begin(), v.end(), a);
}

assaults you with 42 errors, C++ templates are a joy ๐Ÿ˜Š

[โ€“] [email protected] 7 points 1 day ago (1 children)

But like...what's the real bug?

[โ€“] [email protected] 14 points 1 day ago

Uninitalized memory (int a; with no assignment) vector of int vectors (IE a dynamic int[][]) and attempting to find a, an int in the vector of vectors of int IE int instead of vector<int>. I think the iterator type is correct but I'm not sure off the top of my head

[โ€“] [email protected] 29 points 2 days ago (1 children)

And the only thing wrong was a missing bracket.

[โ€“] [email protected] 19 points 1 day ago (2 children)

Well don't write 600 lines of code without hitting compile then! You're not writing an essay that has to be handed in once.

The only time I ever "write" more than a few 10s of lines at a time (dev since the 1970s, pro since 1991) is when I'm scaffolding a new application with a code generator, and that usually compiles first time. And source control is revolutionary. Check in stuff that works, then no matter how bad things get you can always just roll back to the last good commit. Unpicking the last few hours without source control is horrible. Been there, done that way too many times.

And even when you do get 700 errors just look at the first few. The rest are most likely junk caused by the compiler not being able to resynchronise with the remainder of the code.

[โ€“] [email protected] 4 points 1 day ago

I once did a project regex search heavy refactor, clicked compile once and made it without a code error. I had several collegues be amazed when I compile and it works on the first shot ๐Ÿ˜…

[โ€“] [email protected] 2 points 1 day ago

Also, if you develop on a Mac, slow disk sync on their modern OSes not picking up the change. Or if you use Docker, it caching a layer that it shouldnโ€™t. The future has weird new problems sometimes.

[โ€“] [email protected] 11 points 1 day ago* (last edited 1 day ago)

I find it commendable that you wrote code so horrible other libraries started throwing more errors wondering what the hell you were doing.

[โ€“] nous 13 points 1 day ago

Protip: Don't write 600 lines of code without ever testing it at all. And by testing I mean anything, manual testing included or even just compiling it or running a linter over it. Do things incrementally and verify things at each step to make sure you are not drifting off course by some faulty assumption you made near the start.