r/ProgrammerHumor 1d ago

Meme iReplacedItWithABuiltinFunction

Post image
3.2k Upvotes

51 comments sorted by

View all comments

78

u/pyropuschel 1d ago

Is this like "the tests now run a lot faster" because they are broken/deleted?

73

u/Bright-Historian-216 1d ago

if you're curious, literally just replaced a "".join(four ternary if-else statements with a for-loop comprehension) with a repr(...)[12:-2].replace(r"\x00",r"\000")

if you don't speak pythonese, that's just a built-in function to get the string representation of an object, so repr("hello\n") returns "'hello\\n'", then the [] is a slice operator so i shave off the prefix and suffix, then the replace just makes sure that \x00 doesn't bleed into next letters if the next word starts with abcdef or something,

31

u/SpaceCadet87 1d ago

I dunno, I'd appreciate your work if I were there. Compile time performance can stack.

22

u/Bright-Historian-216 1d ago

no i don't think you read it correctly. half a millisecond. and while it does scale linearly, it's for an embedded machine so you'd quicker run out of memory than my contribution would ever be noticeable

11

u/SpaceCadet87 1d ago

Yeah, I read correctly but I had just woken up and I subsequently misread when I double checked.

There's still the principle of the thing.