Exploring 
metaprogramming 
using 
Ruby language 
A brief introduction 
Harshal Ganpatrao Hayatnagarkar 
PhD Candidate in Dept. of Computer Science 
1 
Friday, October 3, 2014
Engineering marvels 
Ford Model T (approx. 1918) Tesla Model S (2010) 
10/24/2014 2
Assembly Lines: Process marvels 
Ford Model T Assembly Line 
Tesla Robotic Assembly Line 
10/24/2014 3
Assembly Lines: Process marvels 
People building cars 
A worker on assembly line does same task 
repetitively, item after item and day after day. 
People building robots building cars 
Is this like programming? 
People building robots build robots building 
cars 
What is this analogous to? 
Courtesy: http://stackoverflow.com/questions/3468246/whats-the-use-of-metaprogramming 
10/24/2014 4
Metaphor 
… 
People building robots building robots… building cars 
What is this analogous to? 
10/24/2014 5
Meta-programming 
• Meta (‘beyond’ in Greek) + programming  Programming 
Abstraction 
– Similar to meta-data, meta-model, meta-physics and so on. 
• “Writing of computer programs that with ability to treat 
programs as their data, as it meant that a program could 
be designed to read, generate, analyse and/or transform 
other programs, and even modify itself while running. In 
some cases, this allows programmers to minimize the 
number of lines of code to express a solution (hence 
reducing development time), or it gives programs greater 
flexibility to efficiently handle new situations without 
recompilation.” - Wikipedia 
10/24/2014 6
Revelation 
Data-Code Duality 
10/24/2014 7
Two aspects 
Reflection Generative programming 
10/24/2014 8
Reflection 
• Ability of a computer program to examine and modify the 
structure and behavior (specifically values, meta-data, 
properties and functions) of the program at runtime. 
– Metalanguage in which metaprogram is written. 
– object language, programs written in which are manipulated. 
– reflection or reflexivity is ability of a programming language to 
be its own metalanguage. 
• Fairly common in programming languages 
– C++ (limited) 
– Java (+ other JVM languages), C# (+ other CLR languages) 
– JavaScript, Python, PHP, Ruby 
10/24/2014 9
Generative Programming 
• “A style of computer programming that uses 
automated source code creation through generic 
frames, classes, prototypes, templates, aspects, 
and code generators to improve programmer 
productivity.” - Wikipedia 
• For example, 
– Internal to language: C/C++ preprocessor macros, C++ 
templates, LISP macros, Ruby/Python/PHP 
evaluations. 
– External: Code generation templates. 
10/24/2014 10
Ruby Programming Language 
• Dynamic, reflective, object-oriented, 
general-purpose programming language. 
• Influenced by Perl, Smalltalk, Eiffel, Ada, 
and Lisp. 
• Supports multiple paradigms functional, 
object-oriented, and imperative. 
• With dynamic type system and automatic 
memory management. 
Yukihiro "Matz" 
Matsumoto 
10/24/2014 11
Meta Object Protocol 
• Everything is an object, including classes. 
• Method calling is analogous to message 
passing where arguments are payload. 
10/24/2014 12
10/24/2014 13
Open Classes 
10/24/2014 14
Dynamic methods 
10/24/2014 15
Dynamic methods 
Ruby on Rails – ActiveRecord example 
10/24/2014 16
Generative Programming 
• Code generation – one or more levels 
– ‘eval’ expression family 
– Takes source code in string form and embed in current 
context. 
10/24/2014 17
Two-level generation 
• Code generating code generating code 
Level 1 
Level 2 
 ‘Level 1’ eval 
 ‘Level 2’ eval 
10/24/2014 18
Pitfalls 
• Metabugs? 
– Bugs generating bugs generating… 
– And there is no ‘programs debugging programs 
debugging programs…’. 
• Increased code complexity 
10/24/2014 19
Further exploration… 
• Model-driven development 
• Domain-specific languages 
• Ruby on Rails for web development 
framework 
– An example of metaprogramming features. 
10/24/2014 20
Questions? 
And thank you for your interest ! 
10/24/2014 21

More Related Content

