4 ms·
>Think how much common code can exist in a software but cannot be refactored to a functions because it will have too many variables. Interesting...can you give
by ConspiracyFact 2y ago
>Think how much common code can exist in a software but cannot be refactored to a functions because it will have too many variables.
Interesting...can you give an example of a macro that solves this refactoring problem?
- skydhash 2y agoOne example is the ~use-package~ macro (Emacs plugin) [0]. Using packages in emacs is mostly the same code over and over. They've already been abstracted in functions, but you still find yourself juggling with so many utilities. You could write a bigger functions, but it will then have a lot of conditional branches. This macro selectively select the code it needs and transforming it if needs be and then the result will be evaluated. It's a bit hard to explain for me (English is not my native language). But it's the difference between coding a solution with all the edge cases baked in and coding an archetype that let you add your own cases. With functions, you abstract common algorithms, with macros you abstract common architecture. [0] https://github.com/jwiegley/use-package/blob/a6e856418d2ebd053b34e0ab2fda328abeba731c/use-package-core.el#L1614 https://github.com/jwiegley/use-package/blob/a6e856418d2ebd0...
- ConspiracyFact 2y agoThanks!