SlideShare a Scribd company logo
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
Ad

Recommended

hexMachina WWX 2016
hexMachina WWX 2016
Francis Bourre
 
Ruby on Rails Introduction M&P - IT Skill Development Program 07
Ruby on Rails Introduction M&P - IT Skill Development Program 07
Muhammad Sunny ✈
 
Extending JS WU2016 Toronto
Extending JS WU2016 Toronto
Francis Bourre
 
Extending js codemotion warsaw 2016
Extending js codemotion warsaw 2016
Francis Bourre
 
The Practice of Programming - Notation
The Practice of Programming - Notation
Juggernaut Liu
 
The Big Picture
The Big Picture
Munazza-Mah-Jabeen
 
mbeddr meets IncQuer - Combining the Best Features of Two Modeling Worlds
mbeddr meets IncQuer - Combining the Best Features of Two Modeling Worlds
Istvan Rath
 
.Net framework
.Net framework
baabtra.com - No. 1 supplier of quality freshers
 
Programming Languages
Programming Languages
Edward Blurock
 
Evalution about programming language part 1
Evalution about programming language part 1
Synapseindiappsdevelopment
 
Session#1 csharp MTCS
Session#1 csharp MTCS
Ahmad Ehab
 
Basic information of C++
Basic information of C++
Fahad Farooq
 
Dynamic language
Dynamic language
Ashish Chaurasiya
 
Static analysis of textual models
Static analysis of textual models
Iván Ruiz-Rube
 
K overview
K overview
Grigore Rosu
 
Swift language - A fast overview of some features
Swift language - A fast overview of some features
Weverton Timoteo
 
Getting Started with PHP Extensions
Getting Started with PHP Extensions
MichaelBrunoLochemem
 
Go Language presentation
Go Language presentation
Gh-Mohammed Eldadah
 
Creating a textual domain specific language
Creating a textual domain specific language
Vicente García Díaz
 
Learning typescript
Learning typescript
Alexandre Marreiros
 
.Net introduction
.Net introduction
Sireesh K
 
PHP - Procedural To Object-Oriented
PHP - Procedural To Object-Oriented
Vance Lucas
 
Beyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffers
Maxim Zaks
 
Metaprogramming ruby
Metaprogramming ruby
GeekNightHyderabad
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
Dmytro Mindra
 
Basics of reflection
Basics of reflection
kim.mens
 
Metaprogramming in Ruby
Metaprogramming in Ruby
Ross Lawley
 
Introduction to programming world
Introduction to programming world
Jaskaran Singh
 
haXe - One codebase to rule'em all
haXe - One codebase to rule'em all
Tom Crombez
 
2011 june-kuala-lumpur-gtug-hackathon
2011 june-kuala-lumpur-gtug-hackathon
ikailan
 

More Related Content

What's hot (15)

Programming Languages
Programming Languages
Edward Blurock
 
Evalution about programming language part 1
Evalution about programming language part 1
Synapseindiappsdevelopment
 
Session#1 csharp MTCS
Session#1 csharp MTCS
Ahmad Ehab
 
Basic information of C++
Basic information of C++
Fahad Farooq
 
Dynamic language
Dynamic language
Ashish Chaurasiya
 
Static analysis of textual models
Static analysis of textual models
Iván Ruiz-Rube
 
K overview
K overview
Grigore Rosu
 
Swift language - A fast overview of some features
Swift language - A fast overview of some features
Weverton Timoteo
 
Getting Started with PHP Extensions
Getting Started with PHP Extensions
MichaelBrunoLochemem
 
Go Language presentation
Go Language presentation
Gh-Mohammed Eldadah
 
Creating a textual domain specific language
Creating a textual domain specific language
Vicente García Díaz
 
Learning typescript
Learning typescript
Alexandre Marreiros
 
.Net introduction
.Net introduction
Sireesh K
 
PHP - Procedural To Object-Oriented
PHP - Procedural To Object-Oriented
Vance Lucas
 
Beyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffers
Maxim Zaks
 
Session#1 csharp MTCS
Session#1 csharp MTCS
Ahmad Ehab
 
Basic information of C++
Basic information of C++
Fahad Farooq
 
Static analysis of textual models
Static analysis of textual models
Iván Ruiz-Rube
 
Swift language - A fast overview of some features
Swift language - A fast overview of some features
Weverton Timoteo
 
Getting Started with PHP Extensions
Getting Started with PHP Extensions
MichaelBrunoLochemem
 
Creating a textual domain specific language
Creating a textual domain specific language
Vicente García Díaz
 
.Net introduction
.Net introduction
Sireesh K
 
PHP - Procedural To Object-Oriented
PHP - Procedural To Object-Oriented
Vance Lucas
 
Beyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffers
Maxim Zaks
 

Similar to Exploring metaprogramming using Ruby language (20)

Metaprogramming ruby
Metaprogramming ruby
GeekNightHyderabad
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
Dmytro Mindra
 
Basics of reflection
Basics of reflection
kim.mens
 
Metaprogramming in Ruby
Metaprogramming in Ruby
Ross Lawley
 
Introduction to programming world
Introduction to programming world
Jaskaran Singh
 
haXe - One codebase to rule'em all
haXe - One codebase to rule'em all
Tom Crombez
 
2011 june-kuala-lumpur-gtug-hackathon
2011 june-kuala-lumpur-gtug-hackathon
ikailan
 
Tools for Meta-Programming
Tools for Meta-Programming
elliando dias
 
Discovering Computers: Chapter 13
Discovering Computers: Chapter 13
Anna Stirling
 
CH13-Computer Programs and Programming Languages
CH13-Computer Programs and Programming Languages
Sukanya Ben
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in c
floraaluoch3
 
Metaprogramming
Metaprogramming
Mehmet Emin İNAÇ
 
Software development... for all? (keynote at ICSOFT'2024)
Software development... for all? (keynote at ICSOFT'2024)
miso_uam
 
GoLightly: Building VM-based language runtimes in Go
GoLightly: Building VM-based language runtimes in Go
Eleanor McHugh
 
Programming for non tech entrepreneurs
Programming for non tech entrepreneurs
Rodrigo Gil
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
Brian Sam-Bodden
 
Introduction to Agile Software Development & Python
Introduction to Agile Software Development & Python
Tharindu Weerasinghe
 
Programing paradigm & implementation
Programing paradigm & implementation
Bilal Maqbool ツ
 
Principles Of Programing Languages
Principles Of Programing Languages
Matthew McCullough
 
2 - OOP
2 - OOP
The World of Smalltalk
 
NetWork - 15.10.2011 - Applied code generation in .NET
NetWork - 15.10.2011 - Applied code generation in .NET
Dmytro Mindra
 
Basics of reflection
Basics of reflection
kim.mens
 
Metaprogramming in Ruby
Metaprogramming in Ruby
Ross Lawley
 
Introduction to programming world
Introduction to programming world
Jaskaran Singh
 
haXe - One codebase to rule'em all
haXe - One codebase to rule'em all
Tom Crombez
 
2011 june-kuala-lumpur-gtug-hackathon
2011 june-kuala-lumpur-gtug-hackathon
ikailan
 
Tools for Meta-Programming
Tools for Meta-Programming
elliando dias
 
Discovering Computers: Chapter 13
Discovering Computers: Chapter 13
Anna Stirling
 
CH13-Computer Programs and Programming Languages
CH13-Computer Programs and Programming Languages
Sukanya Ben
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in c
floraaluoch3
 
Software development... for all? (keynote at ICSOFT'2024)
Software development... for all? (keynote at ICSOFT'2024)
miso_uam
 
GoLightly: Building VM-based language runtimes in Go
GoLightly: Building VM-based language runtimes in Go
Eleanor McHugh
 
Programming for non tech entrepreneurs
Programming for non tech entrepreneurs
Rodrigo Gil
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
Brian Sam-Bodden
 
Introduction to Agile Software Development & Python
Introduction to Agile Software Development & Python
Tharindu Weerasinghe
 
Programing paradigm & implementation
Programing paradigm & implementation
Bilal Maqbool ツ
 
Principles Of Programing Languages
Principles Of Programing Languages
Matthew McCullough
 
Ad

Recently uploaded (20)

GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Transmission Media. (Computer Networks)
Transmission Media. (Computer Networks)
S Pranav (Deepu)
 
What is data visualization and how data visualization tool can help.pptx
What is data visualization and how data visualization tool can help.pptx
Varsha Nayak
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Meet You in the Middle: 1000x Performance for Parquet Queries on PB-Scale Dat...
Alluxio, Inc.
 
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
Milwaukee Marketo User Group June 2025 - Optimize and Enhance Efficiency - Sm...
BradBedford3
 
How to Choose the Right Web Development Agency.pdf
How to Choose the Right Web Development Agency.pdf
Creative Fosters
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
How Insurance Policy Management Software Streamlines Operations
How Insurance Policy Management Software Streamlines Operations
Insurance Tech Services
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Smart Financial Solutions: Money Lender Software, Daily Pigmy & Personal Loan...
Intelli grow
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Wondershare PDFelement Pro 11.4.20.3548 Crack Free Download
Puppy jhon
 
How the US Navy Approaches DevSecOps with Raise 2.0
How the US Navy Approaches DevSecOps with Raise 2.0
Anchore
 
Shell Skill Tree - LabEx Certification (LabEx)
Shell Skill Tree - LabEx Certification (LabEx)
VICTOR MAESTRE RAMIREZ
 
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Async-ronizing Success at Wix - Patterns for Seamless Microservices - Devoxx ...
Natan Silnitsky
 
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
 
Step by step guide to install Flutter and Dart
Step by step guide to install Flutter and Dart
S Pranav (Deepu)
 
Ad

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