Code Generations

Overview

Novice programmers write more code than they need to. They start with long lists of procedural code and then discover functions, parameters, and objects, and—perhaps—higher-order functions and closures.

As we improve our skills, we’ll write less code to solve the same problems. We’ll use better abstractions. We’ll write more general code. We'll reuse code—and when we can add features by deleting code, we’ll achieve something great.

Writing programs to write programs for us—metaprogramming or code generation—allows us to build reusable abstractions. While we can make a huge mess, we can also build amazing things. Metaprogramming techniques make Moose possible, for example.

The AUTOLOAD technique for missing functions and methods demonstrates this technique in a specific form: Perl’s function and method dispatch system allows us to control what happens when the normal lookup fails.

Get hands-on with 1400+ tech skills courses.