This is a 100% theoretical question and, possibly, an opinion is based.
In a professional interview, I got a printed page with a lot of badly written and incorrectly formatted code for two class es to analyze them line by line in speech. Let me name these data structures A and B There was no problem or any information about the expected behavior.
However, one of their questions really pissed me off.
After identifying the suspicious behavior of the algorithm and many potential and actual errors, they asked me to identify another error. I identified several other obvious problems, but I did not understand what they want from me. Well, when they told me the answer, it blew my mind. A simplified version of A and B follows (I left only those methods that are part of their idea):
template <typename T> class A { public:
Well, the solution is not a compilation, runtime, or logical error. Error: since B::setValue sorts the data after the item is placed, you cannot check if the data that you receive at this position is available is the same as what you saved at this given position. However, with A you can do this. This unsurpassed behavior between A and B is considered a mistake (and they added that this is not a mistake, but still this is a mistake).
I think this is completely a design choice (since the whole point of B is to support sorted data), and I would not say that this is a mistake, especially without reporting a problem or any information about the expected behavior. This does not even violate the idea or concept of polymorphism.
Could you identify it as a mistake?
source share