Sunday, March 24, 2019

Metaprogramming

I think that most of the people taking this course have actually already worked directly with metaprogramming! At the Programming Languages course that it is taught here by our professor, a significant effort is made towards using what I'd call Clojure's runtime-self-metaprogramming tool called macros. Pieces of Clojure code that would 'expand' into more Clojure code before being actually evaluated.

I certainly did all that, completed all my macros homework and solved the exams macros excercizes. I enjoyed it. It felt super powerful to have metaprogramming integrated to such an extent into a language, because it meant that you could build on top of the language itself. It allowed you to basically extend the syntax itself to do whatever you could imagine. We even read some articles telling tales of how this flexibility allowed some website company to out-perform their competition.

But, in my personal experience, I see the impact of metaprogramming in another area: the issue of compatibility, interoperability and portability. Particularly with frameworks.  The projects that I work with the most these days simply wouldn't work without metaprogramming. I work a lot with projects in which I code in a node (ecmascript) environment, but the programs that end up being the result of my code and are actually executed do not look like my code at all, but instead are products of what I guess could be called 'metaprogramming' pipelines that adapt it to whatever environment it is targeted at. Things such as the Babel and Typescript libraries are powerful examples that I work with every day. Those libraries basically translate between versions of programming languages. Even more obvious examples are the cli interfaces of frameworks like Angular or Rails, where a single command automatically translates into N different programs of N different programing languages (such as when components are created in Angular, or 'entities' in rails).

That is where I see metaprogramming practices being more impactful.

No comments:

Post a Comment