DELAPARRA
Index
Color
NL
Category: Programming paradigms

Metaprogramming

Explained by Updated

What is Metaprogramming?

Metaprogramming: Metaprogramming treats code as data that can be examined and manipulated programmatically — generating boilerplate, adding behaviour, or building DSLs without hand-writing every line. Metaprogramming is writing code that reads, generates or changes other code. Instead of writing every repetitive piece by hand, a program creates it, or adapts behaviour at runtime based on structure.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Metaprogramming

How is Metaprogramming used in practice?

You use it more often than you might think. PHP attributes read by a framework, Laravel's magic methods that turn whereEmail() into a query, reflection that builds forms from a class definition, and code generators for API clients are all metaprogramming.

What should you keep in mind with Metaprogramming?

It removes boilerplate and enables elegant APIs. The cost is that behaviour becomes less visible. Magic methods do not show up in a plain text search, and editors may not understand them without help files or PHPDoc annotations. Use it where it clearly saves effort, and document the magic for the next developer.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with M

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.