-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
else:no need to use else #17057
else:no need to use else #17057
Conversation
good : if (engine._info) return { buffer, engine }; else return buffer; better : if (engine._info) return { buffer, engine }; return buffer;
-0 on this, I find the explicit else more readable, especially as the if doesn't have braces. @Johnsavadkuhi why do you think it's better? |
If we decide the style proposed here is better, we can use an ESLint's no-else-return rule to enforce it. No opinion either way from me on this. |
first , thank you a lot because of creating Nodejs for us. in my opinion creating professional code helps to other programmers to improve their programming skills also i think every programmer clearly know that return statement destroy function life and without else , readability still is good every programmer know the result is not "hello" function x ( ){
if (true )
return ;
console.log("hello") ;
} and then : function y ( ) {
if (true )
return ;
else
console.log("hello") ;
} which is better ? it is simple code and both are good and the second is more readable for beginner programmer not for professional and we know a beginner have to learn more and practice more and more let me to show you a code in zlib.js function createConvenienceMethod(ctor, sync) {
if (sync) {
return function(buffer, opts) {
return zlibBufferSync(new ctor(opts), buffer);
};
} else {
return function(buffer, opts, callback) {
if (typeof opts === 'function') {
callback = opts;
opts = {};
}
return zlibBuffer(new ctor(opts), buffer, callback);
};
}
} without else : function createConvenienceMethod(ctor, sync) {
if (sync) {
return function(buffer, opts) {
return zlibBufferSync(new ctor(opts), buffer);
};
}
return function(buffer, opts, callback) {
if (typeof opts === 'function') {
callback = opts;
opts = {};
}
return zlibBuffer(new ctor(opts), buffer, callback);
};
} which is better and shorter ? i think the second is better because is shorter and less Braces |
... |
No one has voiced a strong objection. (@gibfahn was a I'm neutral on this myself. I don't care one way or the other, but I do prefer consistency across the code base. So whatever is decided, I hope we can enforce with a lint rule. I suppose that would slightly favor this change, since the lint rule enforcing this style exists and could be deployed. |
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 would like to see this land because it's an eslint rule I want to enable but currently there are way too many instances that need to be fixed. If we can make a dent via this and potentially code-and-learn type of tasks, then that would make it a bit more bearable.
PR-URL: #17057 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]>
Landed in b98027e |
PR-URL: #17057 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]>
PR-URL: #17057 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]>
good :
better :