(no title)
AdieuToLogic | 1 month ago
The instanceof[0] operator is typically banned from use in application code and often frowned upon in library implementations.
0 - https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.htm...
AdieuToLogic | 1 month ago
The instanceof[0] operator is typically banned from use in application code and often frowned upon in library implementations.
0 - https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.htm...
twic|1 month ago
gpderetta|1 month ago
[1] I guess you would get some push back at review time if you used auto_ptr.
AdieuToLogic|1 month ago
Once code such as the below is rejected in a code review, the next version often submitted is an "if-else-if" ladder using `instanceof` (which is effectively the same thing).
And yes, I have seen the above scenario played out in a professional setting.MrBuddyCasino|1 month ago
blandflakes|1 month ago
AdieuToLogic|1 month ago
> Never seen this being banned. Whats the reason?
Its usage encodes a priori assumptions of what a super-type could be, often expressed in an "if-else-if tree", thus making the logic doing so needlessly brittle and difficult to maintain.
Library logic sometimes needs to use this construct (I'd argue those abstractions need to be rethought however), but an application which does exhibits a failure in domain modelling IMHO.