Mirko Stocker

Detecting and Naming Boolean Parameters

After a recent discussion on the Scala-Internals mailing list on the pros and cons of methods that take boolean arguments, the consensus was that they should always be passed as named arguments. The compiler doesn’t enforce this, so it’s up to us IDE and tools developers to provide a solution. The code-analysis branch for the Eclipse Scala IDE can now warn you of such boolean arguments that are passed to Scala methods:

The warning comes with a quick-fix that inserts the parameter name:

Of course, the competition isn’t sleeping either, the IntelliJ Scala plug-in just got a bunch of new Intentions.

6 Comments

    1. Do you mean why the quickfix is only available for booleans or why boolean arguments shouldn’t be used in APIs? First, I should really make that available for all parameters, that’s a good point 🙂 For why they’re bad in API, it just makes it really hard to use, it’s often better to use an enum or two separate methods.

  1. It may be nice to also have a Quick Fix that introduce a method, i.e.,

    def forceDoSomething() = doSomething(force = true)

    Just saying 🙂

Leave a Comment