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
410
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
580
UFO演算子について
5t111111
0
310
Rubyと戯れるOSS DTM
5t111111
4
740
Rubyの拡張をCrystalで書いてみる
5t111111
0
100
Other Decks in Programming
See All in Programming
最新TCAキャッチアップ
0si43
0
140
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
CSC509 Lecture 09
javiergs
PRO
0
140
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
Better Code Design in PHP
afilina
PRO
0
120
cmp.Or に感動した
otakakot
2
140
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
200
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Jakarta EE meets AI
ivargrimstad
0
530
Arm移行タイムアタック
qnighy
0
320
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
222
8.9k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
We Have a Design System, Now What?
morganepeng
50
7.2k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
YesSQL, Process and Tooling at Scale
rocio
169
14k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Automating Front-end Workflow
addyosmani
1366
200k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
It's Worth the Effort
3n
183
27k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
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Ͱ֬ೝ͍ͯ͠·͢ ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