Defining DSL (Domain Specific Language) using Ruby

Preview:

Citation preview

DSLdomain-specific language

@ SPARKcamp #5

(in Ruby)

jakub naliwajek

netguru.co

DSLdomain-specific language

DSLdomain-specific language

A domain-specific language (DSL) is a computer language specialized to a particular application domain.

DSLdomain-specific language

A domain-specific language (DSL) is a computer language specialized to a particular application domain.

•Perl •HTML •MATLAB •VHDL •SQL

DSLdomain-specific language

A domain-specific language (DSL) is a computer language specialized to a particular application domain.

•Perl •HTML •MATLAB •VHDL •SQL

DSLdomain-specific language

A domain-specific language (DSL) is a computer language specialized to a particular application domain.

•Perl •HTML •MATLAB •VHDL •SQL

DSLdomain-specific language

A domain-specific language (DSL) is a computer language specialized to a particular application domain.

•Perl •HTML •MATLAB •VHDL •SQL

DSLdomain-specific language

A domain-specific language (DSL) is a computer language specialized to a particular application domain.

•Perl •HTML •MATLAB •VHDL •SQL

DSLdomain-specific language

A domain-specific language (DSL) is a computer language specialized to a particular application domain.

•Perl •HTML •MATLAB •VHDL •SQL

Simpler DSLs, particularly ones used by a single application, are sometimes informally called mini-languages.

DSLdomain-specific language

A domain-specific language (DSL) is a computer language specialized to a particular application domain.

•Perl •HTML •MATLAB •VHDL •SQL

Simpler DSLs, particularly ones used by a single application, are sometimes informally called mini-languages INTERNAL.

LISP

LISP1958

LISP1958

“On Lisp” – Paul Graham

Add “for” loop to LISP

RUBY

RUBYon rails

Rails “Migrations” DSL

RSpec DSL (testing framework)

DSLis not for COMPUTERS

describe == context == it(for computers)

PROBLEM

survey(name, &block)

survey(name, &block)

survey(name, &block)

survey(name, &block)

survey(name, &block)

question(content, **params, &block)

survey(name, &block)

question(content, **params, &block)

survey(name, &block)

question(content, **params, &block)

survey(name, &block)

question(content, **params, &block)

survey(name, &block)

question(content, **params, &block)

survey(name, &block)

question(content, **params, &block)

answer(content)

survey(name, &block)

question(content, **params, &block)

answer(content)

WHAT HELPS?

META PROGRAMMING

BLOCKS

0

20

40

60

80

no DSL DSL

use

uselearn

learn

How DIFFICULT?

0

20

40

60

80

no DSL DSL

use

uselearn

learn

How DIFFICULT?

Which one is more readable?

MiniTest RSpec

NOT ALWAYS COOL

developers […] who cannot survive without frameworks. – Adam Hawkins

http://hawkins.io/2015/05/the-ruby-community-the-next-version/

simplicity over convenience

= good for long-term

how many lines will that DSL save?

thoughtbot/factory_girl(kinda nice example)

thanksnetguru.co/signup/sparkcamp

Recommended