SlideShare ist ein Scribd-Unternehmen logo
1 von 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が悪い!
おしまい

Weitere ähnliche Inhalte

Was ist angesagt?

GoogleのSHA-1のはなし
GoogleのSHA-1のはなしGoogleのSHA-1のはなし
GoogleのSHA-1のはなしMITSUNARI Shigeo
 
C#でわかる こわくないMonad
C#でわかる こわくないMonadC#でわかる こわくないMonad
C#でわかる こわくないMonadKouji Matsui
 
RSA暗号運用でやってはいけない n のこと #ssmjp
RSA暗号運用でやってはいけない n のこと #ssmjpRSA暗号運用でやってはいけない n のこと #ssmjp
RSA暗号運用でやってはいけない n のこと #ssmjpsonickun
 
Pythonによる黒魔術入門
Pythonによる黒魔術入門Pythonによる黒魔術入門
Pythonによる黒魔術入門大樹 小倉
 
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭するCEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭するYoshifumi Kawai
 
Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링JANGWONSEO4
 
こわくない Git
こわくない Gitこわくない Git
こわくない GitKota Saito
 
Wiresharkの解析プラグインを作る ssmjp 201409
Wiresharkの解析プラグインを作る ssmjp 201409Wiresharkの解析プラグインを作る ssmjp 201409
Wiresharkの解析プラグインを作る ssmjp 201409稔 小林
 
ARM CPUにおけるSIMDを用いた高速計算入門
ARM CPUにおけるSIMDを用いた高速計算入門ARM CPUにおけるSIMDを用いた高速計算入門
ARM CPUにおけるSIMDを用いた高速計算入門Fixstars Corporation
 
PythonとPyCoRAMでお手軽にFPGAシステムを開発してみよう
PythonとPyCoRAMでお手軽にFPGAシステムを開発してみようPythonとPyCoRAMでお手軽にFPGAシステムを開発してみよう
PythonとPyCoRAMでお手軽にFPGAシステムを開発してみようShinya Takamaeda-Y
 
Redisの特徴と活用方法について
Redisの特徴と活用方法についてRedisの特徴と活用方法について
Redisの特徴と活用方法についてYuji Otani
 
サーバPUSHざっくりまとめ
サーバPUSHざっくりまとめサーバPUSHざっくりまとめ
サーバPUSHざっくりまとめYasuhiro Mawarimichi
 
kubernetes初心者がKnative Lambda Runtime触ってみた(Kubernetes Novice Tokyo #13 発表資料)
kubernetes初心者がKnative Lambda Runtime触ってみた(Kubernetes Novice Tokyo #13 発表資料)kubernetes初心者がKnative Lambda Runtime触ってみた(Kubernetes Novice Tokyo #13 発表資料)
kubernetes初心者がKnative Lambda Runtime触ってみた(Kubernetes Novice Tokyo #13 発表資料)NTT DATA Technology & Innovation
 
About GStreamer 1.0 application development for beginners
About GStreamer 1.0 application development for beginnersAbout GStreamer 1.0 application development for beginners
About GStreamer 1.0 application development for beginnersShota TAMURA
 
FridaによるAndroidアプリの動的解析とフッキングの基礎
FridaによるAndroidアプリの動的解析とフッキングの基礎FridaによるAndroidアプリの動的解析とフッキングの基礎
FridaによるAndroidアプリの動的解析とフッキングの基礎ken_kitahara
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?Moriharu Ohzu
 
GoらしいAPIを求める旅路 (Go Conference 2018 Spring)
GoらしいAPIを求める旅路 (Go Conference 2018 Spring)GoらしいAPIを求める旅路 (Go Conference 2018 Spring)
GoらしいAPIを求める旅路 (Go Conference 2018 Spring)lestrrat
 
Halide による画像処理プログラミング入門
Halide による画像処理プログラミング入門Halide による画像処理プログラミング入門
Halide による画像処理プログラミング入門Fixstars Corporation
 

Was ist angesagt? (20)

GoogleのSHA-1のはなし
GoogleのSHA-1のはなしGoogleのSHA-1のはなし
GoogleのSHA-1のはなし
 
C#でわかる こわくないMonad
C#でわかる こわくないMonadC#でわかる こわくないMonad
C#でわかる こわくないMonad
 
RSA暗号運用でやってはいけない n のこと #ssmjp
RSA暗号運用でやってはいけない n のこと #ssmjpRSA暗号運用でやってはいけない n のこと #ssmjp
RSA暗号運用でやってはいけない n のこと #ssmjp
 
Pythonによる黒魔術入門
Pythonによる黒魔術入門Pythonによる黒魔術入門
Pythonによる黒魔術入門
 
圏とHaskellの型
圏とHaskellの型圏とHaskellの型
圏とHaskellの型
 
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭するCEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
 
Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링
 
こわくない Git
こわくない Gitこわくない Git
こわくない Git
 
Wiresharkの解析プラグインを作る ssmjp 201409
Wiresharkの解析プラグインを作る ssmjp 201409Wiresharkの解析プラグインを作る ssmjp 201409
Wiresharkの解析プラグインを作る ssmjp 201409
 
ARM CPUにおけるSIMDを用いた高速計算入門
ARM CPUにおけるSIMDを用いた高速計算入門ARM CPUにおけるSIMDを用いた高速計算入門
ARM CPUにおけるSIMDを用いた高速計算入門
 
PythonとPyCoRAMでお手軽にFPGAシステムを開発してみよう
PythonとPyCoRAMでお手軽にFPGAシステムを開発してみようPythonとPyCoRAMでお手軽にFPGAシステムを開発してみよう
PythonとPyCoRAMでお手軽にFPGAシステムを開発してみよう
 
Redisの特徴と活用方法について
Redisの特徴と活用方法についてRedisの特徴と活用方法について
Redisの特徴と活用方法について
 
サーバPUSHざっくりまとめ
サーバPUSHざっくりまとめサーバPUSHざっくりまとめ
サーバPUSHざっくりまとめ
 
kubernetes初心者がKnative Lambda Runtime触ってみた(Kubernetes Novice Tokyo #13 発表資料)
kubernetes初心者がKnative Lambda Runtime触ってみた(Kubernetes Novice Tokyo #13 発表資料)kubernetes初心者がKnative Lambda Runtime触ってみた(Kubernetes Novice Tokyo #13 発表資料)
kubernetes初心者がKnative Lambda Runtime触ってみた(Kubernetes Novice Tokyo #13 発表資料)
 
About GStreamer 1.0 application development for beginners
About GStreamer 1.0 application development for beginnersAbout GStreamer 1.0 application development for beginners
About GStreamer 1.0 application development for beginners
 
FridaによるAndroidアプリの動的解析とフッキングの基礎
FridaによるAndroidアプリの動的解析とフッキングの基礎FridaによるAndroidアプリの動的解析とフッキングの基礎
FridaによるAndroidアプリの動的解析とフッキングの基礎
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?
 
GoらしいAPIを求める旅路 (Go Conference 2018 Spring)
GoらしいAPIを求める旅路 (Go Conference 2018 Spring)GoらしいAPIを求める旅路 (Go Conference 2018 Spring)
GoらしいAPIを求める旅路 (Go Conference 2018 Spring)
 
systemd 再入門
systemd 再入門systemd 再入門
systemd 再入門
 
Halide による画像処理プログラミング入門
Halide による画像処理プログラミング入門Halide による画像処理プログラミング入門
Halide による画像処理プログラミング入門
 

Andere mochten auch

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
 

Andere mochten auch (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編~
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 
正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?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
 

Mehr von 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を高速化する小手先テクニック -
 

Kürzlich hochgeladen

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
 
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
 
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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
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
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
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
 
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
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 

Kürzlich hochgeladen (20)

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...
 
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
 
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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
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
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
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
 
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
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 

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