SlideShare a Scribd company logo
DSL Powered by Rabbit 2.1.2
DSL
Yukio Goto
sg.rb
2014/04/29
DSL Powered by Rabbit 2.1.2
Who am I ?
Yukio Goto
favorite
Ruby, emacs, zsh, tennis✓
✓
work
Rakuten Asia Pte. Ltd.✓
As senior application engineer✓
✓
✓
DSL Powered by Rabbit 2.1.2
IDs
github
https://github.com/byplayer/
twitter
@byplayer
DSL Powered by Rabbit 2.1.2
Today's target
use DSL
-*-*-*-*-*-*-
making DSL
DSL Powered by Rabbit 2.1.2
DSL
What is DSL ?
DSL Powered by Rabbit 2.1.2
DSL
DSL =
Domain Specific
Language
DSL Powered by Rabbit 2.1.2
external DSL
SQL✓
SELECT id, user_name FROM users
DSL Powered by Rabbit 2.1.2
external DSL
configuration files✓
http {
passenger_root /usr/local/rvm/gems/ruby-2.1.0/gems/passenger-4.0.29;
passenger_ruby /usr/local/rvm/wrappers/ruby-2.1.0/ruby;
include mime.types;
default_type application/octet-stream;
# ...
}
DSL Powered by Rabbit 2.1.2
internal DSL
Rails✓
class User < ActiveRecord::Base
validates :name, presence: true
end
DSL Powered by Rabbit 2.1.2
BTW
By the way
DSL Powered by Rabbit 2.1.2
Did you make DSL ?
Did you make
DSL ?
DSL Powered by Rabbit 2.1.2
use only ?
Do you think
you can only
use DSL?
DSL Powered by Rabbit 2.1.2
No
NO !!!
DSL Powered by Rabbit 2.1.2
You
You
DSL Powered by Rabbit 2.1.2
can
can
DSL Powered by Rabbit 2.1.2
make
make
DSL Powered by Rabbit 2.1.2
your own DSL
your own
DSL
DSL Powered by Rabbit 2.1.2
AND
AND
DSL Powered by Rabbit 2.1.2
Ruby
Ruby
is
DSL Powered by Rabbit 2.1.2
easiest language
one of the most
easiest
language
DSL Powered by Rabbit 2.1.2
making DSL
making DSL
DSL Powered by Rabbit 2.1.2
How to make DSL
How to make
DSL
DSL Powered by Rabbit 2.1.2
before that
Before that
DSL Powered by Rabbit 2.1.2
Benefit of making DSL
DSL makes your Application
easy to write✓
easy to read✓
easy to use✓
✓
DSL Powered by Rabbit 2.1.2
theme
Configuration file using DSL
DSL Powered by Rabbit 2.1.2
config version 1
# singapore-ruby-group.conf
meetup do |conf|
conf.group = 'Singapore-Ruby-Group'
conf.organizer = 'Winston Teo'
conf.sponsors = ['Engine Yard',
'Silicon Straits',
'Plug-In@Blk71']
end
DSL Powered by Rabbit 2.1.2
how to use
mt = Meetup.load('singapore-ruby-group.conf')
puts mt.group
# => Singapore-Ruby-Group
puts mt.organizer
# => Winston Teo
puts mt.sponsors.join(', ')
# => Engine Yard, Silicon Straits, Plug-In@Blk71
DSL Powered by Rabbit 2.1.2
implementation
# Sample class to load configuration
class Meetup
attr_accessor :group, :organizer, :sponsors
def self.load(path)
fail "config file not found: #{path}" unless File.exist?(path)
mt = Meetup.new
File.open(path, 'r') do |file|
mt.instance_eval(File.read(path), path)
end
mt
end
private
def meetup
yield self
end
end
DSL Powered by Rabbit 2.1.2
key point
def self.load
# ...
File.open(path, 'r') do |file|
mt.instance_eval(File.read(path), path)
end
# ...
end
def meetup
yield self
end
DSL Powered by Rabbit 2.1.2
first point
pass string to 'instance_eval'
def self.load
# ...
File.open(path, 'r') do |file|
mt.instance_eval(File.read(path), path)
end
# ...
end
DSL Powered by Rabbit 2.1.2
instance_eval
"instance_eval"
DSL Powered by Rabbit 2.1.2
instance_eval
interpretes
String
DSL Powered by Rabbit 2.1.2
instance_eval
as Ruby code
DSL Powered by Rabbit 2.1.2
instance_eval
using Object
context
DSL Powered by Rabbit 2.1.2
instance_eval
In this case,
DSL Powered by Rabbit 2.1.2
instance_eval
configuration
file is
DSL Powered by Rabbit 2.1.2
instance_eval
interpreted as
DSL Powered by Rabbit 2.1.2
instance_eval
Meetup class
source code
DSL Powered by Rabbit 2.1.2
expand instance_eval virtually
def self.load
# File.open(path, 'r') do |file|
# mt.instance_eval(File.read(path), path)
# end
meetup do |conf|
conf.group = 'Singapore-Ruby-Group'
conf.organizer = 'Winston Teo'
conf.sponsors = ['Engine Yard',
'Silicon Straits',
'Plug-In@Blk71']
end
end
DSL Powered by Rabbit 2.1.2
easy
quite easy
DSL Powered by Rabbit 2.1.2
but
BUT
DSL Powered by Rabbit 2.1.2
Typing config
Typing 'conf.'
DSL Powered by Rabbit 2.1.2
is is
is not
DSL Powered by Rabbit 2.1.2
sexy
sexy
DSL Powered by Rabbit 2.1.2
Is it sexy ?
meetup do |conf|
conf.group = 'Singapore-Ruby-Group'
conf.organizer = 'Winston Teo'
conf.sponsors = ['Engine Yard',
'Silicon Straits',
'Plug-In@Blk71']
end
DSL Powered by Rabbit 2.1.2
ideal configuration
# singapore-ruby-group.conf
meetup {
group 'Singapore-Ruby-Group'
organizer 'Winston Teo'
sponsors ['Engine Yard',
'Silicon Straits',
'Plug-In@Blk71']
}
DSL Powered by Rabbit 2.1.2
readable
readable✓
DRY✓
DSL Powered by Rabbit 2.1.2
Let's use
Let's use
DSL Powered by Rabbit 2.1.2
Ruby's black magic
Ruby's black
magic
DSL Powered by Rabbit 2.1.2
parsing
parsing it
DSL Powered by Rabbit 2.1.2
load
class Meetup
attr_accessor :group, :organizer, :sponsors
def self.load(path)
mt = new
File.open(path, 'r') do |file|
loader = MeetupLoader.new(mt)
loader.instance_eval(file.read, path)
end
mt
end
end
DSL Powered by Rabbit 2.1.2
make support class
make support class
MeetupLoader
DSL Powered by Rabbit 2.1.2
make support class
define setter
method
DSL Powered by Rabbit 2.1.2
make support class
not use '='
DSL Powered by Rabbit 2.1.2
make support class
and
DSL Powered by Rabbit 2.1.2
make support class
load function
(meetup) only
DSL Powered by Rabbit 2.1.2
make support class (setter)
class MeetupLoader
def initialize(mt)
@meetup = mt
end
# ...
def group(g)
@meetup.group = g
end
def organizer(o)
@meetup.organizer = o
end
# ...
end
DSL Powered by Rabbit 2.1.2
instance_eval again
class MeetupLoader
# ...
def meetup(&block)
instance_eval(&block)
end
# ...
end
DSL Powered by Rabbit 2.1.2
The point of black magic
instance_eval
again
DSL Powered by Rabbit 2.1.2
instance_eval for block
instance_eval
with block
DSL Powered by Rabbit 2.1.2
changes
changes
DSL Powered by Rabbit 2.1.2
default receiver
default
receiver
DSL Powered by Rabbit 2.1.2
in the block
in the block
DSL Powered by Rabbit 2.1.2
original code
class Meetup
attr_accessor :group, :organizer, :sponsors
def self.load(path)
mt = new
File.open(path, 'r') do |file|
loader = MeetupLoader.new(mt)
loader.instance_eval(file.read, path)
end
mt
end
end
DSL Powered by Rabbit 2.1.2
expand instance_eval virtually 1
def self.load(path)
mt = new
File.open(path, 'r') do |file|
loader = MeetupLoader.new(mt)
# loader.instance_eval(file.read, path)
loader.meetup {
group 'Singapore-Ruby-Group'
organizer 'Winston Teo'
# ...
}
end
#...
DSL Powered by Rabbit 2.1.2
instance_eval with block
class MeetupLoader
# ...
def meetup(&block)
instance_eval(&block)
end
# ...
end
DSL Powered by Rabbit 2.1.2
expand instance_eval virtually 2
def meetup(&block)
# instance_eval(&block)
#{
self.group 'Singapore-Ruby-Group'
self.organizer 'Winston Teo'
# ...
# }
end
DSL Powered by Rabbit 2.1.2
The trick
The trick
DSL Powered by Rabbit 2.1.2
of
of
DSL Powered by Rabbit 2.1.2
Ruby's black magic
Ruby's black
magic
DSL Powered by Rabbit 2.1.2
is
is
DSL Powered by Rabbit 2.1.2
instance_eval with block
instance_eval
with block
DSL Powered by Rabbit 2.1.2
expand instance_eval virtually 2
def meetup(&block)
# instance_eval(&block)
#{
self.group 'Singapore-Ruby-Group'
self.organizer 'Winston Teo'
# ...
# }
end
DSL Powered by Rabbit 2.1.2
Today
Today,
DSL Powered by Rabbit 2.1.2
I
I
DSL Powered by Rabbit 2.1.2
don't
don't
DSL Powered by Rabbit 2.1.2
talk about
talk about
DSL Powered by Rabbit 2.1.2
caution points
caution points
DSL Powered by Rabbit 2.1.2
caution points
security✓
handle method_missing✓
handle syntax error✓
DSL Powered by Rabbit 2.1.2
source code
https://github.com/byplayer/meetup_config✓
https://github.com/byplayer/
meetup_config_ex
✓
DSL Powered by Rabbit 2.1.2
take a way
You can make DSL✓
instance_eval is interesting✓
DSL Powered by Rabbit 2.1.2
Hiring
Rakuten Asia Pte. Ltd.
wants to hire
Server side Application
Engineer (Ruby, java)
✓
iOS, Android Application
Engineer
✓
✓
DSL Powered by Rabbit 2.1.2
Any question ?
Any question ?
DSL Powered by Rabbit 2.1.2
Thank you
Thank you
for listening

