Who is this guy? CEO of TechGame Networks (techgame.net) B.S. Computer Science from UCCS Started software career in 1996 Passion for dynamic systems design & impl. Software as a process of creative synthesis combining art and science • • • • •
Definition: meta adjective: (of a creative work) referring to itself or to the conventions of its genre; self-referential. combining form: denoting position behind, after, or beyond denoting something of a higher or second-order kind • • •
Meta-programming at Runtime self-modifying code like JIT indirect control flow via state or closures text processing: Jinja2, Mustache Lisp & Scheme runtime macros • • • •
Languages are Meta-Programing Both C++ (Cfront) and Objective-C started as transpilers targeting C Alt-JS: Coffee-script & Dart to Javascript Domain-Specific Languages Remember T-diagrams for bootstrapping compilers? (http://en.wikipedia.org/wiki/T-diagram) • • • •
May Already Use Meta CMake: CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice. SWIG: “Simplified Wrapper and Interface Generator” Parser-Generators: Lex, Yacc, Flex, Bison Templates for Eclipse, XCode, Visual Studio Protocol Buffers, Corba, ActiveX, IDL Markdown, Textile, Haml, Jade, Less, Sass, Stylus • • • • • •
Meta-object concept: “has-a” compositional from wikipedia: any entity that manipulates, creates, describes, or implements other objects. related: reflection, (structural) recursion, meta-object protocol in languages like C++ and Java, the meta- object protocol is defined by the language, while in Objective-C it can be tailored. • • • •
Meta-classes concept: “is-a” behavior through identity subcategory of Meta-objects, particularly Meta-object protocol in the context of Python, Lua, Lisp, Smalltalk, Cola object-oriented programming prototype-oriented programming (under a generalized understanding) • • • •
Structural Recursion in “Pure” OO Languages Everything is an object. All objects have a class. An object’s class must also be an object. As all objects have a class, and a class is an object, what class is the class of a class? • • • •
Meta-class: a Step Back A meta-class creates classes when provoked A class creates instances of objects An object combines state and behavior An instance is an object that has a class • • • •
Why Meta? The bedrock of computing is built upon two concepts: data and the next instruction. Meta-* disciplines are the art of abstracting these fundamentals to models that suit the way we want to think about computing. Goal: improve tradeoffs [cost, time, quality] by investing in abstraction to leverage features, productivity, and uniformity. • • •
Why Meta-*? Allows you to use the computer to work smarter instead of harder. e.g. the same reason you use a computer language over assembly When you want to think about the problem space from a higher level abstraction similar to abstraction to a map/reduce operation from an explicit loop • • • •
When to Meta? When leverage from developing and employing solution will yield >2x over the lifetime cost of manual process. When the meta tools are already built Templates, macros, factories, extension Experience comes from practice • • • •
Time Continuum People: idea, funding, design, coding, support Time Scale: Days to years Software: compile, link, initialize, runtime, hot path. Time Scale: Milliseconds to hours Hardware: fetch, execute, store, branch Time Scale: Picoseconds to seconds • • • • • •
Dynamic Dispatch (Meta-object protocol) Runtime resolution of code or object impl. by key, arg types, values, or internal state commonly stored in associative mappings Also known as message sending Smalltalk, Objective-C, RPC Actors & Coroutines (Erlang, IO, Scala) • • • • • •
Extending Python (from the inside) http://hg.techgame.net/TG/metaObserving/ Use __metaclass__ mechanism to provide extension points: observe subclass creation observe instance creation observe instance restore (pickling) Just add instances to the namespace that support the observation protocol • • • • •
Fuzzy Boundaries Is it object composition or meta-*? Does it matter? Did you avoid explicit cases by your impl.? Higher-order thinking, be it functions, composition, or meta-*, can all help you avoid “the giant switch statement” • • • •
To Meta or Not solving indirect problem fun rabbit hole: challenging puzzles! creation: accidental or intentional? audience: creation vs maintenance tech. debt: troubleshooting and evolving • • • • •
Difficulties with Meta Debugging and tracing. Effects can split between compile-time expansion, initialization, runtime and structural composition. Non-explicit control flow can lead to “magical” feeling of action-at-a-distance Can be similar to tracing through async event driven or queue based systems. • • •
Intention and Audience Be intentional when integrating processed output into your software system. Keep it simple to explain and review Implement test suites and write documentation that anticipate questions and likely changes. Keep the people who will be maintaining the system in mind. • • • •