Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.
def execute(parameterName : scala.Boolean = { /* compiled code */ })

When calling this method, you can go with

someobject.execute(true)

or

someobject.execute(parameterName = true)

If you use the former, IntelliJ pops up a recommendation stating that Boolean arguments should be named. But doesn't this introduce an unnecessary dependency on the name of the parameter? Essentially the name of the parameter becomes part of the interface.

If I then change the name of parameterName in execute() to something else, I potentially break a lot of code that is using the execute method.

I understand that it improves readability a bit (you can look at the code and see which Boolean is being set to true without having to look at the called method). But is it enough of an advantage?

share|improve this question

closed as off-topic by svick, Vedran Šego, Yuushi, Jeff Vanzella, Nikita Brizhak Sep 27 '13 at 5:44

If this question can be reworded to fit the rules in the help center, please edit the question.

    
This is really a question for the Programmers affiliate site. You're asking about a concept, with single line examples, not for a review of some functioning code. You'd get more attention and better answers on the Programmers site, as well. Mind you, you'd probably also find the question closed, because it has been asked so many times before. stackoverflow.com/questions/1240739/… programmers.stackexchange.com/questions/147977/… –  itsbruce Sep 26 '13 at 21:53
    
Noted about using Programmers - but the questions you've linked aren't really the same. This is about the best practice of calling a function with a boolean variable, not a question as to whether the boolean should be there in the first place. –  Ren Sep 26 '13 at 23:17
4  
This question appears to be off-topic because it does not actually ask for review of code. –  svick Sep 26 '13 at 23:24

2 Answers 2

up vote 3 down vote accepted

IDEA's Scala plugin has always been lacking quality compared to other products of Jetbrains. The company develops a direct competitor language to Scala named Kotlin, so I think it's simply an issue of their priorities. In a couple of years of posting dozens of bugs related to Scala plugin on their tracker I've grown accustomed not to trust anything that this plugin says or does.

Your case is an example of how it tries to be too smart. You've given a good enough reason to report this on their bugtracker, and, of course, not to follow that ridiculous advice.

share|improve this answer
2  
The Eclipse Scala IDE does the same thing, fyi. misto.ch/detecting-and-naming-boolean-parameters –  itsbruce Sep 26 '13 at 21:47
    
Good point. Although I still believe that it's quite a ridiculous suggestion. –  Nikita Volkov Sep 26 '13 at 21:56
    
It's a bit like the grammar checker in Word, which always highlights which and that, because they are often misused, without being able to detect whether they are actually being misused in this instance. –  itsbruce Sep 26 '13 at 21:58

Personally, I think it's a reasonable suggestion.

  • If you change the parameter name in a way that changes its meaning, it's a good thing that the code using the old name doesn't compile anymore.
  • If you change the parameter name, keep the meaning the same and all your code is in the same solution, then your IDE should be able to rename all usages at the same time.
  • If you change the parameter name, keep the meaning the same, but your code is not all in the same solution (e.g. when you're writing a library used by third parties), then somebody could be using this practice, no matter what you use. So, the name is already part of the interface, no matter what you use.

There is a middle ground where all your code is not in the same solution, but you have control over all of it (e.g. by specifying coding guidelines for your company). In this case, you might decide that it's an unnecessary dependency. But in all the other cases, I think that using named parameter often makes sense.

share|improve this answer
2  
I'd argue with your points. If a function's parameter changes its meaning it's a sure sign that the function does a different thing, which means that it's rather more appropriate to change the function's name instead. Depending on IDE to keep a project manageable can't be a good idea either. IMO this whole thing is an example of an overcomplication without any real practical benefit. –  Nikita Volkov Sep 27 '13 at 0:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.