Coder Social home page Coder Social logo

Comments (2)

jakemac53 avatar jakemac53 commented on September 22, 2024 3

I prefer the current approach (unsurprisingly, because I designed it 🤣 ), here are some reasons:

  • How does a macro get a "macro context"? Presumably, this essentially adds a 4th phase (for registering which phases you want to run in), with additional round trips and overhead (to register your macro in each phase) that isn't required with the current approach.
  • Knowing all the phases a macro wants to operate in ahead of time allows you to more easily only run the necessary phases. As an example, the first phase cannot do introspection and never needs to be re-ran unless the current file changes. If you have to (or have the ability to) register which later phases you are going to run in during that phase, then it is more challenging to avoid redoing this work.
  • The callback approach encourages retaining state between phases which we do not want macros to do. The (const) class based approach means you can only share global state, and won't implicitly capture local state like a callback would. In particular, objects retrieved from macro APIs are only valid in the current zone, attempting to cache them and use them in a later phase will cause problems.
  • Similarly the callback approach is more prone to memory leaks - these callbacks have to be retained potentially indefinitely (especially if you want to try and avoid re-running earlier phases). And it is very easy for them to retain a bunch of state that isn't actually necessary, or shouldn't have been retained.
  • I don't believe it actually makes the code meaningfully better. It won't be significantly shorter (the callbacks will be essentially the same as the implemented methods), the class header is short and replaces the explicit register calls.
  • When written as a class the tooling is better because you write the interfaces you want to implement, and the tooling will create the stubs for you to fill in.
  • Classes also enable the use of mixins etc which makes them easily composable.

from language.

jakemac53 avatar jakemac53 commented on September 22, 2024

I am going to close this one as not planned.

from language.

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.