More Related Content

What's hot

Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
Timur Safin
 
A Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiA Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry Pi
Jian-Hong Pan
 
Making asterisk feel like home outside north america
Making asterisk feel like home outside north americaMaking asterisk feel like home outside north america
Making asterisk feel like home outside north america
PaloSanto Solutions
 
HA Hadoop -ApacheCon talk
HA Hadoop -ApacheCon talkHA Hadoop -ApacheCon talk
HA Hadoop -ApacheCon talkSteve Loughran
 
Pfm technical-inside
Pfm technical-insidePfm technical-inside
Pfm technical-inside
iyatomi takehiro
 
Python twisted
Python twistedPython twisted
Python twisted
Mahendra M
 
How to build Debian packages
How to build Debian packages How to build Debian packages
How to build Debian packages
Priyank Kapadia
 
Linux class 8 tar
Linux class 8   tar  Linux class 8   tar
NLTK in 20 minutes
NLTK in 20 minutesNLTK in 20 minutes
NLTK in 20 minutes
Jacob Perkins
 
High Availability Server with DRBD in linux
High Availability Server with DRBD in linuxHigh Availability Server with DRBD in linux
High Availability Server with DRBD in linux
Ali Rachman
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking systemJesse Vincent
 
Concurrency in Python
Concurrency in PythonConcurrency in Python
Concurrency in PythonGavin Roy
 
