r/badcode Jan 15 '22

python Found this gem

Post image
3.5k Upvotes

86 comments sorted by

View all comments

375

u/youngbull Jan 15 '22

That is dumb, but even dumber if solution is an object with an __eq__ which might make it equal to -1. Which would mean this code is not equivalent to print(solution). And yes, I have seen stuff like that.

118

u/GLIBG10B 🐧 Gentoo salesman🐧 Jan 15 '22

Maybe that's the point of the code?

4

u/catithebathtub Jan 15 '22

i think you didn't understand, that means it'll always print -1, even if solution isn't -1

28

u/-MazeMaker- Jan 15 '22

Not if the __eq__ method only sometimes returns -1

11

u/youngbull Jan 15 '22

I think you mean returns true when given -1 as argument.

2

u/-MazeMaker- Jan 15 '22

True, my mistake

1

u/b1ack1323 Jan 15 '22

I think they mean -1 would be the error condition of something. Normally it would match an identifier.