SlideShare a Scribd company logo
1 of 61
PyConJP 2012




Fantastic DSL
in Python
Makoto Kuwata <kwa@kuwata-lab.com>
http://www.kuwata-lab.com/
2012-09-16 (Sun)

Video: http://www.youtube.com/watch?v=l8ptNmtB0G8
Agenda
•About DSL
•Fantastic 'with' statement
•Fantastic 'for' statement
•Fantastic Decorator
•Fantastic Operator
About DSL
What is DSL (Domain Specific Language?)




         DSL

             Google Search
Internal DSL v.s. External DSL
•Internal DSL (内部DSL)
 •Written inside an existing host language
   既存の言語を使って、その言語の文法を使って書かれたDSL

 •No need to implement parser
   パーサを書く必要なし

 •Some lang are not good at internal DSL
   言語によっては苦手な場合がある

•External DSL (外部DSL)      Python?
 •Original, indendent syntax
   独自の文法

 •Need to implement parser
   パーサを実装する必要あり

 •All languages have same power about external DSL
   言語による得手不得手は、ほぼない
Fantastic 'with' Statement
What is 'with' statement?

•Enforces finishing       ## Python 2.4
 process                 f = open('file')
 終了処理を強制する機能             try:
 •ex: close opened file     text = f.read()
  certainly              finally:
   例:ファイルを必ず閉じる            f.close()

                         ## Python 2.5 or later
                         with open('file') as f:
                          text = f.read()
How to use 'with' statement in DSL?

•Appends pre-
                             Append pre-process
 process and post-                 前処理を追加
 process around

                               }
 block                 x=1
 ブロックに前処理と後処理をくっ
                       y=2         code block
 つける                   z=3

                            Append post-process
                                   後処理を追加
Case Study: Change Directory (Kook)

## before               ## after
chdir('build')          with chdir('build'):
cp('../file', 'file')     cp('../file', 'file')
system('cmd...')          system('cmd...')
chdir('..')
Case Study: Start/Stop time (Benchmarker)

## before              ## after
t1 = time.time()       bm = Benchmarker()
for i in xrange(N):    with bm('func'):
   func()                for i in xrange(N):
t2 = time.time()            func()
print('func: %s'
        % (t2-t1))
Case Study: Form Builder

 ## before
 <form action="/" method="POST">
  <input type="hidden" name="_csrf"
         value="${request.csrf()}" />
  <input type="text" ... />
  <input type="submit" ... />
 </form>
Case Study: Form Builder

 ## after
 % with FormBuilder(request, "/") as fb:
  <input type="text" ... />
  <input type="submit" ... />
 % endwith
Pitfall: Variable Scope

 with test("arithmetic operation"):

    with test("1+1 should be 1"):
      x = 1+1
      assert x == 2

    with test("1-1 should be 0"):
      x = 1-1         Identical variable because
      assert x == 0 scope is not independented
                          スコープが独立してないので変数も共有される
Pitfall: Cannot Skip Block!

 <div>
 % with cache("key", 60*60*1):
   <ul>
   % for item in get_items():
   <li>${item}</li>
   % endfor        You may want to skip block
   </ul>           when cache is not expired,
 % endwith         but Python doesn't allow it!
 </div>            キャッシュが生きている間はブロックを
                      スキップしたいんだけど、実はできない
Fantastic 'for' Statement
What is 'for' statement?

•Iterates code block       ## repeat 100 times
 ブロックを繰り返す機能               for i in xrange(100):
 •ex: repeat block for N     print("i=%s" % i)
  times
   例:ブロックをN回実行             ## read lines from file
                           with open('file') as f:
 •ex: read each line         for line in f:
  from opened file
                                print(line)
  例:オープンしたファイルから
  1行ずつ読み込む
How to use 'for' statement in DSL? #1

•Appends pre-
                             Append pre-process
 process and post-                 前処理を追加
 process around

                              }
 iteration block       x=1
 繰り返し用のブロックに
                       y=2        iteration block
 前処理と後処理をくっつける         z=3

                            Append post-process
                                   後処理を追加
How to use 'for' statement in DSL? #1

•Appends pre-
                       def gfunc():
 process and post-
 process around
 iteration block
                         ....
                         ....   }pre-process

 繰り返し用のブロックに             for i in xrange(n):

                                    } exec block
 前処理と後処理をくっつける

                           yield
                         ....
                         ....   }    post-process
Case Study: Start/Stop time (Benchmarker)

## before              ## after
t1 = time.time()       bm = Benchmarker(
for i in xrange(N):             repeat=N)
   func1()             for _ in bm('func'):
t2 = time.time()         func1()
print('func: %s'
        % (t2-t1))
How to use 'for' statement in DSL? #2

•Iterate code block
                        def gfunc():
 only once
 ブロックを1回だけ繰り返す
                          ....
                          ....  } pre-process

                          yield } exec block
                                   (only once!)
•Emulates 'with' stmt     ....
 by 'for' stmt            .... }  post-process
 with文をfor文でエミュレート
Case Study: Change Directory (Kook)

## before               ## after
chdir('tmp')            for _ in chdir('tmp'):
cp('../file', 'file')     cp('../file', 'file')
system('cmd...')          system('cmd...')
chdir('..')

                          Use 'for' as alternative
                          of 'with' in Python 2.4
                          Python2.4では 'with' が使えない
                          ので、代わりとして 'for' を使う
How to use 'for' statement in DSL? #3

•Iterate block in 0 or
                         def gfunc():
 1 time
 ブロックを0回または1回だけ
 繰り返す
                           ....
                           ....   }pre-process

                           if condition:

                                      }
•Emulates 'if' stmt by
 'for' stmt to skip           yield       exec block
 block according to        ....
 condition
 if文をfor文でエミュレートし、条
                           ....   }   post-process

 件によってブロックをスキップ
Case Study: Fragment Cache (Tenjin)

 <div>
 % for _ in cache("key", 60*60*1):
   <ul>
   % for item in get_items():
   <li>${item}</li>
   % endfor         You can skip block when
   </ul>           cache is not expired! Wow!
 % endfor          with文と違い、キャッシュが生きている

 </div>            ときにブロックをスキップできる! ステキ!
Case Study: Java and JSP

 <div>
 <% for (int _: cache("key",60)) { %>
   <ul>
   <% for (Item item: getItems()) { %>
   <li>${item}</li>
   <% } %>
   </ul>
 <% } %>
 </div>
Fantastic Decorator
What is Decorator?

•Higher-order function   class Hello(object):
 to manipulate
 declaring function or    @classmethod
 class                    def fn(cls):
 宣言中の関数やクラスを操作する            print("Hello")
 高階関数

 •ex: @classmethod(),     ## above is same as
      @property()         def fn(cls):
   例:@classmethod(),
                            print("Hello")
      @property           fn = classmethod(fn)
How to use Decorator in DSL? #1

•Mark function with
                      def deco(func):
 or without args
                       func._mark = True
 関数に目印をつける
                       return func

                      def deco_with(arg):
                       def deco(func):
                         func._mark = arg
                         return func
                       deco
Case Study: Marking and Options (Kook)

@recipe
def test(c):
 system("python -m oktest test")

@recipe("*.o")
@ingreds("$(1).c", if_exist="$(1).h")
def file_o(c):
 system(c%'gcc -o $(product) $(ingred)')
How to use Decorator in DSL? #2

•Syntax sugar to
                      def fn(arg):
 pass function arg
                        print(arg)
 引数として関数を渡すときの
 シンタックスシュガー           func(x, y, fn)



                      @func(x, y)
                      def fn(arg):
                        print(arg)
Case Study: Event Handler

## before              ## after
def _():               @button.onclick
 do()                  def _():
 some()                  do()
 thing()                 some()
button.onclick(_)        thing()
                            More readable because
                            @onclick appears first
                              ブロックより先に@onclickが
                              きているのでより読みやすい
Case Study: Database Transaction

## before              ## after
def _():               @transaction
  do()                 def _():
  some()                 do()
  thing()                some()
transaction(_)           thing()
                         More readable because
                        @transaction appears first
                          ブロックより先に@transactionが
                           現れるので、より読みやすい
Case Study: unittest

## before               ## after
def _():                @assertRaise2(Err)
  do()                  def _():
  some()                 do()
  thing()                some()
assertRaise(Err, _)      thing()

                        More readable because
                       assertRailse() appears first
                       assertRaises2()のほうがブロックより
                        先に現れるので、より読みやすい
How to use Decorator in DSL? #3

•Alternative syntax of
                         with func(arg) as x:
 with- or for-
                           ....
 statement
 with文やfor文の代替

  •Independent scope!
   独立したスコープ!
                         @func(arg)
  •Nested scope!         def _(x):
   入れ子になったスコープ!            ....
Case Study: open()

## before            ## after
with open('file',    @open('file', 'w')
'w') as f:           def _(f):
  f.write("....")      f.write("....")
How to use Decorator in DSL? #4

•Alternative syntax of
                           class Foo(object):
 class definition
                              def meth1(self):
 class定義の代替
                                ....
  •More natural
   representation of
   inheritance structure
                           @classdef
   継承構造のより自然な表現
                           def _():
  •More natural scope        @methoddef
   より自然なスコープ
                             def _():
                                ....
Class Inheritance

class Parent(object):
   ....

class Child(Parent):
   ....
                        Inheritance structure
class Baby(Child):        is not represented
   ....                         visually
                          継承構造が視覚的には
                           表現されていない
Nested Class Definition

class Parent(object):

  class Child(Parent):
                               Represents
     class Baby(Child):   inheritance structure
        ....                 visually, but not
                           possible in Python!
                            こう書けば継承構造が視
                            覚的に表現できるけど、
                            Pythonではこう書けない!
Nested Structure by with-statement

with define('Parent'):

  with define('Child'):

     with define('Baby'):    Represents structure
       ....                   visually, but scopes
                             are not independent
                              構造は視覚的に表現でき
                              ているが、スコープが独
                              立していない (共有される)
Nested Structure with Decorator

@defclass
def Parent():

  @defclass
  def Child():               Represents structure
                             visually, and scopes
     @defclass                  are not shared
     def Baby():              継承構造を視覚的に表現
                              できるし、スコープも共
       ....                   有されない (独立している)
Strange Scope Rule (for beginner) in Class Definition

1: class Outer(object):
2: VAR = 1
3:
4: class Inner(object):
5:      # error
6:      print(VAR)                Why I can't access
7:      # error, too              to outer variable?
8:      print(Outer.VAR)            どうして外側の変数に
                                    アクセスできないの?
Natural Scope Rule (for beginner) with Function

1: def outer():
2: VAR = 1
3:
4: def middle():
5:      print(VAR) # OK                More natual
6:                                     scope rule
7:      def inner():              (especially for beginner)

8:         print(VAR) # OK         より自然なスコープルール
                                    (特に初心者にとっては)
Case Study: RSpec

describe("Class1") do

  describe("#method1()") do

   it("should return None") do
     Class1.new.method1().should be_nil
   end

 end
end
Case Study: RSpec

class Class1Test(TestCase):

  class method1Test(Class1Test):

   def test_should_return_None(self):
    assert Class1().method1() is None
Case Study: RSpec

@describe("Class1")
def _():

  @describe("#method1()")
  def _():

    @it("should return None")
    def _(self):
      assert Class1().method1() is None
Case Study: RSpec

@describe("Class1")
def _():        Variables in outer are...
  def this():    外側の関数で定義された変数に...

     return Class1()
  @describe("#method1()")
  def _():
     @it("should return None")
     def _(self):
       assert this().method1() is None
                    Accessable from inner!
                  内側の関数から自然にアクセスできる!
Fantastic Operator
Operator Override


 1: class Node(object):
 2: def __init__(self, op, left, right):
 3:      self.op, self.left, self.right = 
 4: Overrides '==' operator   op, left, right
 5:
 6: def __eq__(self, other):
 7:      return Node('==', self, other)
 8: def __ne__(self, other):
 9:      return Node('!=', self, other)
               Overrides '!=' operator
Expression Evaluation v.s. AST

Expression Evaluation

           x+1                                          2

AST (Abstract Syntax Tree)
                                                            +
           x+1
                                                        x       1
参考: http://www.slideshare.net/kwatch/dsl-presentation
Case Study: Modern O/R Mapper (SQLAlchemy)
 Python                            SQL


                     ==
 x == 1                           x=1
                 x        1

                     ==
x == None                         x is null
                 x    None
Case Study: Assertion (Oktest)

Assertion                 When Failed
 ##	 Python	 	 	 	 	 	 	 	 	 AssertionError:
 assert	 x	 ==	 y	 	 	 	 	 	 (no message)

 ##	 Nose	 	 	 	 	 	 	 	 	 	 	 AssertionError:
 ok_(x	 ==	 y)	 	 	 	 	 	 	 	 (no message)

 ##	 Oktest	 	 	 	 	 	 	 	 	 AssertionError:
 ok	 (x)	 ==	 y	 	 	 	 	 	 	 	 1	 ==	 2	 :	 failed
                    Shows actual & expected values
                     失敗時に、実際値と期待値を表示してくれる
Case Study: Assertion (Oktest)

Oktest                    Oktest() returns AssertionObject
                           ok() はAssertionObject のインスタンスを返す
 >>> ok (1+1)
 <oktest.AssertionObject object>

 >>> ok (1+1).__eq__(1)
 Traceback (most recent call last):
  ...
 AssertionError: 2 == 1 : failed.
                                  Overrides '==' operator
                                 '==' 演算子をオーバーライドしている


参考: http://goo.gl/C6Eun
Case Study: String Interpolation (Kook)

CMD	 =	 'rst2html	 -i	 utf-8'

@recipe('*.html')
@ingreds('$(1).txt')                   Low readability
def	 file_html(c):                        可読性が低い

	 	 system("%s	 %s	 >	 %s"	 %	 
	 	 	 	 	 	 	 	 	 	 (CMD,	 c.ingreds[0],	 c.product))
	 	 #	 or
	 	 cmd,prod,ingred	 =	 CC,c.product,c.ingreds[0]
	 	 system("%(cmd)s	 %(ingred)s	 >	 %(prod)s"	 %
	 	 	 	 	 	 	 	 	 	 	 locals())
                                  Name only, No expression
                                 名前のみで式が使えない
Case Study: String Interpolation (Kook)
    http://www.kuwata-lab.com/kook/pykook-users-guide.html#cookbook-prod

 CMD	 =	 'rst2html	 -i	 utf-8'

 @recipe('hello')
 @ingreds('hello.c')
 def	 compile(c):
 	 	 prod,	 ingreds	 =	 c.product,	 c.ingreds
 	 	 system(c%"$(CMD)	 $(ingreds[0])	 >	 $(prod)")

 Operator                                              Indexing
 override              Both global and                 available
演算子オーバーライド            local var available               添字も利用可能

                       グローバル変数とローカル
                        変数の両方が利用可能
Case Study: Method Chain Finishing Problem


 AppointmentBuilder()	 
 	 .From(1300)	 
 	 .To(1400)	 
 	 .For("Dental")	 
 	 .done()
         Method chain requires end of chain.
       メソッドチェーンでは、チェーンの終わりを明示する必要がある
Case Study: Method Chain Finishing Problem


 -	 AppointmentBuilder()	 
 	 	 	 .From(1300)	 
 	 	 	 .To(1400)	 
 	 	 	 .For("Dental")

     Unary operator works at end of chain!
         単項演算子はチェーンの終わりに実行される!

     Very similar to unordered list or bullet!
                見た目が箇条書きそっくり!
Reflected operator


 class	 Foo(object):

 	 	 def	 __add__(self,	 other):
 	 	 	 	 ...   foo + 1


 	 	 def	 __radd__(self,	 other):
 	 	 	 	 ...    1 + foo
Reflected operator


 def	 __add__(self,	 other):
 	 	 	 ...
 int.__add__	 =	 __add__
 1	 +	 Foo()    Not possible ;<
                    Pythonではできない

 class	 Foo(object):
 	 	 	 def	 __radd__(self,	 other):
 	 	 	 	 	 	 ...  No problem :)
 1	 +	 Foo()         問題なし
Case Study: Should DSL
                                http://www.should-dsl.info/

def	 test1(self):
	 	 self.player	 |should|	 have(11).cards

def	 test2(self):
	 	 self.player.name	 |should|	 
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 equal_to('John	 Doe')

         Instead of adding method to any object,
          use bit operator which has low priority
        ビットOR演算子の優先順位が低いことを利用して、任意のオブジェクトに
         メソッドを追加できないというPythonの欠点を克服した、絶妙なDSL
One more thing...
DSL設計者に贈る言葉

「キモイ」は褒め言葉!

古参のイチャモンは新規性の証し!

オレが書きたいように書けないのはPythonが悪い!
おしまい

More Related Content

What's hot

クリスマスに工場(Factorio)を作るゲームをしよう
クリスマスに工場(Factorio)を作るゲームをしようクリスマスに工場(Factorio)を作るゲームをしよう
クリスマスに工場(Factorio)を作るゲームをしようMasahito Zembutsu
 
正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?kwatch
 
SAT/SMTソルバの仕組み
SAT/SMTソルバの仕組みSAT/SMTソルバの仕組み
SAT/SMTソルバの仕組みMasahiro Sakai
 
情報検索の基礎
情報検索の基礎情報検索の基礎
情報検索の基礎Retrieva inc.
 
暗号文のままで計算しよう - 準同型暗号入門 -
暗号文のままで計算しよう - 準同型暗号入門 -暗号文のままで計算しよう - 準同型暗号入門 -
暗号文のままで計算しよう - 準同型暗号入門 -MITSUNARI Shigeo
 
Re永続データ構造が分からない人のためのスライド
Re永続データ構造が分からない人のためのスライドRe永続データ構造が分からない人のためのスライド
Re永続データ構造が分からない人のためのスライドMasaki Hara
 
C#/.NETがやっていること 第二版
C#/.NETがやっていること 第二版C#/.NETがやっていること 第二版
C#/.NETがやっていること 第二版信之 岩永
 
Amortize analysis of Deque with 2 Stack
Amortize analysis of Deque with 2 StackAmortize analysis of Deque with 2 Stack
Amortize analysis of Deque with 2 StackKen Ogura
 
プログラミングコンテストでのデータ構造 2 ~動的木編~
プログラミングコンテストでのデータ構造 2 ~動的木編~プログラミングコンテストでのデータ構造 2 ~動的木編~
プログラミングコンテストでのデータ構造 2 ~動的木編~Takuya Akiba
 
Rustに触れて私のPythonはどう変わったか
Rustに触れて私のPythonはどう変わったかRustに触れて私のPythonはどう変わったか
Rustに触れて私のPythonはどう変わったかShunsukeNakamura17
 
勉強か?趣味か?人生か?―プログラミングコンテストとは
勉強か?趣味か?人生か?―プログラミングコンテストとは勉強か?趣味か?人生か?―プログラミングコンテストとは
勉強か?趣味か?人生か?―プログラミングコンテストとはTakuya Akiba
 
CTF for ビギナーズ バイナリ講習資料
CTF for ビギナーズ バイナリ講習資料CTF for ビギナーズ バイナリ講習資料
CTF for ビギナーズ バイナリ講習資料SECCON Beginners
 
ユークリッド最小全域木
ユークリッド最小全域木ユークリッド最小全域木
ユークリッド最小全域木理玖 川崎
 
すごい配列楽しく学ぼう
すごい配列楽しく学ぼうすごい配列楽しく学ぼう
すごい配列楽しく学ぼうxenophobia__
 
Constexprとtemplateでコンパイル時にfizz buzz
Constexprとtemplateでコンパイル時にfizz buzzConstexprとtemplateでコンパイル時にfizz buzz
Constexprとtemplateでコンパイル時にfizz buzz京大 マイコンクラブ
 

What's hot (20)

クリスマスに工場(Factorio)を作るゲームをしよう
クリスマスに工場(Factorio)を作るゲームをしようクリスマスに工場(Factorio)を作るゲームをしよう
クリスマスに工場(Factorio)を作るゲームをしよう
 
最大流 (max flow)
最大流 (max flow)最大流 (max flow)
最大流 (max flow)
 
双対性
双対性双対性
双対性
 
Rolling hash
Rolling hashRolling hash
Rolling hash
 
正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?
 
SAT/SMTソルバの仕組み
SAT/SMTソルバの仕組みSAT/SMTソルバの仕組み
SAT/SMTソルバの仕組み
 
Chokudai search
Chokudai searchChokudai search
Chokudai search
 
情報検索の基礎
情報検索の基礎情報検索の基礎
情報検索の基礎
 
暗号文のままで計算しよう - 準同型暗号入門 -
暗号文のままで計算しよう - 準同型暗号入門 -暗号文のままで計算しよう - 準同型暗号入門 -
暗号文のままで計算しよう - 準同型暗号入門 -
 
Re永続データ構造が分からない人のためのスライド
Re永続データ構造が分からない人のためのスライドRe永続データ構造が分からない人のためのスライド
Re永続データ構造が分からない人のためのスライド
 
C#/.NETがやっていること 第二版
C#/.NETがやっていること 第二版C#/.NETがやっていること 第二版
C#/.NETがやっていること 第二版
 
Amortize analysis of Deque with 2 Stack
Amortize analysis of Deque with 2 StackAmortize analysis of Deque with 2 Stack
Amortize analysis of Deque with 2 Stack
 
プログラミングコンテストでのデータ構造 2 ~動的木編~
プログラミングコンテストでのデータ構造 2 ~動的木編~プログラミングコンテストでのデータ構造 2 ~動的木編~
プログラミングコンテストでのデータ構造 2 ~動的木編~
 
文字列アルゴリズム
文字列アルゴリズム文字列アルゴリズム
文字列アルゴリズム
 
Rustに触れて私のPythonはどう変わったか
Rustに触れて私のPythonはどう変わったかRustに触れて私のPythonはどう変わったか
Rustに触れて私のPythonはどう変わったか
 
勉強か?趣味か?人生か?―プログラミングコンテストとは
勉強か?趣味か?人生か?―プログラミングコンテストとは勉強か?趣味か?人生か?―プログラミングコンテストとは
勉強か?趣味か?人生か?―プログラミングコンテストとは
 
CTF for ビギナーズ バイナリ講習資料
CTF for ビギナーズ バイナリ講習資料CTF for ビギナーズ バイナリ講習資料
CTF for ビギナーズ バイナリ講習資料
 
ユークリッド最小全域木
ユークリッド最小全域木ユークリッド最小全域木
ユークリッド最小全域木
 
すごい配列楽しく学ぼう
すごい配列楽しく学ぼうすごい配列楽しく学ぼう
すごい配列楽しく学ぼう
 
Constexprとtemplateでコンパイル時にfizz buzz
Constexprとtemplateでコンパイル時にfizz buzzConstexprとtemplateでコンパイル時にfizz buzz
Constexprとtemplateでコンパイル時にfizz buzz
 

Viewers also liked

Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonSiddhi
 
20 examples on Domain-Specific Modeling Languages
20 examples on Domain-Specific Modeling Languages20 examples on Domain-Specific Modeling Languages
20 examples on Domain-Specific Modeling LanguagesJuha-Pekka Tolvanen
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific LanguagesJavier Canovas
 
Internal DSLs For Automated Functional Testing
Internal DSLs For Automated Functional TestingInternal DSLs For Automated Functional Testing
Internal DSLs For Automated Functional TestingJohn Sonmez
 
DSL in test automation
DSL in test automationDSL in test automation
DSL in test automationtest test
 
Real world DSL - making technical and business people speaking the same language
Real world DSL - making technical and business people speaking the same languageReal world DSL - making technical and business people speaking the same language
Real world DSL - making technical and business people speaking the same languageMario Fusco
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLsIndicThreads
 
The Unbearable Stupidity of Modeling
The Unbearable Stupidity of ModelingThe Unbearable Stupidity of Modeling
The Unbearable Stupidity of ModelingPeter Friese
 
おしゃべりゆかり 外部ツールによるMMDAgent操作
おしゃべりゆかり 外部ツールによるMMDAgent操作おしゃべりゆかり 外部ツールによるMMDAgent操作
おしゃべりゆかり 外部ツールによるMMDAgent操作kouji azuma
 
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策kwatch
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaTomer Gabel
 
Introducción a DSL (Lenguajes Específicos de Dominios) con Python
Introducción a DSL (Lenguajes Específicos de Dominios) con PythonIntroducción a DSL (Lenguajes Específicos de Dominios) con Python
Introducción a DSL (Lenguajes Específicos de Dominios) con PythonJuan Rodríguez
 
How Spark is Making an Impact at Goldman Sachs by Vincent Saulys
How Spark is Making an Impact at Goldman Sachs by Vincent SaulysHow Spark is Making an Impact at Goldman Sachs by Vincent Saulys
How Spark is Making an Impact at Goldman Sachs by Vincent SaulysSpark Summit
 
SI屋のためのF# ~DSL編~
SI屋のためのF# ~DSL編~SI屋のためのF# ~DSL編~
SI屋のためのF# ~DSL編~bleis tift
 

Viewers also liked (18)

Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
 
20 examples on Domain-Specific Modeling Languages
20 examples on Domain-Specific Modeling Languages20 examples on Domain-Specific Modeling Languages
20 examples on Domain-Specific Modeling Languages
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific Languages
 
Internal DSLs For Automated Functional Testing
Internal DSLs For Automated Functional TestingInternal DSLs For Automated Functional Testing
Internal DSLs For Automated Functional Testing
 
DSL in test automation
DSL in test automationDSL in test automation
DSL in test automation
 
Real world DSL - making technical and business people speaking the same language
Real world DSL - making technical and business people speaking the same languageReal world DSL - making technical and business people speaking the same language
Real world DSL - making technical and business people speaking the same language
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLs
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
The Unbearable Stupidity of Modeling
The Unbearable Stupidity of ModelingThe Unbearable Stupidity of Modeling
The Unbearable Stupidity of Modeling
 
おしゃべりゆかり 外部ツールによるMMDAgent操作
おしゃべりゆかり 外部ツールによるMMDAgent操作おしゃべりゆかり 外部ツールによるMMDAgent操作
おしゃべりゆかり 外部ツールによるMMDAgent操作
 
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
 
Scala DSLの作り方
Scala DSLの作り方Scala DSLの作り方
Scala DSLの作り方
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in Scala
 
Logic programming in python
Logic programming in pythonLogic programming in python
Logic programming in python
 
Introducción a DSL (Lenguajes Específicos de Dominios) con Python
Introducción a DSL (Lenguajes Específicos de Dominios) con PythonIntroducción a DSL (Lenguajes Específicos de Dominios) con Python
Introducción a DSL (Lenguajes Específicos de Dominios) con Python
 
RubyでDSL
RubyでDSLRubyでDSL
RubyでDSL
 
How Spark is Making an Impact at Goldman Sachs by Vincent Saulys
How Spark is Making an Impact at Goldman Sachs by Vincent SaulysHow Spark is Making an Impact at Goldman Sachs by Vincent Saulys
How Spark is Making an Impact at Goldman Sachs by Vincent Saulys
 
SI屋のためのF# ~DSL編~
SI屋のためのF# ~DSL編~SI屋のためのF# ~DSL編~
SI屋のためのF# ~DSL編~
 

Similar to PyConJP 2012: Fantastic DSL in Python

Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And BeyondMike Fogus
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring ClojurescriptLuke Donnet
 
Spock: Test Well and Prosper
Spock: Test Well and ProsperSpock: Test Well and Prosper
Spock: Test Well and ProsperKen Kousen
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with ClojureJohn Stevenson
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019Leonardo Borges
 
Make Sure Your Applications Crash
Make Sure Your  Applications CrashMake Sure Your  Applications Crash
Make Sure Your Applications CrashMoshe Zadka
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
Lcna tutorial-2012
Lcna tutorial-2012Lcna tutorial-2012
Lcna tutorial-2012Gluster.org
 
Lcna 2012-tutorial
Lcna 2012-tutorialLcna 2012-tutorial
Lcna 2012-tutorialGluster.org
 
Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in RustInfluxData
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the webMichiel Borkent
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)Jacek Laskowski
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures CodingMax Kleiner
 
How to use the new Domino Query Language
How to use the new Domino Query LanguageHow to use the new Domino Query Language
How to use the new Domino Query LanguageTim Davis
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v RubyJano Suchal
 
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverageTesting NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoveragemlilley
 
Clojure and Modularity
Clojure and ModularityClojure and Modularity
Clojure and Modularityelliando dias
 

Similar to PyConJP 2012: Fantastic DSL in Python (20)

Clojure 1.1 And Beyond
Clojure 1.1 And BeyondClojure 1.1 And Beyond
Clojure 1.1 And Beyond
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Spock: Test Well and Prosper
Spock: Test Well and ProsperSpock: Test Well and Prosper
Spock: Test Well and Prosper
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
DSL简介
DSL简介DSL简介
DSL简介
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019
 
Make Sure Your Applications Crash
Make Sure Your  Applications CrashMake Sure Your  Applications Crash
Make Sure Your Applications Crash
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
Lcna tutorial-2012
Lcna tutorial-2012Lcna tutorial-2012
Lcna tutorial-2012
 
Lcna 2012-tutorial
Lcna 2012-tutorialLcna 2012-tutorial
Lcna 2012-tutorial
 
Performance Profiling in Rust
Performance Profiling in RustPerformance Profiling in Rust
Performance Profiling in Rust
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
EKON 12 Closures Coding
EKON 12 Closures CodingEKON 12 Closures Coding
EKON 12 Closures Coding
 
How to use the new Domino Query Language
How to use the new Domino Query LanguageHow to use the new Domino Query Language
How to use the new Domino Query Language
 
Postobjektové programovanie v Ruby
Postobjektové programovanie v RubyPostobjektové programovanie v Ruby
Postobjektové programovanie v Ruby
 
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverageTesting NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
 
Clojure and Modularity
Clojure and ModularityClojure and Modularity
Clojure and Modularity
 

More from kwatch

How to make the fastest Router in Python
How to make the fastest Router in PythonHow to make the fastest Router in Python
How to make the fastest Router in Pythonkwatch
 
Migr8.rb チュートリアル
Migr8.rb チュートリアルMigr8.rb チュートリアル
Migr8.rb チュートリアルkwatch
 
なんでもID
なんでもIDなんでもID
なんでもIDkwatch
 
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方kwatch
 
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方kwatch
 
O/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐO/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐkwatch
 
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)kwatch
 
DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!kwatch
 
PHPとJavaScriptにおけるオブジェクト指向を比較する
PHPとJavaScriptにおけるオブジェクト指向を比較するPHPとJavaScriptにおけるオブジェクト指向を比較する
PHPとJavaScriptにおけるオブジェクト指向を比較するkwatch
 
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?kwatch
 
PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門kwatch
 
Pretty Good Branch Strategy for Git/Mercurial
Pretty Good Branch Strategy for Git/MercurialPretty Good Branch Strategy for Git/Mercurial
Pretty Good Branch Strategy for Git/Mercurialkwatch
 
Oktest - a new style testing library for Python -
Oktest - a new style testing library for Python -Oktest - a new style testing library for Python -
Oktest - a new style testing library for Python -kwatch
 
文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみた文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみたkwatch
 
I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"kwatch
 
Cより速いRubyプログラム
Cより速いRubyプログラムCより速いRubyプログラム
Cより速いRubyプログラムkwatch
 
Javaより速いLL用テンプレートエンジン
Javaより速いLL用テンプレートエンジンJavaより速いLL用テンプレートエンジン
Javaより速いLL用テンプレートエンジンkwatch
 
Underlaying Technology of Modern O/R Mapper
Underlaying Technology of Modern O/R MapperUnderlaying Technology of Modern O/R Mapper
Underlaying Technology of Modern O/R Mapperkwatch
 
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -kwatch
 
Benchmarker - A Good Friend for Performance
Benchmarker - A Good Friend for PerformanceBenchmarker - A Good Friend for Performance
Benchmarker - A Good Friend for Performancekwatch
 

More from kwatch (20)

How to make the fastest Router in Python
How to make the fastest Router in PythonHow to make the fastest Router in Python
How to make the fastest Router in Python
 
Migr8.rb チュートリアル
Migr8.rb チュートリアルMigr8.rb チュートリアル
Migr8.rb チュートリアル
 
なんでもID
なんでもIDなんでもID
なんでもID
 
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
 
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
 
O/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐO/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐ
 
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
 
DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!
 
PHPとJavaScriptにおけるオブジェクト指向を比較する
PHPとJavaScriptにおけるオブジェクト指向を比較するPHPとJavaScriptにおけるオブジェクト指向を比較する
PHPとJavaScriptにおけるオブジェクト指向を比較する
 
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
 
PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門
 
Pretty Good Branch Strategy for Git/Mercurial
Pretty Good Branch Strategy for Git/MercurialPretty Good Branch Strategy for Git/Mercurial
Pretty Good Branch Strategy for Git/Mercurial
 
Oktest - a new style testing library for Python -
Oktest - a new style testing library for Python -Oktest - a new style testing library for Python -
Oktest - a new style testing library for Python -
 
文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみた文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみた
 
I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"
 
Cより速いRubyプログラム
Cより速いRubyプログラムCより速いRubyプログラム
Cより速いRubyプログラム
 
Javaより速いLL用テンプレートエンジン
Javaより速いLL用テンプレートエンジンJavaより速いLL用テンプレートエンジン
Javaより速いLL用テンプレートエンジン
 
Underlaying Technology of Modern O/R Mapper
Underlaying Technology of Modern O/R MapperUnderlaying Technology of Modern O/R Mapper
Underlaying Technology of Modern O/R Mapper
 
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -
 
Benchmarker - A Good Friend for Performance
Benchmarker - A Good Friend for PerformanceBenchmarker - A Good Friend for Performance
Benchmarker - A Good Friend for Performance
 

Recently uploaded

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesSanjay Willie
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Recently uploaded (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your QueriesExploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
Exploring ChatGPT Prompt Hacks To Maximally Optimise Your Queries
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

PyConJP 2012: Fantastic DSL in Python

  • 1. PyConJP 2012 Fantastic DSL in Python Makoto Kuwata <kwa@kuwata-lab.com> http://www.kuwata-lab.com/ 2012-09-16 (Sun) Video: http://www.youtube.com/watch?v=l8ptNmtB0G8
  • 2. Agenda •About DSL •Fantastic 'with' statement •Fantastic 'for' statement •Fantastic Decorator •Fantastic Operator
  • 4. What is DSL (Domain Specific Language?) DSL Google Search
  • 5. Internal DSL v.s. External DSL •Internal DSL (内部DSL) •Written inside an existing host language 既存の言語を使って、その言語の文法を使って書かれたDSL •No need to implement parser パーサを書く必要なし •Some lang are not good at internal DSL 言語によっては苦手な場合がある •External DSL (外部DSL) Python? •Original, indendent syntax 独自の文法 •Need to implement parser パーサを実装する必要あり •All languages have same power about external DSL 言語による得手不得手は、ほぼない
  • 7. What is 'with' statement? •Enforces finishing ## Python 2.4 process f = open('file') 終了処理を強制する機能 try: •ex: close opened file text = f.read() certainly finally: 例:ファイルを必ず閉じる f.close() ## Python 2.5 or later with open('file') as f: text = f.read()
  • 8. How to use 'with' statement in DSL? •Appends pre- Append pre-process process and post- 前処理を追加 process around } block x=1 ブロックに前処理と後処理をくっ y=2 code block つける z=3 Append post-process 後処理を追加
  • 9. Case Study: Change Directory (Kook) ## before ## after chdir('build') with chdir('build'): cp('../file', 'file') cp('../file', 'file') system('cmd...') system('cmd...') chdir('..')
  • 10. Case Study: Start/Stop time (Benchmarker) ## before ## after t1 = time.time() bm = Benchmarker() for i in xrange(N): with bm('func'): func() for i in xrange(N): t2 = time.time() func() print('func: %s' % (t2-t1))
  • 11. Case Study: Form Builder ## before <form action="/" method="POST"> <input type="hidden" name="_csrf" value="${request.csrf()}" /> <input type="text" ... /> <input type="submit" ... /> </form>
  • 12. Case Study: Form Builder ## after % with FormBuilder(request, "/") as fb: <input type="text" ... /> <input type="submit" ... /> % endwith
  • 13. Pitfall: Variable Scope with test("arithmetic operation"): with test("1+1 should be 1"): x = 1+1 assert x == 2 with test("1-1 should be 0"): x = 1-1 Identical variable because assert x == 0 scope is not independented スコープが独立してないので変数も共有される
  • 14. Pitfall: Cannot Skip Block! <div> % with cache("key", 60*60*1): <ul> % for item in get_items(): <li>${item}</li> % endfor You may want to skip block </ul> when cache is not expired, % endwith but Python doesn't allow it! </div> キャッシュが生きている間はブロックを スキップしたいんだけど、実はできない
  • 16. What is 'for' statement? •Iterates code block ## repeat 100 times ブロックを繰り返す機能 for i in xrange(100): •ex: repeat block for N print("i=%s" % i) times 例:ブロックをN回実行 ## read lines from file with open('file') as f: •ex: read each line for line in f: from opened file print(line) 例:オープンしたファイルから 1行ずつ読み込む
  • 17. How to use 'for' statement in DSL? #1 •Appends pre- Append pre-process process and post- 前処理を追加 process around } iteration block x=1 繰り返し用のブロックに y=2 iteration block 前処理と後処理をくっつける z=3 Append post-process 後処理を追加
  • 18. How to use 'for' statement in DSL? #1 •Appends pre- def gfunc(): process and post- process around iteration block .... .... }pre-process 繰り返し用のブロックに for i in xrange(n): } exec block 前処理と後処理をくっつける yield .... .... } post-process
  • 19. Case Study: Start/Stop time (Benchmarker) ## before ## after t1 = time.time() bm = Benchmarker( for i in xrange(N): repeat=N) func1() for _ in bm('func'): t2 = time.time() func1() print('func: %s' % (t2-t1))
  • 20. How to use 'for' statement in DSL? #2 •Iterate code block def gfunc(): only once ブロックを1回だけ繰り返す .... .... } pre-process yield } exec block (only once!) •Emulates 'with' stmt .... by 'for' stmt .... } post-process with文をfor文でエミュレート
  • 21. Case Study: Change Directory (Kook) ## before ## after chdir('tmp') for _ in chdir('tmp'): cp('../file', 'file') cp('../file', 'file') system('cmd...') system('cmd...') chdir('..') Use 'for' as alternative of 'with' in Python 2.4 Python2.4では 'with' が使えない ので、代わりとして 'for' を使う
  • 22. How to use 'for' statement in DSL? #3 •Iterate block in 0 or def gfunc(): 1 time ブロックを0回または1回だけ 繰り返す .... .... }pre-process if condition: } •Emulates 'if' stmt by 'for' stmt to skip yield exec block block according to .... condition if文をfor文でエミュレートし、条 .... } post-process 件によってブロックをスキップ
  • 23. Case Study: Fragment Cache (Tenjin) <div> % for _ in cache("key", 60*60*1): <ul> % for item in get_items(): <li>${item}</li> % endfor You can skip block when </ul> cache is not expired! Wow! % endfor with文と違い、キャッシュが生きている </div> ときにブロックをスキップできる! ステキ!
  • 24. Case Study: Java and JSP <div> <% for (int _: cache("key",60)) { %> <ul> <% for (Item item: getItems()) { %> <li>${item}</li> <% } %> </ul> <% } %> </div>
  • 26. What is Decorator? •Higher-order function class Hello(object): to manipulate declaring function or @classmethod class def fn(cls): 宣言中の関数やクラスを操作する print("Hello") 高階関数 •ex: @classmethod(), ## above is same as @property() def fn(cls): 例:@classmethod(), print("Hello") @property fn = classmethod(fn)
  • 27. How to use Decorator in DSL? #1 •Mark function with def deco(func): or without args func._mark = True 関数に目印をつける return func def deco_with(arg): def deco(func): func._mark = arg return func deco
  • 28. Case Study: Marking and Options (Kook) @recipe def test(c): system("python -m oktest test") @recipe("*.o") @ingreds("$(1).c", if_exist="$(1).h") def file_o(c): system(c%'gcc -o $(product) $(ingred)')
  • 29. How to use Decorator in DSL? #2 •Syntax sugar to def fn(arg): pass function arg print(arg) 引数として関数を渡すときの シンタックスシュガー func(x, y, fn) @func(x, y) def fn(arg): print(arg)
  • 30. Case Study: Event Handler ## before ## after def _(): @button.onclick do() def _(): some() do() thing() some() button.onclick(_) thing() More readable because @onclick appears first ブロックより先に@onclickが きているのでより読みやすい
  • 31. Case Study: Database Transaction ## before ## after def _(): @transaction do() def _(): some() do() thing() some() transaction(_) thing() More readable because @transaction appears first ブロックより先に@transactionが 現れるので、より読みやすい
  • 32. Case Study: unittest ## before ## after def _(): @assertRaise2(Err) do() def _(): some() do() thing() some() assertRaise(Err, _) thing() More readable because assertRailse() appears first assertRaises2()のほうがブロックより 先に現れるので、より読みやすい
  • 33. How to use Decorator in DSL? #3 •Alternative syntax of with func(arg) as x: with- or for- .... statement with文やfor文の代替 •Independent scope! 独立したスコープ! @func(arg) •Nested scope! def _(x): 入れ子になったスコープ! ....
  • 34. Case Study: open() ## before ## after with open('file', @open('file', 'w') 'w') as f: def _(f): f.write("....") f.write("....")
  • 35. How to use Decorator in DSL? #4 •Alternative syntax of class Foo(object): class definition def meth1(self): class定義の代替 .... •More natural representation of inheritance structure @classdef 継承構造のより自然な表現 def _(): •More natural scope @methoddef より自然なスコープ def _(): ....
  • 36. Class Inheritance class Parent(object): .... class Child(Parent): .... Inheritance structure class Baby(Child): is not represented .... visually 継承構造が視覚的には 表現されていない
  • 37. Nested Class Definition class Parent(object): class Child(Parent): Represents class Baby(Child): inheritance structure .... visually, but not possible in Python! こう書けば継承構造が視 覚的に表現できるけど、 Pythonではこう書けない!
  • 38. Nested Structure by with-statement with define('Parent'): with define('Child'): with define('Baby'): Represents structure .... visually, but scopes are not independent 構造は視覚的に表現でき ているが、スコープが独 立していない (共有される)
  • 39. Nested Structure with Decorator @defclass def Parent(): @defclass def Child(): Represents structure visually, and scopes @defclass are not shared def Baby(): 継承構造を視覚的に表現 できるし、スコープも共 .... 有されない (独立している)
  • 40. Strange Scope Rule (for beginner) in Class Definition 1: class Outer(object): 2: VAR = 1 3: 4: class Inner(object): 5: # error 6: print(VAR) Why I can't access 7: # error, too to outer variable? 8: print(Outer.VAR) どうして外側の変数に アクセスできないの?
  • 41. Natural Scope Rule (for beginner) with Function 1: def outer(): 2: VAR = 1 3: 4: def middle(): 5: print(VAR) # OK More natual 6: scope rule 7: def inner(): (especially for beginner) 8: print(VAR) # OK より自然なスコープルール (特に初心者にとっては)
  • 42. Case Study: RSpec describe("Class1") do describe("#method1()") do it("should return None") do Class1.new.method1().should be_nil end end end
  • 43. Case Study: RSpec class Class1Test(TestCase): class method1Test(Class1Test): def test_should_return_None(self): assert Class1().method1() is None
  • 44. Case Study: RSpec @describe("Class1") def _(): @describe("#method1()") def _(): @it("should return None") def _(self): assert Class1().method1() is None
  • 45. Case Study: RSpec @describe("Class1") def _(): Variables in outer are... def this(): 外側の関数で定義された変数に... return Class1() @describe("#method1()") def _(): @it("should return None") def _(self): assert this().method1() is None Accessable from inner! 内側の関数から自然にアクセスできる!
  • 47. Operator Override 1: class Node(object): 2: def __init__(self, op, left, right): 3: self.op, self.left, self.right = 4: Overrides '==' operator op, left, right 5: 6: def __eq__(self, other): 7: return Node('==', self, other) 8: def __ne__(self, other): 9: return Node('!=', self, other) Overrides '!=' operator
  • 48. Expression Evaluation v.s. AST Expression Evaluation x+1 2 AST (Abstract Syntax Tree) + x+1 x 1 参考: http://www.slideshare.net/kwatch/dsl-presentation
  • 49. Case Study: Modern O/R Mapper (SQLAlchemy) Python SQL == x == 1 x=1 x 1 == x == None x is null x None
  • 50. Case Study: Assertion (Oktest) Assertion When Failed ## Python AssertionError: assert x == y (no message) ## Nose AssertionError: ok_(x == y) (no message) ## Oktest AssertionError: ok (x) == y 1 == 2 : failed Shows actual & expected values 失敗時に、実際値と期待値を表示してくれる
  • 51. Case Study: Assertion (Oktest) Oktest Oktest() returns AssertionObject ok() はAssertionObject のインスタンスを返す >>> ok (1+1) <oktest.AssertionObject object> >>> ok (1+1).__eq__(1) Traceback (most recent call last): ... AssertionError: 2 == 1 : failed. Overrides '==' operator '==' 演算子をオーバーライドしている 参考: http://goo.gl/C6Eun
  • 52. Case Study: String Interpolation (Kook) CMD = 'rst2html -i utf-8' @recipe('*.html') @ingreds('$(1).txt') Low readability def file_html(c): 可読性が低い system("%s %s > %s" % (CMD, c.ingreds[0], c.product)) # or cmd,prod,ingred = CC,c.product,c.ingreds[0] system("%(cmd)s %(ingred)s > %(prod)s" % locals()) Name only, No expression 名前のみで式が使えない
  • 53. Case Study: String Interpolation (Kook) http://www.kuwata-lab.com/kook/pykook-users-guide.html#cookbook-prod CMD = 'rst2html -i utf-8' @recipe('hello') @ingreds('hello.c') def compile(c): prod, ingreds = c.product, c.ingreds system(c%"$(CMD) $(ingreds[0]) > $(prod)") Operator Indexing override Both global and available 演算子オーバーライド local var available 添字も利用可能 グローバル変数とローカル 変数の両方が利用可能
  • 54. Case Study: Method Chain Finishing Problem AppointmentBuilder() .From(1300) .To(1400) .For("Dental") .done() Method chain requires end of chain. メソッドチェーンでは、チェーンの終わりを明示する必要がある
  • 55. Case Study: Method Chain Finishing Problem - AppointmentBuilder() .From(1300) .To(1400) .For("Dental") Unary operator works at end of chain! 単項演算子はチェーンの終わりに実行される! Very similar to unordered list or bullet! 見た目が箇条書きそっくり!
  • 56. Reflected operator class Foo(object): def __add__(self, other): ... foo + 1 def __radd__(self, other): ... 1 + foo
  • 57. Reflected operator def __add__(self, other): ... int.__add__ = __add__ 1 + Foo() Not possible ;< Pythonではできない class Foo(object): def __radd__(self, other): ... No problem :) 1 + Foo() 問題なし
  • 58. Case Study: Should DSL http://www.should-dsl.info/ def test1(self): self.player |should| have(11).cards def test2(self): self.player.name |should| equal_to('John Doe') Instead of adding method to any object, use bit operator which has low priority ビットOR演算子の優先順位が低いことを利用して、任意のオブジェクトに メソッドを追加できないというPythonの欠点を克服した、絶妙なDSL