| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
object?.method?.() is equivalent to if(object && object.method) object.method(), not if(object) object.method(). I think we should not add extra checks to avoid behaviour changes, and it might impact perf.
Sorry, something went wrong.
Yes, thanks for the guidance. |
Sorry, something went wrong.
|
Benchmark run (link may not yet be active): https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/760/ Nevermind.. looks like @mscdex beat me to it. There was a benchmark job running already but I hadn't noticed that it was for the same PR. https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/759/ |
Sorry, something went wrong.
There was a problem hiding this comment.
Performance benchmark results look good! Happy to see us start to make these changes. The one downside is that it'll make backporting a bit more difficult
Sorry, something went wrong.
Sorry, something went wrong.
Yes, and this will make our code easier to read. And I have two questions and would like to know what you think.
|
Sorry, something went wrong.
|
Incremental changes are best. And no, backporting shouldn't hold this up. |
Sorry, something went wrong.
I know what to do now, thanks for your guidance. |
Sorry, something went wrong.
I disagree :) |
Sorry, something went wrong.
When there is a difference of opinion on code style, I think we should look at what the community thinks.
This results in shorter and simpler expressions when accessing chained properties when the possibility exists that a reference may be missing.
// Error prone-version, could throw.
const nameLength = db.user.name.length;
// Less error-prone, but harder to read.
let nameLength;
if (db && db.user && db.user.name)
nameLength = db.user.name.length;
// The above can also be expressed using the ternary operator, which doesn’t exactly help readability
const nameLength =
(db
? (db.user
? (db.user.name
? db.user.name.length
: undefined)
: undefined)
: undefined);
// Still checks for errors and is much more readable.
const nameLength = db?.user?.name?.length; |
Sorry, something went wrong.
PR-URL: #36524 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
PR-URL: #36524 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
| Back | FazBrowse Home | New Git URL |
Checklist