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
130
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
930
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
42 best practices for Symfony, a decade later
tucksaun
1
180
Zoneless Testing
rainerhahnekamp
0
120
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
CSC305 Lecture 26
javiergs
PRO
0
140
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
130
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Visualization
eitanlees
146
15k
KATA
mclloyd
29
14k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Speed Design
sergeychernyshev
25
670
Side Projects
sachag
452
42k
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Ͱ֬ೝ͍ͯ͠·͢ ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