Comments (7)
cc @Qard
from apm-agent-nodejs.
I've been using const/let in all my personal code for quite awhile now.
The nice thing about const/let is that you can't rebind them in keyword form, so you don't get confusing errors when you accidentally do something like this:
var thing = 1
if (condition) {
var thing = 2
useInternalThing(thing)
}
useExternalThing(thing)
If the var
was let
or const
, it'd throw an error complaining about rebinding. With var
it'll just happily replace the existing reference.
My personal style is to make everything const
until proven it needs to be mutable. Linters are generally pretty good about detecting that and complaining when your code tries to mutate a const
.
The performance issues are largely conditional, the main one being that reassigning a let
in a loop body used to deopt. (NOTE: loop body, not loop condition statements, so that does not include the incrementer component.)
FYI: A simple search and replace wouldn't work as I know there are at least a few cases like if (condition) { var foo = 'bar' }
that would no longer get hoisted out of the block.
from apm-agent-nodejs.
@Qard thanks :) Out of curiosity, do you remember when the let
loop body reassignment issue was fixed? Is that still the case in Node 6 for instance?
I've also started using const
and let
now in my personal code... it took me quite a while 😅
from apm-agent-nodejs.
If I recall correctly, it was fixed in early 6.x releases. I don't remember the exact version, but not 6.0.0.
from apm-agent-nodejs.
We should probably wait with this until we drop support for 4.x.
Would be interesting to get some numbers on this as well: https://twitter.com/stephenbelanger/status/952988762421706753
from apm-agent-nodejs.
Note to self: If we make a PR with these changes, we should benchmark it against master to see if there's any performance gains or degradations
from apm-agent-nodejs.
We agreed to start using let
and const
on new code and refactors. We won't do a major refactor of all the code.
from apm-agent-nodejs.
Related Issues (20)
- update-tav-versions.js needs update for tav@5 syntax
- update Lambda guide to point out ELASTIC_APM_API_KEY for Elastic serverless usage
- Elastic APM Node package 3.50.0 and above causing issues with file upload HOT 1
- Agent environment not set correctly from NODE_ENV in 4.3.0 HOT 3
- avoid instrumenting some Node.js apps when `NODE_OPTIONS=-r elastic-apm-node/start` is being used
- "pg/knex.test.js" fails with Node.js v18.19.0 HOT 2
- Failed to start typescript app with APM agent. HOT 1
- elastic-apm-node not working for mongoose 8.0.3 and mongodb 6.2.0 HOT 1
- support `node --enable-source-maps` usage with our custom `Error.prepareStackTrace` usage
- fix <database>.$cmd.getMore span on mongodb
- Memory usage reported incorrectly in k8s pod HOT 3
- Support of Next js ^14 HOT 2
- `_signalLambdaEnd` request to Lambda extension should set `Content-Type`
- Questions re ESM support for MikroOrm / knex, Node v20, & OIDC HOT 3
- Unhandled ERR_INVALID_URL causing node.js service to exit HOT 1
- question: applying user.id when using opentelemetry api with Elastic HOT 2
- remove opentracing doc
- issue labeler workflow failing HOT 7
- Support mtls connection
- test issue to see if labeler action works on an issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apm-agent-nodejs.