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
320
Rubyと戯れるOSS DTM
5t111111
4
740
Rubyの拡張をCrystalで書いてみる
5t111111
0
100
Other Decks in Programming
See All in Programming
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
150
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
CSC509 Lecture 09
javiergs
PRO
0
140
CSC509 Lecture 12
javiergs
PRO
0
160
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
Macとオーディオ再生 2024/11/02
yusukeito
0
370
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
Arm移行タイムアタック
qnighy
0
340
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Bash Introduction
62gerente
608
210k
What's new in Ruby 2.0
geeforr
343
31k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
GitHub's CSS Performance
jonrohan
1030
460k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Raft: Consensus for Rubyists
vanstee
136
6.6k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
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Ͱ֬ೝ͍ͯ͠·͢ ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