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

More Related Content

What's hot (15)

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

Similar to Exploring metaprogramming using Ruby language (20)

PDF
Meetup. Technologies Intro for Non-Tech People
IT Arena
 
PDF
Are High Level Programming Languages for Multicore and Safety Critical Conver...
InfinIT - Innovationsnetværket for it
 
PPTX
sl slides-unit-1.pptx
SRAVANTHISALLARAM1
 
PDF
Sudipta_Mukherjee_Resume_APR_2023.pdf
sudipto801
 
PPTX
Introduction-to-Programming-Languages.pptx
ranjan317165
 
PPTX
Plc part 1
Taymoor Nazmy
 
PDF
Reaktive Programmierung mit den Reactive Extensions (Rx)
NETUserGroupBern
 
PPTX
After the LAMP, it's time to get MEAN
Jeff Fox
 
PDF
Unit 4 Assignment 1 Comparative Study Of Programming...
Carmen Sanborn
 
PPTX
Memory models in c#
Sophie Obomighie
 
PDF
Resume
muddanas
 
PDF
Srinivas Muddana Resume
muddanas
 
PDF
Srinivas Muddana Resume
muddanas
 
PDF
Srinivas Muddana Resume
muddanas
 
PDF
Sudipta_Mukherjee_Resume-Nov_2022.pdf
Sudipta Mukherjee
 
PDF
Modeling software systems at a macroscopic scale
Ralf Laemmel
 
PDF
A Brief History of Programming Languages.pdf
EdFeranil
 
PPTX
Computer programminglanguages
PaulineGayVillarama
 
PDF
6_Object-oriented-using-java.pdf object oriented programming concepts
harinipradeep15
 
PPT
Ruby On Rails Presentation
Paul Pajo
 
Meetup. Technologies Intro for Non-Tech People
IT Arena
 
Are High Level Programming Languages for Multicore and Safety Critical Conver...
InfinIT - Innovationsnetværket for it
 
sl slides-unit-1.pptx
SRAVANTHISALLARAM1
 
Sudipta_Mukherjee_Resume_APR_2023.pdf
sudipto801
 
Introduction-to-Programming-Languages.pptx
ranjan317165
 
Plc part 1
Taymoor Nazmy
 
Reaktive Programmierung mit den Reactive Extensions (Rx)
NETUserGroupBern
 
After the LAMP, it's time to get MEAN
Jeff Fox
 
Unit 4 Assignment 1 Comparative Study Of Programming...
Carmen Sanborn
 
Memory models in c#
Sophie Obomighie
 
Resume
muddanas
 
Srinivas Muddana Resume
muddanas
 
Srinivas Muddana Resume
muddanas
 
Srinivas Muddana Resume
muddanas
 
Sudipta_Mukherjee_Resume-Nov_2022.pdf
Sudipta Mukherjee
 
Modeling software systems at a macroscopic scale
Ralf Laemmel
 
A Brief History of Programming Languages.pdf
EdFeranil
 
Computer programminglanguages
PaulineGayVillarama
 
6_Object-oriented-using-java.pdf object oriented programming concepts
harinipradeep15
 
Ruby On Rails Presentation
Paul Pajo
 
Ad

Recently uploaded (20)

PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
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