• Gavin (unregistered)

    Maybe, just maybe, although highly unlikely, isEnabled() on the parent class is private? Maybe it doesn't return a boolean? Maybe I'll also win the lottery one day.

  • Latengo (unregistered)

    On the contrary. This is an excellent piece of code which does its job perfectly.

    It says:

    1. If 'super' says it isn't enabled, say we are not enabled.
    2. Perform any further tests which may lead to this object being disabled, and return 'false' if any of them says that it is disabled. In the given sample, 0 lines are dedicated to this.
    3. If there are no remaining impediments, say we are enabled.

    The proposed single return statement obfuscates this process and makes it unclear how to add the extra tests; or that they need to be added.

    The proposed removal conceals, from an eventual maintainer, the fact that an isEnabled test is needed at all.

    The only rational approach is (1) to leave this hygienic code as it is, as insurance for the future, perhaps with a comment saying "Insert additional tests here" - or (2) remove the class altogether.

  • (nodebb)

    Best case, the person who wrote this function did have a use case at some point, but it was removed before they committed it to the source control. Like something in this class would have this function return true even if the super class would return false, but before they committed the code that would allow that edge case, it was removed and the person just forgot to remove this function, and now there's bad code smell.

    Worse case (and most likely) this function is in every class in which there's a isEnabled function, and whoever started it just wanted to allow other classes to allow it to return true even if the super class might return disabled.

  • witchdoctor (unregistered)

    I've seen something like this where the function was protected on the base class and made public in the override. That also smells and would be really strange for a getter method like this though.

  • Conradus (unregistered)

    Bonus points for using negation to invert the conditional to make it extra confusing.

  • (nodebb)

    I can think of one case where the existence of this method is potentially actually useful: when using AspectJ to intercept the method and do complicated things. The method weaver might actually care about that. Or it might be more correctly implemented; it's hard to be sure without setting up a project. That said, if your codebase has and needs that level of trick, you need to go for a long walk in the country and reconsider the decisions that have lead your life to that point.

    AspectJ is a level of trickiness that virtually all Java programmers should avoid. Proper scripting languages are better. (So too is the restricted weaver that Spring uses when it has interfaces available.)

  • (nodebb)

    This is awful: Remy has a new picture.

    What happened to the time-worn practice of using pictures from twenty years ago, and then never updating them?

  • (author) in reply to PotatoEngineer

    The old one was only ten years old!

  • Fizzlecist (unregistered) in reply to Remy Porter

    Clearly it has at least another 10 years of life in it then ;)

  • Jeremy (unregistered)

    They should have used a ternary. It would make it so much better

  • (nodebb)

    Obviously, this was put in place so that the developer could easily place a breakpoint when this particular class was not enabled…

    Just calling the super method directly wouldn’t do it; you’d need a conditional breakpoint.

    An override is required; otherwise, the other descendants of the superclass would also trigger the breakpoint.

    Should have been removed before committing though!

  • Chris O (unregistered)

    That looks like a function that was written because the developer thought 'there MIGHT be a time when we want to do some additional work here so we'll account for that now'. Anyone who hasn't worked with someone like that at some point isn't being sincere :)

Leave a comment on “Disable This”

Log In or post as a guest

Replying to comment #:

« Return to Article