golang and domain specific languages - fntlnz.wtf · background on dsls: terminology internal dsl :...

29
Golang and Domain Specific Languages Lorenzo Fontana March 24, 2017

Upload: vocong

Post on 30-Jul-2018

238 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Golang and Domain Specific Languages

Lorenzo Fontana

March 24, 2017

Page 2: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

About Me

Lorenzo Fontana

DevOps Expert @Kiratech

Docker Maintainer

http://fntlnz.wtf

https://github.com/fntlnz

https://twitter.com/fntlnz

1

Page 3: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs

Page 4: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 5: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 6: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 7: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 8: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 9: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 10: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 11: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 12: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 13: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 14: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more

2

Page 15: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more, really

2

Page 16: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Examples

• HTML

• SQL

• GraphQL

• Protobuf

• Regex

• Jenkinsfile

• Dockerfile

• Make

• CSS

• TeX

• And a lot more, really, trust me

2

Page 17: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Terminology

Internal DSL : a DSL which exposes a particular form of host general

purpose language to fit domain specific needs, for their

nature, this kind of DSLs are easier to implement but

limited by the design of the host language.

External DSL : a DSL which is parsed independently of the host

general purpose language.

3

Page 18: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: External or internal ?

Example from: Ginkgo, BDD testing framework for Go

I t ( ” shou ld f a i l i n a l l the p o s s i b l e ways” , func ( ) {s e s s i o n := s t a r tG i n k go ( pathToTest , ”−−noCo lo r ” )

E v e n t u a l l y ( s e s s i o n ) . Should ( gexec . E x i t ( 1 ) )

output := s t r i n g ( s e s s i o n . Out . Contents ( ) )

( output ) . ShouldNot (

Con t a i nSub s t r i n g ( ”NEVER SEE THIS” )

)

}

4

Page 19: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: External or internal?

Makefile

.PHONY: check−gopath

check−gopath :

i f n d e f GOPATH

$ ( e r r o r GOPATH i s not s e t )

e n d i f

l i n t : check−gopath@echo ” check i ng l i n t ”

@ . / . t o o l / l i n t

gofmt :

@. / hack/ v e r i f y −gofmt . sh

conmon :

$ (MAKE) −C $@

5

Page 20: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Lexical analyzers and parser generators

6

Page 21: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: Backus-Naur Form (BNF)

<expr> : := <term> ”+” <expr>

| <term>

<term> : := <f a c t o r> ”∗” <term>

| <f a c t o r>

<f a c t o r> : := ”(” <expr> ”)”

| <const>

<const> : := i n t e g e r

7

Page 22: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Background on DSLs: lex and yacc - flex and bison

8

Page 23: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

What about Go?

Page 24: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Go: goyacc

9

Page 25: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Go: SHOW US THE CODE!

Who am I to not put a gopher in my slides?

10

Page 26: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Conclusion

Page 27: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Conclusion: Happy promotion!

Kiratech, the company I work for, is hiring!

drop me a line at [email protected]

11

Page 28: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Questions?

11

Page 29: Golang and Domain Specific Languages - fntlnz.wtf · Background on DSLs: Terminology Internal DSL : a DSL which exposes a particular form of host general purpose language to t domain

Thanks for listening!

And thanks to all the organizers!

11