PPTX
hexMachina WWX 2016
PPTX
Ruby on Rails Introduction M&P - IT Skill Development Program 07
PDF
Extending JS WU2016 Toronto
PDF
Extending js codemotion warsaw 2016
PPTX
The Practice of Programming - Notation
PPTX
The Big Picture
PPTX
mbeddr meets IncQuer - Combining the Best Features of Two Modeling Worlds
hexMachina WWX 2016
Ruby on Rails Introduction M&P - IT Skill Development Program 07
Extending JS WU2016 Toronto
Extending js codemotion warsaw 2016
The Practice of Programming - Notation
The Big Picture
mbeddr meets IncQuer - Combining the Best Features of Two Modeling Worlds

What's hot (15)

PPTX
Programming Languages
PPT
Evalution about programming language part 1
PPTX
Session#1 csharp MTCS
PPTX
Basic information of C++
PPTX
Dynamic language
PDF
Static analysis of textual models
PPTX
K overview
PDF
Swift language - A fast overview of some features
PDF
Getting Started with PHP Extensions
PPTX
Go Language presentation
PPTX
Creating a textual domain specific language
PPT
Learning typescript
PPTX
.Net introduction
PPT
PHP - Procedural To Object-Oriented
PDF
Beyond JSON - An Introduction to FlatBuffers
Programming Languages
Evalution about programming language part 1
Session#1 csharp MTCS
Basic information of C++
Dynamic language
Static analysis of textual models
K overview
Swift language - A fast overview of some features
Getting Started with PHP Extensions
Go Language presentation
Creating a textual domain specific language
Learning typescript
.Net introduction
PHP - Procedural To Object-Oriented
Beyond JSON - An Introduction to FlatBuffers
Ad

Similar to Exploring metaprogramming using Ruby language (20)

