Hacker News new | past | comments | ask | show | jobs | submit login

I'm not gonna claim the conclusion is wrong (or right), but Shoot() is probably not the most compelling example one could try to, well, shoot down.

How about a function like add()? It might mean something like BigInteger.add, or something like List.add, or Set.add, and these could all satisfy the same interface while behaving very differently.




Satisfying the interface was just one of the things the article lists as reasons why breakage is quite implausible. Your example doesn't address the others though.

For example, how did you accidentally get an instance of "Set" in the code path doing arithmetic on "BigInteger" instances, and why didn't that "Set" fail earlier during the other operations that are most likely being performed on the BigInteger (parsing it from a string, doing other arithmetic on it, etc)?


> For example, how did you accidentally get an instance of "Set" in the code path doing arithmetic on "BigInteger" instances, and why didn't that "Set" fail earlier during the other operations that are most likely being performed on the BigInteger (parsing it from a string, doing other arithmetic on it, etc)?

Because I got it as a return value from someone else’s function, and then this was the next thing I did with it.

It’s not hard to come up with everyday examples.


So your code calls a function that is named in a way that indicates it might return a set or an integer (and its parameters make sense in both situations), then you take the return value and add() to it ambiguously, and then you do nothing else with it? You don't loop over it or query it for set membership or pass it to any functions or multiply it?

This is exactly the point of the article. Extremely extremely unlikely.

But if you have a real world example of this, I'm sure the article's author is interested.


> Your example doesn't address the others though.

I wasn't claiming it would. I was just saying Shoot() isn't exactly a common function name that would collide with anything to begin with, so it's a bit of a strawman as an example before you even need to list out multiple criteria. I'm pretty sure I've never written a Shoot() function in my life, let alone worried about it colliding with something. Compared with add(), get(), setValue(), read(), etc. which are incredibly common and thus more realistic candidates. That's all.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: