An Introduction to Metaprogramming
This last blog post was really short, a lot more so than most
of the others we’ve been reading so being honest I’m not really sure I have
enough to say about it. It was very much an introductory kind of writing just showing
a tiny bit of what metaprogramming is and a couple of examples of it in action.
I do like the concept, metaprogramming is something I actually have used before,
at first without realizing it was a known, named, thing and only realizing it
was about a year ago. It’s a very useful concept, especially on those languages
that can be done at runtime, meaning you don’t generate the source for other
program but expand the running program’s capabilities while its running. Python,
Ruby and JS are good examples of languages where its really easy to do some
basic metaprogramming to make your life easier, although they don’t get to the
levels of Lisp-based languages like Clojure that take metaprogramming to eleven
by taking advantage of their really simple syntax allowing you to actually do
something like a hybrid between expanding your program’s capabilities and
writing code for another program, you actually get to write and/or modify the
source code of your own running program, be it just changing or expanding an
existing function or even adding base syntax that didn’t exist before. I’ve also
used it a lot at some workplaces I’ve been, where they mostly use it to write
repetitive code based on a simpler version that the programmer actually writes,
although I’ve also worked at a company that used metaprogramming to write code
equivalent to what programmers usually write but in a language that allows it
to run much faster, basically making a transpiler of sorts. I wouldn’t call it
a complete transpiler as it couldn’t really convert any program, only a bunch
of really specialized structures that were strictly defined so that it could
work.
Comments
Post a Comment