Writing/Book

Metaprogramming: An Adventure — cover

Metaprogramming:
An Adventure

Dan Gittik · free to read online

Metaprogramming is the practice of writing code that operates on other code: inspecting, modifying, even generating programs from scratch. It's incredibly powerful, somewhat underrated and understudied – and most importantly, incredibly fun.

I've been fascinated with this sorcery since I first encountered it. I've written plenty of useful code employing it, but the moment it became "work", it shifted into the realm of "advanced programming techniques". This book contains a bunch of those practices, but I've tried to tell it as an adventure.

For me, metaprogramming isn't something to learn for any serious purpose. Concrete goals narrow our vision; playing lets our imagination run wild, experiment and stumble onto innovation. We can later refine those discoveries into practical techniques, but novelty often begins with uninhibited, irreverent joy.

That joy is what I'd like to impart: a sense of wonder. Even with AI doing most of our coding nowadays, I hope you'll enjoy these strange and beautiful ideas as much as I enjoyed exploring them.

Start reading

Contents

  1. 01 Introduction13 min
  2. 02 Tracer Tricks19 min
  3. 03 Bytecode Manipulation23 min
  4. 04 Dynamic Code Execution26 min
  5. 05 Shell Autocompletion19 min
  6. 06 Aspect-Oriented Programming28 min
  7. 07 Domain-Specific Languages24 min
  8. 08 A Metaprogramming Layer24 min
  9. 09 Source Code Manipulation25 min
  10. 10 Runtime Serialization28 min
  11. 11 A Templating Engine in 20 Lines23 min
  12. 12 A Metaprogramming Framework42 min
  13. 13 Code Generation40 min