Giter VIP home page Giter VIP logo

Comments (7)

watson avatar watson commented on May 23, 2024

cc @Qard

from apm-agent-nodejs.

Qard avatar Qard commented on May 23, 2024

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.

watson avatar watson commented on May 23, 2024

@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.

Qard avatar Qard commented on May 23, 2024

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.

watson avatar watson commented on May 23, 2024

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.

watson avatar watson commented on May 23, 2024

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.

alvarolobato avatar alvarolobato commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.