else:no need to use else#17057
else:no need to use else#17057Johnsavadkuhi wants to merge 1 commit intonodejs:masterfrom Johnsavadkuhi:patch-2
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. |
apapirovski
left a comment
There was a problem hiding this comment.
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 <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
Landed in b98027e |
PR-URL: #17057 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #17057 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
good :
better :