intro to crystal programming language

44
Adler Hsieh 2016/12/02 Fast as C, Slick as Ruby

Upload: adler-hsieh

Post on 16-Apr-2017

310 views

Category:

Software


8 download

TRANSCRIPT

Page 1: Intro to Crystal Programming Language

AdlerHsieh2016/12/02

FastasC,SlickasRuby

Page 2: Intro to Crystal Programming Language

About

•  AdlerHsieh•  So=wareEngineer•  ContributorofCrystalLanguage

Blog:moGon-express.comadlerhsieh

Page 3: Intro to Crystal Programming Language

Whatisthislanguage?

Page 4: Intro to Crystal Programming Language
Page 5: Intro to Crystal Programming Language

What’sthedifference?

Page 6: Intro to Crystal Programming Language

Features

•  Rubysyntax•  CompiledwithLLVM•  StaGsGcallytype-checked•  Cbindings•  Macrosystem

Page 7: Intro to Crystal Programming Language

Features

•  Rubysyntax•  CompiledwithLLVM•  StaGsGcallytype-checked•  Cbindings•  Macrosystem

• Unixsystemonly

Page 8: Intro to Crystal Programming Language

Whydoweneedanewprogramminglanguage?

Page 9: Intro to Crystal Programming Language
Page 10: Intro to Crystal Programming Language

Crystal

•  WeloveRuby'sefficiencyforwriGngcode.•  WeloveC'sefficiencyforrunningcode.•  Wedon'twanttowriteCcodetomakethecoderunfaster.

Page 11: Intro to Crystal Programming Language
Page 12: Intro to Crystal Programming Language

calculator.rb

Page 13: Intro to Crystal Programming Language
Page 14: Intro to Crystal Programming Language
Page 15: Intro to Crystal Programming Language

Performance?

Page 16: Intro to Crystal Programming Language
Page 17: Intro to Crystal Programming Language
Page 18: Intro to Crystal Programming Language

Compile!

Page 19: Intro to Crystal Programming Language
Page 20: Intro to Crystal Programming Language
Page 21: Intro to Crystal Programming Language

28Gmesfaster!

Page 22: Intro to Crystal Programming Language

Somelibraries…

Page 23: Intro to Crystal Programming Language

Kemal

source

Page 24: Intro to Crystal Programming Language

Macros

Page 25: Intro to Crystal Programming Language

InRuby…

Page 26: Intro to Crystal Programming Language

InRuby…

"foo".send(:upcase)# => "FOO"

Page 27: Intro to Crystal Programming Language

InRuby…

"foo".send(:upcase)# => "FOO"

code = "a = 10 ; a += 10"eval(code)# => 20

Page 28: Intro to Crystal Programming Language

InCrystal…

"foo".send(:upcase)# => "FOO"

code = "a = 10 ; a += 10"eval(code)# => 20

Page 29: Intro to Crystal Programming Language

Macros

“MacrosaremethodsthatreceiveASTnodesatcompile-Gmeandproducecodethatispastedintoaprogram”

Page 30: Intro to Crystal Programming Language

Macros

“MacrosaremethodsthatreceiveASTnodesatcompile-Gmeandproducecodethatispastedintoaprogram”

1.  Runmacros2.  Runcode

Page 31: Intro to Crystal Programming Language

QuickExample

foo = 20

macro plus(number) foo += {{number}}end plus(20)puts foo

Page 32: Intro to Crystal Programming Language

QuickExample

foo = 20

macro plus(number) foo += {{number}}end plus(20)puts foo

1.Runmacros

Page 33: Intro to Crystal Programming Language

QuickExample

foo = 20

macro plus(number) foo += {{number}}end plus(20) foo += 20puts foo

1.Runmacros

Page 34: Intro to Crystal Programming Language

QuickExample

foo = 20

macro plus(number) foo += {{number}}end plus(20) foo += 20puts foo

2.Runcode

Page 35: Intro to Crystal Programming Language

QuickExample

foo = 20

macro plus(number) foo += {{number}}end plus(20) foo += 20puts foo # => 40

2.Runcode

Page 36: Intro to Crystal Programming Language

Andalotofsyntaxsugar!!!

Page 37: Intro to Crystal Programming Language

QuickExample class Foo getter :bar # => attr_reader setter :baz # => attr_writer property :qux # => attr_accessor

def initialize(@bar : Int32) @bar += 10 endend

foo = Foo.new(20)foo.bar # => 30

Page 38: Intro to Crystal Programming Language

CBinding!

Page 39: Intro to Crystal Programming Language

QuickExample

@[Link("pcre")]lib LibPCRE # …end

Page 40: Intro to Crystal Programming Language

Jointhecommunity!!!

Page 41: Intro to Crystal Programming Language

CurrentStatus

•  Startin2012•  v0.20.0•  SGllneedmaturelibraries

Page 42: Intro to Crystal Programming Language

TheOfficialWebsite

Page 43: Intro to Crystal Programming Language

Thelibraries

Page 44: Intro to Crystal Programming Language

ThankYou!

Blog:moGon-express.comGitHub:adlerhsiehTwider:@adler_hsieh