PDF
Metaprogramming ruby
PDF
NetWork - 15.10.2011 - Applied code generation in .NET
PDF
Basics of reflection
PDF
Metaprogramming in Ruby
PPTX
Introduction to programming world
PPTX
haXe - One codebase to rule'em all
PDF
2011 june-kuala-lumpur-gtug-hackathon
PDF
Tools for Meta-Programming
PPTX
Discovering Computers: Chapter 13
PPTX
CH13-Computer Programs and Programming Languages
PPTX
DOC-20210303-WA0017..pptx,coding stuff in c
PDF
Metaprogramming
PPT
Software development... for all? (keynote at ICSOFT'2024)
PDF
GoLightly: Building VM-based language runtimes in Go
PDF
Programming for non tech entrepreneurs
PDF
Ruby Metaprogramming - OSCON 2008
PPT
Introduction to Agile Software Development & Python
PDF
Programing paradigm & implementation
PDF
Principles Of Programing Languages
Metaprogramming ruby
NetWork - 15.10.2011 - Applied code generation in .NET
Basics of reflection
Metaprogramming in Ruby
Introduction to programming world
haXe - One codebase to rule'em all
2011 june-kuala-lumpur-gtug-hackathon
Tools for Meta-Programming
Discovering Computers: Chapter 13
CH13-Computer Programs and Programming Languages
DOC-20210303-WA0017..pptx,coding stuff in c
Metaprogramming
Software development... for all? (keynote at ICSOFT'2024)
GoLightly: Building VM-based language runtimes in Go
Programming for non tech entrepreneurs
Ruby Metaprogramming - OSCON 2008
Introduction to Agile Software Development & Python
Programing paradigm & implementation
Principles Of Programing Languages
Ad

Recently uploaded (20)

PDF
Salesforce Agentforce AI Implementation.pdf
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PPTX
Computer Software - Technology and Livelihood Education
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
Microsoft Office 365 Crack Download Free
PPTX
"Secure File Sharing Solutions on AWS".pptx
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
DOCX
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
MCP Security Tutorial - Beginner to Advanced
PPTX
GSA Content Generator Crack (2025 Latest)
PDF
Visual explanation of Dijkstra's Algorithm using Python
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PDF
Website Design Services for Small Businesses.pdf
Salesforce Agentforce AI Implementation.pdf
Topaz Photo AI Crack New Download (Latest 2025)
Monitoring Stack: Grafana, Loki & Promtail
Computer Software - Technology and Livelihood Education
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Autodesk AutoCAD Crack Free Download 2025
CCleaner 6.39.11548 Crack 2025 License Key
Microsoft Office 365 Crack Download Free
"Secure File Sharing Solutions on AWS".pptx
Weekly report ppt - harsh dattuprasad patel.pptx
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Modern SharePoint Intranet Templates That Boost Employee Engagement in 2025.docx
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
Oracle Fusion HCM Cloud Demo for Beginners
MCP Security Tutorial - Beginner to Advanced
GSA Content Generator Crack (2025 Latest)
Visual explanation of Dijkstra's Algorithm using Python
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
Website Design Services for Small Businesses.pdf

Exploring metaprogramming using Ruby language

  • 1. Exploring metaprogramming using Ruby language A brief introduction Harshal Ganpatrao Hayatnagarkar PhD Candidate in Dept. of Computer Science 1 Friday, October 3, 2014
  • 2. Engineering marvels Ford Model T (approx. 1918) Tesla Model S (2010) 10/24/2014 2
  • 3. Assembly Lines: Process marvels Ford Model T Assembly Line Tesla Robotic Assembly Line 10/24/2014 3
  • 4. Assembly Lines: Process marvels People building cars A worker on assembly line does same task repetitively, item after item and day after day. People building robots building cars Is this like programming? People building robots build robots building cars What is this analogous to? Courtesy: http://stackoverflow.com/questions/3468246/whats-the-use-of-metaprogramming 10/24/2014 4
  • 5. Metaphor … People building robots building robots… building cars What is this analogous to? 10/24/2014 5
  • 6. Meta-programming • Meta (‘beyond’ in Greek) + programming  Programming Abstraction – Similar to meta-data, meta-model, meta-physics and so on. • “Writing of computer programs that with ability to treat programs as their data, as it meant that a program could be designed to read, generate, analyse and/or transform other programs, and even modify itself while running. In some cases, this allows programmers to minimize the number of lines of code to express a solution (hence reducing development time), or it gives programs greater flexibility to efficiently handle new situations without recompilation.” - Wikipedia 10/24/2014 6
  • 8. Two aspects Reflection Generative programming 10/24/2014 8
  • 9. Reflection • Ability of a computer program to examine and modify the structure and behavior (specifically values, meta-data, properties and functions) of the program at runtime. – Metalanguage in which metaprogram is written. – object language, programs written in which are manipulated. – reflection or reflexivity is ability of a programming language to be its own metalanguage. • Fairly common in programming languages – C++ (limited) – Java (+ other JVM languages), C# (+ other CLR languages) – JavaScript, Python, PHP, Ruby 10/24/2014 9
  • 10. Generative Programming • “A style of computer programming that uses automated source code creation through generic frames, classes, prototypes, templates, aspects, and code generators to improve programmer productivity.” - Wikipedia • For example, – Internal to language: C/C++ preprocessor macros, C++ templates, LISP macros, Ruby/Python/PHP evaluations. – External: Code generation templates. 10/24/2014 10
  • 11. Ruby Programming Language • Dynamic, reflective, object-oriented, general-purpose programming language. • Influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp. • Supports multiple paradigms functional, object-oriented, and imperative. • With dynamic type system and automatic memory management. Yukihiro "Matz" Matsumoto 10/24/2014 11
  • 12. Meta Object Protocol • Everything is an object, including classes. • Method calling is analogous to message passing where arguments are payload. 10/24/2014 12
  • 16. Dynamic methods Ruby on Rails – ActiveRecord example 10/24/2014 16
  • 17. Generative Programming • Code generation – one or more levels – ‘eval’ expression family – Takes source code in string form and embed in current context. 10/24/2014 17
  • 18. Two-level generation • Code generating code generating code Level 1 Level 2  ‘Level 1’ eval  ‘Level 2’ eval 10/24/2014 18
  • 19. Pitfalls • Metabugs? – Bugs generating bugs generating… – And there is no ‘programs debugging programs debugging programs…’. • Increased code complexity 10/24/2014 19
  • 20. Further exploration… • Model-driven development • Domain-specific languages • Ruby on Rails for web development framework – An example of metaprogramming features. 10/24/2014 20
  • 21. Questions? And thank you for your interest ! 10/24/2014 21

Editor's Notes

  • #6: This metaphor can explain metaphor in two ways: Robots building robots… Self-aware robots (autonomic computing)
  • #9: 1. Reflection: Recalling the example of self-aware robots, if a robot can inspect itself for faults and optimization, it is wonderful. Such a capability requires many features in the robotic system, which could be provided by reflection.
  • #10: In many languages such as C/C++, once code is generated, the information about types and variables is lost after compilation (only exception is RTTI where name of type is retained at runtime). However, the