101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file management
Acácio Oliveira
 
101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file management
Acácio Oliveira
 
Linux
LinuxLinux
Linux final exam
Linux final examLinux final exam
Linux final exam
Andrew Ibrahim
 
Do more than one thing at the same time, the Python way
Do more than one thing at the same time, the Python wayDo more than one thing at the same time, the Python way
Do more than one thing at the same time, the Python wayJaime Buelta
 
Software Defined Networks (SDN) na przykładzie rozwiązania OpenContrail.
Software Defined Networks (SDN) na przykładzie rozwiązania OpenContrail.Software Defined Networks (SDN) na przykładzie rozwiązania OpenContrail.
Software Defined Networks (SDN) na przykładzie rozwiązania OpenContrail.
Semihalf
 

What's hot (20)

Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
 
A Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry PiA Journey to Boot Linux on Raspberry Pi
A Journey to Boot Linux on Raspberry Pi
 
Making asterisk feel like home outside north america
Making asterisk feel like home outside north americaMaking asterisk feel like home outside north america
Making asterisk feel like home outside north america
 
2003 December
2003 December2003 December
2003 December
 
HA Hadoop -ApacheCon talk
HA Hadoop -ApacheCon talkHA Hadoop -ApacheCon talk
HA Hadoop -ApacheCon talk
 
