-
Notifications
You must be signed in to change notification settings - Fork 14
Boolean parameters on a call site #21
Comments
IMO this one should be mandatory. Not only there should be an IDE intention to add the clarification comments, but the auto formatter should add them on its own. |
I don't believe that people would appreciate the auto-formatter adding any kind of comments to their code, unless they've explicitly asked for that. |
Yes I understand formatters don't usually do that. The reason for my opinion is that it's super lame to add those by hands |
That is definitely true. :) One option is to make an inspection ("Boolean parameter passed without specifying argument name") and to allow running it through Code Cleanup. |
@voddan actually it's applicable not just for booleans, but for all literals.
Can you remember what all these values mean without peeking into function's declaration? |
@dstd The idea was to actively enforce naming for boolean flags, and leave the rest to the developer. Non-boolean parameters are usually self-explanatory and follow conventions, while bools are always a mystery. An example of multiple
On the other hand the developer is free to name them:
|
Ideally, there should be language feature so that one can mark a parameter as "always use by name". This puts the decision into the hands of a person who designs API. There is already a requirement that parameters after vargas can be invoked by name only, by the way. However, there is also an interop question, e.g. in how one should call existing Java APIs? Booleans are special, indeed. It seems logical, that interop layer shall implicitly mark all Java functions with boolean parameters as "always use by name" if the original name is available in the class file. |
Since IJ 2016.3 has a feature of "Parameter hints", I wonder if the concept of this thread become absolute. |
I think that the example @voddan gave is a perfect example why this should be applicable to literals, not just booleans.
|
@kevinmost Luckily such conventions as Personally I prefer |
Boolean parameters in a multi-parameter function (boolean flags) must be marked on a call site to clarify their meaning. In for Kotlin functions use named parameters. For Java functions use inline comments since named parameters are prohibited (v1.0):
or
This is not applicable when the boolean parameter is not a boolean flag (e.i. it's the only non-optional parameter or it's a boolean vararg):
The text was updated successfully, but these errors were encountered: