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 unreachable code #1160

Merged
merged 1 commit into from
Dec 31, 2018
Merged

Remove unreachable code #1160

merged 1 commit into from
Dec 31, 2018

Conversation

davesque
Copy link
Contributor

@davesque davesque commented Dec 13, 2018

Also, remove unnecessary else clause that tends to obscure that problem.

What was wrong?

There was an assert False statement which was unreachable. It was clearly expected that this statement was not supposed to be reached in a "normal" situation. However, I don't think it was realized that the statement could never be reach in any situation.

How was it fixed?

Deleted it.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

Also, remove unnecessary else clause that tends to obscure that code.
@davesque davesque requested a review from carver December 14, 2018 20:05
Copy link
Collaborator

@carver carver left a comment

Choose a reason for hiding this comment

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

Yeah, I feel ambivalent. There are times when I think that having explicit branching and an explicit "unreachable" statement are more robust to future breakage.

In such a short, straightforward method, I see the elegance in the approach with less branching. So then the only thing that bothers me is that it's a pattern elsewhere.

So in my ambivalence, I leave it up to you :) 👍

@davesque
Copy link
Contributor Author

davesque commented Dec 17, 2018

@carver So is the unreachable assert meant to hint that the function should terminate in one of the if branches? If so, that makes more sense.

However, I still do kinda feel like that pattern is confusing. It seems like you'd need to explain it to anyone who encounters it, whereas returning false in the except block or true in the normal function body is clear enough at a glance.

Although it does kinda bother me if the pattern is used elsewhere except here...hmm.

@carver
Copy link
Collaborator

carver commented Dec 17, 2018

@carver So is the unreachable assert meant to hint that the function should terminate in one of the if branches? If so, that makes more sense.

Exactly, that's how I read the unreachable assert.

However, I still do kinda feel like that pattern is confusing. It seems like you'd need to explain it to anyone who encounters it, whereas returning false in the except block or true in the normal function body is clear enough at a glance.

Yeah, this is why I don't feel strongly about it.

Although it does kinda bother me if the pattern is used elsewhere except here...hmm.

It's not used a whole lot, but has become a bit of a pattern. I searched for "unreachable" (which didn't even find this usage, of course), and only found two. I think the explicit message is much better than the blank assert. For example:

if request.param == 'instance':
return web3.eth.account
elif request.param == 'class':
return Account
raise Exception('Unreachable!')

and even better:

else:
raise Exception("Unreachable path: transaction's 'data' is either set or not set")

@davesque
Copy link
Contributor Author

Mkay, concerns noted. Since this is only a few lines of code, I'll go ahead and merge this.

@davesque davesque merged commit 28108ec into ethereum:master Dec 31, 2018
@davesque davesque deleted the unreachable branch January 2, 2019 01:07
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.

2 participants