Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
静的型付け言語 Crystal
Search
Hirofumi Wakasugi
October 23, 2015
Programming
0
110
静的型付け言語 Crystal
Tokyo Crystal Meetup #2 (2015-10-23)
Hirofumi Wakasugi
October 23, 2015
Tweet
Share
More Decks by Hirofumi Wakasugi
See All by Hirofumi Wakasugi
Racc Introduction
5t111111
1
420
Keep Calm and Enjoy Gachima
5t111111
3
350
Swift Functional Programming
5t111111
0
260
Middleman on Production
5t111111
0
160
名古屋Ruby会議03 高速一言感想
5t111111
3
1k
ドキュメント翻訳懺悔のLT ~進捗ダメです~
5t111111
1
590
UFO演算子について
5t111111
0
320
Rubyと戯れるOSS DTM
5t111111
4
740
Rubyの拡張をCrystalで書いてみる
5t111111
0
110
Other Decks in Programming
See All in Programming
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
140
testcontainers のススメ
sgash708
1
120
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
390
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
940
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
260
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
3
300
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.3k
Haze - Real time background blurring
chrisbanes
1
510
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
140
Exploring: Partial and Independent Composables
blackbracken
0
100
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
BBQ
matthewcrist
85
9.4k
For a Future-Friendly Web
brad_frost
175
9.4k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
How STYLIGHT went responsive
nonsquared
95
5.2k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Optimising Largest Contentful Paint
csswizardry
33
3k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
A Modern Web Designer's Workflow
chriscoyier
693
190k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Transcript
੩తܕ͚ݴޠ$SZTUBM Crystal The Programming Language with Static Typing Hirofumi Wakasugi
(@5t111111)
$SZTUBM੩తܕ͚ͷ ϓϩάϥϛϯάݴޠͰ͢ɻ
੩తܕ͚ w มͳͲͷܕίϯύΠϧ࣌ʹܾఆ͞Ε͍ͯΔ w ܕνΣοΫʹΑͬͯࣄલʹόάΛัଊ͍͢͠ w มͳͲͷܕ࣮ࡍͷ࣮ߦ࣌ͷʹͳΔ w ॊೈͰ࠶ར༻ੑͷߴ͍ϓϩάϥϜΛॻ͖͍͢ ಈతܕ͚
ಈతܕ͚ͷ3VCZͱ ੩తܕ͚ͷ$SZTUBM Ͳ͕ͬͪ༏ΕͯΔ͔ͱ͔ ͦ͏͍͏͠·ͤΜʂ
$SZTUBM͕ ੩తܕ͚ݴޠͱͯ͠ ͲͷΑ͏ʹಇ͔͘ ୶ʑͱݟ͍͖ͯ·͢ɻ
มͷఆٛ a = 3 b = "we are like crystal,
we break easy" c = [1, 2, 3] w มBͷܕ*OU w มCͷܕ4USJOH w มDͷܕ"SSBZ *OU มॳΊ͕ͯೖ͞Εͨͱ͖ʹએݴ͞ΕΔ
มͷఆٛ w มBͷܕ*OU w มCͷܕ4USJOH w มDͷܕ"SSBZ *OU มॳΊ͕ͯೖ͞Εͨͱ͖ʹએݴ͞ΕΔ a
= 3 b = "we are like crystal, we break easy" c = [1, 2, 3] ܕਪ 5ZQF*OGFSFODF
มͷ࠶ೖ ͜ΕͲ͏ͳΔʁ Τϥʔʹͳͬͯ͠·͏ͷʁ ͢Ͱʹએݴ͞Εͯܕ͕ܾ·͍ͬͯΔมʹೖ͢Δ a = "we are like crystal,
it is not easy" a = 100
มͷ࠶ೖ ผͷܕΛมʹೖͯ͠ΤϥʔʹͳΒͳ͍ มͷܕೖ͞ΕΔࣜ ʹΑͬͯܕਪ͞ΕΔ ͢Ͱʹએݴ͞Εͯܕ͕ܾ·͍ͬͯΔมʹೖ͢Δ a = "we are
like crystal, it is not easy" # ここで変数 a は String a = 100 # ここで変数 a は Int32
"SSBZͷܕ ͜ΕͲ͏ͳΔʁ ͍͚ͦ͏͡Όͳ͍ʁ *OUͷ"SSBZʹ4USJOHܕͷཁૉΛՃ͢Δ a = [1, 2, 3] a
<< "we are like crystal"
"SSBZͷܕ *OUͷ"SSBZʹ4USJOHܕͷཁૉΛՃ͢Δ a = [1, 2, 3] a << "we
are like crystal" no overload matches 'Array(Int32)#<<' with types String Overloads are: - Array(Int32)#<<(value : Int32) a << "we are like crystal" ^~ ͜Ε ίϯύΠϧΤϥʔ &SSPS
ۭͷ"SSBZ ܕΛࢦఆͤͣʹۭͷ"SSBZΛએݴ͢Δ͜ͱͰ͖ͳ͍ a = [] # Syntax Error a =
[] of Int32 # OK! ͱ͍͏͜ͱɺ ҟͳΔܕͷཁૉΛؚΉ"SSBZ ࡞Εͳ͍ʁ
6OJPOܕ "SSBZ(FOFSJDܕͰ͋Γɺ 6OJPOܕΛؚΉ ཁૉ ͷܕΛࢦఆͰ͖Δ )BTIͳͲɺଞͷίϯςφ ίϨΫγϣϯ ܕಉ༷ ܕͷΈ߹ΘͤΛදݱ͢Δ6OJPOܕ a
= [1, 2, 3, "we are like crystal"] #=> Array(String | Int32) a = [] of String | Int32 #=> Array(String | Int32)
(FOFSJDܕ ޙͰઆ໌͠·͢͠·ͤΜ
ϝιουݺͼग़͠ ͜ΕͲ͏ͳΔʁ Τϥʔʹͳͬͯ͠·͏ͷʁ ͋Δܕ Ϋϥε ʹଘࡏ͠ͳ͍ϝιουΛݺͼग़ͨ͠߹ a = 3 a.size
ϝιουݺͼग़͠ ͋Δܕ Ϋϥε ʹଘࡏ͠ͳ͍ϝιουΛݺͼग़ͨ͠߹ a = 3 a.size undefined method
'size' for Int32 a.size ^~~~ ͜Ε ίϯύΠϧΤϥʔ &SSPS
ϝιουҾ def put_size(x) puts x.size end put_size("crystal") put_size(5) undefined method
'size' for Int32 puts x.size ^~~~ &SSPS ҾͰ͞ΕͨΦϒδΣΫτʹϝιου͕ͳ͍
ܕ੍ def put_size(x : String) puts x.size end put_size(5) no
overload matches 'put_size' with types Int32 Overloads are: - put_size(x : String) put_size(5) ^~~~~~~~ &SSPS ҾʹܕΞϊςʔγϣϯΛࢦఆ͠ܕΛ੍͢Δ
ܕ੍͕͋Δͱ҆৺ͩͶʂ ҾͲΜͲΜܕ੍͠Α͏ʂ
3FϝιουҾ def put_size(x) puts x.size end put_size("crystal") put_size([1, 2, 3])
ҾͰ͞ΕͨΦϒδΣΫτʹϝιου͕͋Δ ͑ͬʁ
3FϝιουҾ def put_size(x) puts x.size end put_size("crystal") put_size([1, 2, 3])
ҾͰ͞ΕͨΦϒδΣΫτʹϝιου͕͋Δ 7 3 3FTVMU Τϥʔͳ͘ਖ਼ৗऴྃ͢Δ
3FϝιουҾ def put_size(x) puts x.size end put_size("crystal") put_size([1, 2, 3])
ҾͰ͞ΕͨΦϒδΣΫτʹϝιου͕͋Δ 7 3 3FTVMU Τϥʔͳ͘ਖ਼ৗऴྃ͢Δ ໌֬ʹܕ੍͕͞Ε͍ͯ ͳ͚Εɺ͋Δܕ͕ݺͼ ग़͞ΕΔϝιουʹԠ ͢Δͱ͖ɺίϯύΠϥͷ ܕνΣοΫ௨Δɻ
μοΫλΠϐϯάతͳܕγεςϜ ܕͦͷͷͦͷܧঝؔʹґଘ͠ͳ͍ɺ ॊೈੑΛ࣋ͬͨ੩తܕ͚ʹͳ͍ͬͯΔ γάωΠνϟ͕ಛʹॏཁͰ͋Δͱ͍͏Ͱɺ 4USVDUVSBM4VCUZQJOH ߏత෦ܕ͚ ͱݴͬͯΑ͍͔
3F3FϝιουҾ def put_size(x) puts x.size end put_size("crystal") put_size(5) undefined method
'size' for Int32 puts x.size ^~~~ &SSPS ܕ੍Λ͠ͳͯ͘ίϯύΠϧ࣌ʹΤϥʔ͕ัଊ͞ΕΔ ෆඞཁͳܕ੍ ॊೈੑΛܽ͘
Πϯελϯεม Πϯελϯεมೖ͞ΕΔ͔Βܕਪ͞ΕΔ class Person getter name def initialize(@name) end end
barney = Person.new "Barney" barney.name #=> "Barney" barney.name.size #=> 6
barney = Person.new "Barney" barney.name.size one = Person.new 1 3FΠϯελϯεม
ΠϯελϯεมʹҟͳΔܕΛ༩͑ͯॳظԽ ͳΜ͔͓͔͍͠ͱ͋͜Δʁ
barney = Person.new "Barney" barney.name.size one = Person.new 1 3FΠϯελϯεม
ΠϯελϯεมʹҟͳΔܕΛ༩͑ͯॳظԽ undefined method 'size' for Int32 (compile-time type is (String | Int32)) barney.name.size #=> 4 ^~~~ ͜Ε ίϯύΠϧΤϥʔ &SSPS
JGWBSJT@B ʜ JT@B ͰܕΛνΣοΫ੍͠ݶ͢Δ if a.is_a?(String) # ここでは a が
# String で「ある」ことが保証される else # ここでは a が # String では「ない」ことが保証される end ίϯύΠϧ࣌ϦϑϨΫγϣϯʹΑΔܕͷอূ
JGWBSSFTQPOET@UP ʜ SFTQPOET@UP ͰԠΛνΣοΫ੍͠ݶ͢Δ if a.responds_to?(:size) # ここでは a が
# size に応答「する」ことが保証される else # ここでは a が # size に応答「しない」ことが保証される end ίϯύΠϧ࣌ϦϑϨΫγϣϯʹΑΔϝιουԠͷอূ
3F3FΠϯελϯεม JT@B SFTQPOET@UP Ͱ੍ݶ͢Δ if (name = barney.name).is_a?(String) name.size #=>
4 end if (name = barney.name).responds_to?(:size) name.size #=> 4 end Πϯελϯεมͷ߹ɺ্هͷΑ͏ʹҰมʹೖ͢Δඞཁ͕͋Δ
BT BTͰܕΛ੍ݶ͢Δ͜ͱͰ͖Δ name = barney.name as String name.size #=> 4
w BT࣮ߦ࣌ʹνΣοΫΛߦ͏ w ର͕4USJOHͰͳ͔ͬͨ߹ʹྫ֎͕ൃੜ w BTΩϟετͰͳ͍ ผͷܕͷม͠ͳ͍
OJMBCMF ͋Δܕ͕/JMܕΛ࣋ͭՄೳੑ a = [] of String? a.class #=> Array(String?)
a << "crystal" #=> ["crystal"] a << nil #=> ["crystal", nil] w 4USJOH ܕ͕/JMܕΛ࣋ͭ͜ͱΛҙຯ͢Δ w 4USJOHc/JM ͱ͍͏6OJPOܕͱಉ༷
OJMBCMFΠϯελϯεม JOJUJBMJ[FͰॳظԽ͞Εͳ͍Πϯελϯεม class Person getter name property address def initialize(@name)
end end barney = Person.new "Barney" barney.address = "Manchester" barney.address.size
OJMBCMFΠϯελϯεม JOJUJBMJ[FͰॳظԽ͞Εͳ͍Πϯελϯεม barney = Person.new "Barney" barney.address = "Manchester" barney.address.size
undefined method 'size' for Nil (compile-time type is String?) barney.address.size ^~~~ &SSPS ͜Ε ίϯύΠϧΤϥʔ JOJUJBMJ[FͰॳظԽ͞Εͳ͍Πϯελϯεม/JMܕΛ࣋ͭ
3FOJMBCMFΠϯελϯεม ΠϯελϯεมΛJOJUJBMJ[Fͷ֎ଆͰॳظԽ͢Δ class Person getter name property address @address =
"nowhere" def initialize(@name) end end barney = Person.new "Barney" barney.address = "Manchester" barney.address.size #=> 10
Πϯελϯεมͷܕࢦఆ ΠϯελϯεมΛܕΞϊςʔγϣϯͰࢦఆ͢Δ class Person … @address :: String … end
w !BEESFTTʹ4USJOHҎ֎ͷܕΛೖ͢ΔͱΤϥʔ w ܕͷσϑΥϧτଘࡏ͠ͳ͍ͷͰॳظԽඞཁ
·ͱΊ w $SZTUBM㱠3VCZ w தͰ੩తܕ͚ʹΑΔҧ͍ඇৗʹେ͖͍ ͦΕͰɺ We love Ruby's efficiency
for writing code. ͱ͍͏ͷ͕$SZTUBMͷग़ൃͷͭͰ͋ΔΑ͏ʹɺ 3VCZͷॊೈੑੜ࢈ੑɺؾ͍͍࣋ͪॻ͖ຯΛҡ࣋ͯ͠ ੩తܕ͚ʹ͠Α͏ͱ͢Δ͕ਵॴʹݟΒΕΔɻ
ͤͳ͔ͬͨͨͪ w (FOFSJDܕ (FOFSJDT w ྫ֎ॲཧͰͷܕਪͷಇ͖ w ΫϩʔδϟͰͷมͷܕ w
ϚΫϩʹ͓͚ΔܕใͷΞΫηε w UZQFPGɺ0CKFDUUSZͳͲͷϝιου w FUDFUD
IUUQKBDSZTUBMMBOHPSHEPDT ࠓͤͳ͔ͬͨ༰υΩϡϝϯτʹهࡌ͕͋Γ·͢
υΩϡϝϯτΛ͍ͭVQUPEBUFʹ͢ΔͨΊʹ ༁Λखͬͯ͘ΕΔํΛืू͍ͯ͠·͢ (JU)VC IUUQTHJUIVCDPNDSZTUBMKQKBDSZTUBMMBOHPSH (JUUFS IUUQTHJUUFSJNDSZTUBMKQKBDSZTUBMMBOHPSH ͘͠@5t111111·Ͱ͓Β͍ͤͩ͘͞ʂ 4MBDL IUUQDSZTUBMQJOFNPF
ຊεϥΠυதͷαϯϓϧίʔυ ͓Αͼͦͷग़ྗ༰ ͯ͢$SZTUBMͰ֬ೝ͍ͯ͠·͢ ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