Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove nullable boolean "idiom" #3818

Merged
merged 1 commit into from
Oct 10, 2023
Merged

Remove nullable boolean "idiom" #3818

merged 1 commit into from
Oct 10, 2023

Conversation

SebastianAigner
Copy link
Member

Open for discussion here @JetBrains/kotlin-technical-writing – I don't understand the original motivation for adding this as a Kotlin "idiom", seeing how this seems like an instance of the tri-state boolean problem.

If there is a reason as to why we're highlighting this as an idiom, I'd appreciate a short explanation – otherwise, it's probably better if it is removed.

@SebastianAigner SebastianAigner requested a review from a team as a code owner October 9, 2023 10:15
Copy link
Member

@koshachy koshachy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @SebastianAigner
Thanks for raising the issue!
This idiom was added long ago, and I can't find any reason why it should be in the documentation.

I agree with you that we should remove it.
Thanks again for pointing this out!
We appreciate it!

@koshachy koshachy merged commit e5419e9 into master Oct 10, 2023
4 checks passed
@koshachy koshachy deleted the SebastianAigner-patch-1 branch October 10, 2023 09:30
@YSakhno
Copy link

YSakhno commented Oct 11, 2023

Frankly speaking, I do not understand why this was removed. This idiom, as it was written, while very trivial, is not obvious. As in, it's hard to come up with it on your own — when someone unfamiliar with the "idom" is hard pressed to use nullable Boolean in an "if" (or otherwise convert nullable Boolean to a non-nullable one), they will most likely write b!! or b ?: false. To me, if (b == true) is more idiomatic than if (b ?: false) (and much, much more idiomatic than if (b!!)).

If your argument was "simply don't use nullable Booleans", then why is it in the language at all? Sometimes you have to use it because it is more convenient, or because such are the constraints of the underlying system.

P.S. I would actually extend this idiom by including the case of defaulting null to true: b != false (although this might be less obvious to the reader than b ?: true).

P.P.S. Also see Detekt's NullableBooleanCheck. Your change will break their rules, because they are referencing the very much idiom you removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants