this post was submitted on 22 Jul 2024
85 points (97.8% liked)

Programming Horror

1891 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 @[email protected]

Rules

Credits

founded 1 year ago
MODERATORS
 
top 14 comments
sorted by: hot top controversial new old
[–] [email protected] 23 points 4 months ago

Now please publish it as a Node.js module and in 3 weeks, it will be in Top 10 most used modules, being used in 90% of Fortune 500 corporations.

[–] [email protected] 13 points 4 months ago (1 children)

But… does it pass all the tests?

[–] [email protected] 15 points 4 months ago (1 children)

If it does, they don't have enough of the right tests.

[–] [email protected] 3 points 4 months ago (1 children)
[–] [email protected] 6 points 4 months ago* (last edited 4 months ago) (1 children)

What would the output be for the following:

99 Beers on the Wall!

[–] [email protected] 3 points 4 months ago

Or for "CAFÉ"?

[–] [email protected] 7 points 4 months ago* (last edited 4 months ago) (1 children)

This will not work on Unicode

Greek and Arabic have cases as well

[–] [email protected] 5 points 4 months ago (1 children)

This will not work on Unicode

Correct.

Greek and Arabic have cases as well

Who told you that?

[–] [email protected] 7 points 4 months ago

Brain fart, I meant Cyrillic but I wrote the wrong word! Good catch thanks!

[–] [email protected] 4 points 4 months ago (1 children)
[–] [email protected] 8 points 4 months ago* (last edited 4 months ago)

This looks like O(n), because you don't include constants when calculating Big-O. It's still ~26 times slower than the implementation without the inner loop.

~~This looks like O(n^2) because of the sub.~~

I was right the first time. sub is "substring" and not "substitute".

[–] [email protected] 3 points 4 months ago (1 children)

here's a more nuanced question: in school iirc my teacher was implementing terminal 2-human tic-tac-toe with us and used an only slightly less egregious 7-by-3 AND/OR gate to see whether any player had won. because I didn't like all the repetition, my version iterated through a 7-by-3 list of lists of indecies instead. every toy programming problem I've seen since was so general that it didn't go well with this kind of hardcoding either

[–] [email protected] 2 points 4 months ago

When creating an example for beginning programmers, sometimes using a very inefficient data structure is more illustrative and a helpful educational tool.

[–] [email protected] 1 points 1 month ago* (last edited 1 month ago)

Honestly as long as literals are properly converted, I don't see any other way to do this in an entirely encoding agnostic way