Pfm technical-inside
Pfm technical-insidePfm technical-inside
Pfm technical-inside
 
Python twisted
Python twistedPython twisted
Python twisted
 
How to build Debian packages
How to build Debian packages How to build Debian packages
How to build Debian packages
 
Linux class 8 tar
Linux class 8   tar  Linux class 8   tar
Linux class 8 tar
 
NLTK in 20 minutes
NLTK in 20 minutesNLTK in 20 minutes
NLTK in 20 minutes
 
High Availability Server with DRBD in linux
High Availability Server with DRBD in linuxHigh Availability Server with DRBD in linux
High Availability Server with DRBD in linux
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking system
 
Concurrency in Python
Concurrency in PythonConcurrency in Python
Concurrency in Python
 
101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file management
 
101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file management
 
Linux
LinuxLinux
Linux
 
Linux final exam
Linux final examLinux final exam
Linux final exam
 
Do more than one thing at the same time, the Python way
Do more than one thing at the same time, the Python wayDo more than one thing at the same time, the Python way
Do more than one thing at the same time, the Python way
 
Software Defined Networks (SDN) na przykładzie rozwiązania OpenContrail.
Software Defined Networks (SDN) na przykładzie rozwiązania OpenContrail.Software Defined Networks (SDN) na przykładzie rozwiązania OpenContrail.
Software Defined Networks (SDN) na przykładzie rozwiązania OpenContrail.
 
Linux
LinuxLinux
Linux
 

Similar to How to make DSL

#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
Salesforce Marketing Cloud
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Cosimo Streppone
 
New features in Ruby 2.5
New features in Ruby 2.5New features in Ruby 2.5
New features in Ruby 2.5
Ireneusz Skrobiś
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
Schalk Cronjé
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
bobmcwhirter
 
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
DECK36
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapes
José Paumard
 
The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)Peter Eisentraut
 
Collaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI CookbookCollaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI Cookbook
Ken Lin
 
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
Harshal Hayatnagarkar
 
Subversion To Mercurial
Subversion To MercurialSubversion To Mercurial
Subversion To Mercurial
Ladislav Prskavec
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in R
Samuel Bosch
 
Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Vitaly Baum
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
Arto Artnik
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Clinton Dreisbach
 
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...RootedCON
 
Cloud Meetup - Automation in the Cloud
Cloud Meetup - Automation in the CloudCloud Meetup - Automation in the Cloud
Cloud Meetup - Automation in the Cloud
petriojala123
 
Discovering OpenBSD on AWS
Discovering OpenBSD on AWSDiscovering OpenBSD on AWS
Discovering OpenBSD on AWS
Laurent Bernaille
 
JRuby e DSL
JRuby e DSLJRuby e DSL
JRuby e DSL
jodosha
 

Similar to How to make DSL (20)

#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed#CNX14 - Using Ruby for Reliability, Consistency, and Speed
#CNX14 - Using Ruby for Reliability, Consistency, and Speed
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
 
New features in Ruby 2.5
New features in Ruby 2.5New features in Ruby 2.5
New features in Ruby 2.5
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
Our Puppet Story – Patterns and Learnings (sage@guug, March 2014)
 
