-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Remove most of the use of else after return
from JS library code. NFC
#17450
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
Conversation
The code size benefits don't really show here because we don't include most of these JS libraries as part of our codesize tests (perhaps we should measure the size of |
src/library_egl.js
Outdated
@@ -645,12 +643,12 @@ var LibraryEGL = { | |||
eglGetCurrentSurface: function(readdraw) { | |||
if (readdraw == 0x305A /* EGL_READ */) { | |||
return EGL.currentReadSurface; | |||
} else if (readdraw == 0x3059 /* EGL_DRAW */) { | |||
} | |||
if (readdraw == 0x3059 /* EGL_DRAW */) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find else-if actually easier to read for a thing like this, where it's a series of ifs on the same thing. Do you disagree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe marginally easier to read in some cases. But I think that benefits outweigh the costs:
- less code
- less indentation
- Single rule for all cases ("else after return is always wrong") keeps things simple.
Since tidying up this stuff in various places I've trained my self to see else after return a code smell, so for me the old code now looks wrong :)
src/library_egl.js
Outdated
@@ -645,12 +643,12 @@ var LibraryEGL = { | |||
eglGetCurrentSurface: function(readdraw) { | |||
if (readdraw == 0x305A /* EGL_READ */) { | |||
return EGL.currentReadSurface; | |||
} else if (readdraw == 0x3059 /* EGL_DRAW */) { | |||
} | |||
if (readdraw == 0x3059 /* EGL_DRAW */) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm happy to revert those 3 cases for now, if you are OK with the rest of the change landing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel strongly, I guess, if you prefer the other form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted the three places you mentioned..
9fd6dc5
to
9c9398d
Compare
f5d9b1e
to
ccc8f36
Compare
This is small code size win but it looks like it only effects the unoptimized (non-closure) build. Still good coding style anyway. I noticed this while working on #17449 and wrong a little command line to try to find all these: ``` $ pcregrep -n -M 'return[^\n]*;\n\s*}\s*else\s*{' src/*.js ```
ccc8f36
to
f05f835
Compare
This is small code size win but it looks like it only effects the
unoptimized (non-closure) build. Still good coding style anyway.
I noticed this while working on #17449 and wrong a little command line
to try to find all these: