← Back to context

Comment by AdieuToLogic

21 hours ago

> You almost never see a list of banned Java features ...

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...

I've never heard of that being banned. It hasn't been banned anywhere i've written Java.

  • Similarly I never been in a company that outright banned c++ language of library features[1]. Turns out that different companies are different.

    [1] I guess you would get some push back at review time if you used auto_ptr.

Never seen this being banned. Whats the reason?

  • If you have to ask an object what its type is, you're probably about to cast it, and these are operations that the language doesn't enforce that you do together (and so the habit of casting can lead to the habit of casting without the check...). There are times when it's appropriate but generally if you have to ask what type an object is, your code is already starting to smell (because typically dispatching on type is handled by polymorphism, not be the programmer manually implementing it).