Construire son JDK en 10 étapes
Construire son JDK en 10 étapesConstruire son JDK en 10 étapes
Construire son JDK en 10 étapes
 
The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)
 
Collaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI CookbookCollaborative Cuisine's 1 Hour JNDI Cookbook
Collaborative Cuisine's 1 Hour JNDI Cookbook
 
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
 
Subversion To Mercurial
Subversion To MercurialSubversion To Mercurial
Subversion To Mercurial
 
Reproducible Computational Research in R
Reproducible Computational Research in RReproducible Computational Research in R
Reproducible Computational Research in R
 
Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
 
Week1
Week1Week1
Week1
 
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
Sergi Álvarez + Roi Martín - radare2: From forensics to bindiffing [RootedCON...
 
Cloud Meetup - Automation in the Cloud
Cloud Meetup - Automation in the CloudCloud Meetup - Automation in the Cloud
Cloud Meetup - Automation in the Cloud
 
Discovering OpenBSD on AWS
Discovering OpenBSD on AWSDiscovering OpenBSD on AWS
Discovering OpenBSD on AWS
 
JRuby e DSL
JRuby e DSLJRuby e DSL
JRuby e DSL
 

Recently uploaded

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 

How to make DSL

  • 1. DSL Powered by Rabbit 2.1.2 DSL Yukio Goto sg.rb 2014/04/29
  • 2. DSL Powered by Rabbit 2.1.2 Who am I ? Yukio Goto favorite Ruby, emacs, zsh, tennis✓ ✓ work Rakuten Asia Pte. Ltd.✓ As senior application engineer✓ ✓ ✓
  • 3. DSL Powered by Rabbit 2.1.2 IDs github https://github.com/byplayer/ twitter @byplayer
  • 4. DSL Powered by Rabbit 2.1.2 Today's target use DSL -*-*-*-*-*-*- making DSL
  • 5. DSL Powered by Rabbit 2.1.2 DSL What is DSL ?
  • 6. DSL Powered by Rabbit 2.1.2 DSL DSL = Domain Specific Language
  • 7. DSL Powered by Rabbit 2.1.2 external DSL SQL✓ SELECT id, user_name FROM users
  • 8. DSL Powered by Rabbit 2.1.2 external DSL configuration files✓ http { passenger_root /usr/local/rvm/gems/ruby-2.1.0/gems/passenger-4.0.29; passenger_ruby /usr/local/rvm/wrappers/ruby-2.1.0/ruby; include mime.types; default_type application/octet-stream; # ... }
  • 9. DSL Powered by Rabbit 2.1.2 internal DSL Rails✓ class User < ActiveRecord::Base validates :name, presence: true end
  • 10. DSL Powered by Rabbit 2.1.2 BTW By the way
  • 11. DSL Powered by Rabbit 2.1.2 Did you make DSL ? Did you make DSL ?
  • 12. DSL Powered by Rabbit 2.1.2 use only ? Do you think you can only use DSL?
  • 13. DSL Powered by Rabbit 2.1.2 No NO !!!
  • 14. DSL Powered by Rabbit 2.1.2 You You
  • 15. DSL Powered by Rabbit 2.1.2 can can
  • 16. DSL Powered by Rabbit 2.1.2 make make
  • 17. DSL Powered by Rabbit 2.1.2 your own DSL your own DSL
  • 18. DSL Powered by Rabbit 2.1.2 AND AND
  • 19. DSL Powered by Rabbit 2.1.2 Ruby Ruby is
  • 20. DSL Powered by Rabbit 2.1.2 easiest language one of the most easiest language
  • 21. DSL Powered by Rabbit 2.1.2 making DSL making DSL
  • 22. DSL Powered by Rabbit 2.1.2 How to make DSL How to make DSL
  • 23. DSL Powered by Rabbit 2.1.2 before that Before that
  • 24. DSL Powered by Rabbit 2.1.2 Benefit of making DSL DSL makes your Application easy to write✓ easy to read✓ easy to use✓ ✓
  • 25. DSL Powered by Rabbit 2.1.2 theme Configuration file using DSL
  • 26. DSL Powered by Rabbit 2.1.2 config version 1 # singapore-ruby-group.conf meetup do |conf| conf.group = 'Singapore-Ruby-Group' conf.organizer = 'Winston Teo' conf.sponsors = ['Engine Yard', 'Silicon Straits', 'Plug-In@Blk71'] end
  • 27. DSL Powered by Rabbit 2.1.2 how to use mt = Meetup.load('singapore-ruby-group.conf') puts mt.group # => Singapore-Ruby-Group puts mt.organizer # => Winston Teo puts mt.sponsors.join(', ') # => Engine Yard, Silicon Straits, Plug-In@Blk71
  • 28. DSL Powered by Rabbit 2.1.2 implementation # Sample class to load configuration class Meetup attr_accessor :group, :organizer, :sponsors def self.load(path) fail "config file not found: #{path}" unless File.exist?(path) mt = Meetup.new File.open(path, 'r') do |file| mt.instance_eval(File.read(path), path) end mt end private def meetup yield self end end
  • 29. DSL Powered by Rabbit 2.1.2 key point def self.load # ... File.open(path, 'r') do |file| mt.instance_eval(File.read(path), path) end # ... end def meetup yield self end
  • 30. DSL Powered by Rabbit 2.1.2 first point pass string to 'instance_eval' def self.load # ... File.open(path, 'r') do |file| mt.instance_eval(File.read(path), path) end # ... end
  • 31. DSL Powered by Rabbit 2.1.2 instance_eval "instance_eval"
  • 32. DSL Powered by Rabbit 2.1.2 instance_eval interpretes String
  • 33. DSL Powered by Rabbit 2.1.2 instance_eval as Ruby code
  • 34. DSL Powered by Rabbit 2.1.2 instance_eval using Object context
  • 35. DSL Powered by Rabbit 2.1.2 instance_eval In this case,
  • 36. DSL Powered by Rabbit 2.1.2 instance_eval configuration file is
  • 37. DSL Powered by Rabbit 2.1.2 instance_eval interpreted as
  • 38. DSL Powered by Rabbit 2.1.2 instance_eval Meetup class source code
  • 39. DSL Powered by Rabbit 2.1.2 expand instance_eval virtually def self.load # File.open(path, 'r') do |file| # mt.instance_eval(File.read(path), path) # end meetup do |conf| conf.group = 'Singapore-Ruby-Group' conf.organizer = 'Winston Teo' conf.sponsors = ['Engine Yard', 'Silicon Straits', 'Plug-In@Blk71'] end end
  • 40. DSL Powered by Rabbit 2.1.2 easy quite easy
  • 41. DSL Powered by Rabbit 2.1.2 but BUT
  • 42. DSL Powered by Rabbit 2.1.2 Typing config Typing 'conf.'
  • 43. DSL Powered by Rabbit 2.1.2 is is is not
  • 44. DSL Powered by Rabbit 2.1.2 sexy sexy
  • 45. DSL Powered by Rabbit 2.1.2 Is it sexy ? meetup do |conf| conf.group = 'Singapore-Ruby-Group' conf.organizer = 'Winston Teo' conf.sponsors = ['Engine Yard', 'Silicon Straits', 'Plug-In@Blk71'] end
  • 46. DSL Powered by Rabbit 2.1.2 ideal configuration # singapore-ruby-group.conf meetup { group 'Singapore-Ruby-Group' organizer 'Winston Teo' sponsors ['Engine Yard', 'Silicon Straits', 'Plug-In@Blk71'] }
  • 47. DSL Powered by Rabbit 2.1.2 readable readable✓ DRY✓
  • 48. DSL Powered by Rabbit 2.1.2 Let's use Let's use
  • 49. DSL Powered by Rabbit 2.1.2 Ruby's black magic Ruby's black magic
  • 50. DSL Powered by Rabbit 2.1.2 parsing parsing it
  • 51. DSL Powered by Rabbit 2.1.2 load class Meetup attr_accessor :group, :organizer, :sponsors def self.load(path) mt = new File.open(path, 'r') do |file| loader = MeetupLoader.new(mt) loader.instance_eval(file.read, path) end mt end end
  • 52. DSL Powered by Rabbit 2.1.2 make support class make support class MeetupLoader
  • 53. DSL Powered by Rabbit 2.1.2 make support class define setter method
  • 54. DSL Powered by Rabbit 2.1.2 make support class not use '='
  • 55. DSL Powered by Rabbit 2.1.2 make support class and
  • 56. DSL Powered by Rabbit 2.1.2 make support class load function (meetup) only
  • 57. DSL Powered by Rabbit 2.1.2 make support class (setter) class MeetupLoader def initialize(mt) @meetup = mt end # ... def group(g) @meetup.group = g end def organizer(o) @meetup.organizer = o end # ... end
  • 58. DSL Powered by Rabbit 2.1.2 instance_eval again class MeetupLoader # ... def meetup(&block) instance_eval(&block) end # ... end
  • 59. DSL Powered by Rabbit 2.1.2 The point of black magic instance_eval again
  • 60. DSL Powered by Rabbit 2.1.2 instance_eval for block instance_eval with block
  • 61. DSL Powered by Rabbit 2.1.2 changes changes
  • 62. DSL Powered by Rabbit 2.1.2 default receiver default receiver
  • 63. DSL Powered by Rabbit 2.1.2 in the block in the block
  • 64. DSL Powered by Rabbit 2.1.2 original code class Meetup attr_accessor :group, :organizer, :sponsors def self.load(path) mt = new File.open(path, 'r') do |file| loader = MeetupLoader.new(mt) loader.instance_eval(file.read, path) end mt end end
  • 65. DSL Powered by Rabbit 2.1.2 expand instance_eval virtually 1 def self.load(path) mt = new File.open(path, 'r') do |file| loader = MeetupLoader.new(mt) # loader.instance_eval(file.read, path) loader.meetup { group 'Singapore-Ruby-Group' organizer 'Winston Teo' # ... } end #...
  • 66. DSL Powered by Rabbit 2.1.2 instance_eval with block class MeetupLoader # ... def meetup(&block) instance_eval(&block) end # ... end
  • 67. DSL Powered by Rabbit 2.1.2 expand instance_eval virtually 2 def meetup(&block) # instance_eval(&block) #{ self.group 'Singapore-Ruby-Group' self.organizer 'Winston Teo' # ... # } end
  • 68. DSL Powered by Rabbit 2.1.2 The trick The trick
  • 69. DSL Powered by Rabbit 2.1.2 of of
  • 70. DSL Powered by Rabbit 2.1.2 Ruby's black magic Ruby's black magic
  • 71. DSL Powered by Rabbit 2.1.2 is is
  • 72. DSL Powered by Rabbit 2.1.2 instance_eval with block instance_eval with block
  • 73. DSL Powered by Rabbit 2.1.2 expand instance_eval virtually 2 def meetup(&block) # instance_eval(&block) #{ self.group 'Singapore-Ruby-Group' self.organizer 'Winston Teo' # ... # } end
  • 74. DSL Powered by Rabbit 2.1.2 Today Today,
  • 75. DSL Powered by Rabbit 2.1.2 I I
  • 76. DSL Powered by Rabbit 2.1.2 don't don't
  • 77. DSL Powered by Rabbit 2.1.2 talk about talk about
  • 78. DSL Powered by Rabbit 2.1.2 caution points caution points
  • 79. DSL Powered by Rabbit 2.1.2 caution points security✓ handle method_missing✓ handle syntax error✓
  • 80. DSL Powered by Rabbit 2.1.2 source code https://github.com/byplayer/meetup_config✓ https://github.com/byplayer/ meetup_config_ex ✓
  • 81. DSL Powered by Rabbit 2.1.2 take a way You can make DSL✓ instance_eval is interesting✓
  • 82. DSL Powered by Rabbit 2.1.2 Hiring Rakuten Asia Pte. Ltd. wants to hire Server side Application Engineer (Ruby, java) ✓ iOS, Android Application Engineer ✓ ✓
  • 83. DSL Powered by Rabbit 2.1.2 Any question ? Any question ?
  • 84. DSL Powered by Rabbit 2.1.2 Thank you Thank you for listening