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

Tiny suggestion : remove Redundant-null-check on "Shell.java" #16

Closed
AndroidDeveloperLB opened this issue Jun 20, 2014 · 6 comments
Closed

Comments

@AndroidDeveloperLB
Copy link

running some warnings checks of Eclipse, I've found a warning of a redundant-null-check :

            Boolean enforcing = null;

            // Detect enforcing through sysfs, not always present
            if (enforcing == null) {

this should be removed.

@Chainfire
Copy link
Owner

Its part of several checks each of which begin with this. It's a code-style-preference thing. I prefer it to be this way, redundant or not.

@AndroidDeveloperLB
Copy link
Author

I don't understand.
Why would you check if something is null, if you know for a fact that it must be null?

@Chainfire
Copy link
Owner

Because in cases like these the blocks below that check and set this variable tend to get switched around and cases added over time. Keeping the check there will prevent the logical failure that will occur when the blocks are copy/pasted to change order. There's no technical reason for this, I just prefer it this way as it prevents a possible future logic failure and is clearer to read (imho). Feel free to disagree, I feel free to not care. The compiler/optimizer will take it out anyway if it is redundant.

@AndroidDeveloperLB
Copy link
Author

So you keep a check because you might move the block of code to somewhere else?
But you've already set it to be in a safe place...
For making it safer to move around, you could just put it in a function. It's one of the purposes of functions...
Another alternative is to just comment this code.
In the current situation, it just adds more code to read, so I don't get why it's more readable.
For me, removal of redundant code, as well as commented code (especially old one) makes the code more readable. The less to read, the less time it takes to read.
Plus here you made me wonder why it exists this way, so I thought maybe it's a possible bug in the code that should be taken care of...

Anyway, I will just turn off this warning for this library.
Thanks for helping out.

@Chainfire
Copy link
Owner

Stop trying to debate preference. This is exactly why I dislike open source. I have better things to do than discussing this - it's certainly not like we're ever going to agree on it, and worse, it really doesn't matter.

@AndroidDeveloperLB
Copy link
Author

OK OK.
I've already wrote : I will just turn off this warning for this project.

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

No branches or pull requests

2 participants