Slide 1

Slide 1 text

Meta: Programming, Objects, and Classes presented by Shane Holloway of TechGame Networks ( [email protected] ) share under Creative Commons BY-NC-SA 3.0

Slide 2

Slide 2 text

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 • • • • •

Slide 3

Slide 3 text

Background Experience Instrumentation, Hardware Automation, Scientific Visualization, Accessibility 10 years Python 10 years C++ (some Objective-C & ANSI C) projects in: Javascript, Smalltalk, Lua, OMeta, Lisp, Scheme, Coffee-script pre-career: Pascal & Object Pascal (Delphi) • • • • •

Slide 4

Slide 4 text

Let’s get Meta “Fingerpainting. Escher revisited”, by Joseandrés Guijarro used under CC BY-NC 2.0 from http://bit.ly/HX8QnV

Slide 5

Slide 5 text

Impressions Meta Blurt out the ideas it brings to mind!

Slide 6

Slide 6 text

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 • • •

Slide 7

Slide 7 text

Impressions Meta- Programming Don’t we have enough “real” programming?

Slide 8

Slide 8 text

Meta-programming concept: “does-a” expansion C preprocessor macros compile-time optimizations: loop unrolling C++ Templates and Generics polymorphism, operators, and protocols (leverages generics by redefining methods) • • • • •

Slide 9

Slide 9 text

Meta-programming at Runtime self-modifying code like JIT indirect control flow via state or closures text processing: Jinja2, Mustache Lisp & Scheme runtime macros • • • •

Slide 10

Slide 10 text

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) • • • •

Slide 11

Slide 11 text

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 • • • • • •

Slide 12

Slide 12 text

Impressions Meta-Objects Is that kind of like the little meeting that sets the agenda for the big meeting?

Slide 13

Slide 13 text

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. • • • •

Slide 14

Slide 14 text

Meta-object Powered Object-oriented: Smalltalk, CLOS, Python Prototype-oriented: self, javascript, lua Aspect-oriented Traits, Objective-C Categories Lieberman prototypes (ask me later, they are cool!) • • • • •

Slide 15

Slide 15 text

Impressions Meta-Classes Just be happy that we gave you class definitions and inheritance!

Slide 16

Slide 16 text

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) • • • •

Slide 17

Slide 17 text

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? • • • •

Slide 18

Slide 18 text

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 • • • •

Slide 19

Slide 19 text

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. • • •

Slide 20

Slide 20 text

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 • • • •

Slide 21

Slide 21 text

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 • • • •

Slide 22

Slide 22 text

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 • • • • • •

Slide 23

Slide 23 text

How to Meta? (on purpose) Reflection! getattr(self,‘on_’+name)(evt) Web: url path, args, mimetype, accept Events, observers, broadcast, msg queues Plugins & runtime composed systems metaclass registers component reflection + delegation for plugin hooks • • • • • •

Slide 24

Slide 24 text

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) • • • • • •

Slide 25

Slide 25 text

Javascript Browser Events Add context to DOM elements data-verb, id, class, ... Capture all interesting events grab event target’s context resolve action using context & event type • • • • •

Slide 26

Slide 26 text

Object Composition (GoF Design Patterns) “Design Patterns: Elements of Reusable Object-Oriented Software”, Gamma et al. © 1995 Commands with State & Strategy patterns Context dependent actions Undo/redo stacks, automation Inversion of Control, Builder pattern Proxy, Composite and Decorator patterns • • • • •

Slide 27

Slide 27 text

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 • • • • •

Slide 28

Slide 28 text

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” • • • •

Slide 29

Slide 29 text

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 • • • • •

Slide 30

Slide 30 text

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. • • •

Slide 31

Slide 31 text

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. • • • •

Slide 32

Slide 32 text

Let’s get Meta “Fingerpainting. Escher revisited”, by Joseandrés Guijarro used under CC BY-NC 2.0 from http://bit.ly/HX8QnV