Share
Embed
Rubyから世界へ / Let’s start a journey around the world beyond Ruby
Rubyを第1言語(最初に学んだプログラミング言語)としてRubyを学んだ人向けのプログラミング言語の紹介です。
Yuya Kato
April 02, 2019
Transcript
35 slides
-
Ruby͔Βੈք 2019/04/02 Kobe.rb #100 -LT Party- @120 WORKPLACE KOBE Nayutaya
Inc. / Yuya Kato !1 Let's start a journey around the world beyond Ruby -
ࣗݾհ: Ճ౻ ༐ • ιϑτΣΞΤϯδχΞʢ2000ʙʣ • גࣜձࣾಹ༝ଟ දऔకʢ2007ʙʣ ͳ Ώ
ͨ • झຯ: • ͷͮ͘Γશൠ • 3DϓϦϯλʢ2013ʙʣ • ϘϧμϦϯάʢ2011ʙʣ !2 yuyakato1984 nayutaya About me: Yuya Kato I work as a software engineer since 2000. I'm running my own company, Nayutaya Inc., as the CEO since 2007. My hobbies are: Creating software, hardware and so on. Designing something using 3D printer. Doing bouldering. -
ͪͳΈʹ ͕ॳΊͯࢀՃͨ͠ ਆށ.rbୈ6ճ ʢ201410݄30։࠵ʣ Ͱͨ͠ https://koberb.doorkeeper.jp/events/15791 !4 Incidentally, my first
participation in Kobe.rb was the 6th meetup held on Oct. 30 2014. -
࣍ • ͜ͷLTͷλʔήοτ • ͜ͷLTͷΰʔϧ • ͦͦʮݴޠʯͱʁ • ϓϩάϥϛϯάݴޠΛ༷ʑͳΓޱͰ !5
Table of contents The targets of this LT The goals of this LT What is "language?" Let's look at various programming languages from various aspects -
͜ͷLTͷλʔήοτ • ୈ1ݴޠʢॳΊͯ৮ͬͨϓϩάϥϛϯάݴޠʣͱͯ͠RubyΛֶΜͩਓ • ϓϩάϥϛϯάͷੈքΛΑΓ͍͛ͨਓ !6 The targets of this
LT are: People who hopes to spread his/her world about programming People who learned Ruby as his/her first programming language -
͜ͷLTͷΰʔϧ • ϓϩάϥϛϯάͷੈքͷ͞Λײͯ͡Β͏͜ͱ • ʮଞͷϓϩάϥϛϯάݴޠֶΜͰΈ͍ͨʂʯͱײͯ͡Β͏͜ͱ !7 The goals of this
LT are: To let you think that you want to learn other programming languages more To let you feel the extent of the programming world -
ݴޠͱ !9 ʮ͋Δଘࡏʯͱʮผͷଘࡏʯ͕ҙࢥͷૄ௨ΛਤΔͨΊʹ༻͍Δ จࣈΛத৺ͱͨ͠Ұఆͷܾ·Γʹैͬͨදݱ Languages are Representations according to rules
to communicate his/her thought between others, in most cases based on characters. -
͍Ζ͍Ζͳʮݴޠʯ !10 ࣗવݴޠ Japanese, English ਓݴޠ ࠃࡍิॿޠ Esperanto Sign lang.
ίϯϐϡʔλݴޠ σʔλهड़ݴޠ ϚʔΫΞοϓݴޠ HTML, Markdown ϋʔυΣΞهड़ݴޠ Verilog, VHDL ͍߹Θͤݴޠ SQL, GraphQL ϓϩάϥϛϯάݴޠ Ruby, C/C++ : ͜ͷޙͷεϥΠυͰʮݴ ޠʯʮϓϩάϥϛϯάݴޠʯ Λࣔ͠·͢ Variety of languages Natural lang. Artificial lang. International auxiliary lang. Query lang. Programming lang. Computer lang. Data description lang. Markup lang. HDL Note: "Lang." means programming lang. after this slide. -
ύϥμΠϜʹΑΔྨ !12 Paradigms ໋ྩܕݴޠʢखଓ͖ܕݴޠʣ Ruby એݴܕݴޠ ؔܕݴޠ Haskell ཧܕݴޠ Prolog
C/C++ LISP Idris Scala ७ਮ ඇ७ਮ Java ͦͷଞɺଟ͘ͷݴޠ Imperative (Procedural) Declarative Functional Purely Not purely Logic Python And many other languages -
நʹΑΔྨ !13 நʢϨϕϧʣ ߴநʢߴϨϕϧʣ Machine code Assembly lang. C/C++ Ruby
:ʮϨϕϧʯݴޠͷ༏ྼΛࣔ͢ͷͰ͋Γ·ͤΜ Java Rust Haskell Abstraction level Low degree of abstraction High degree of abstraction Note: "Level" doesn't express superiority or inferiority of lang. -
ܕ͚ʹΑΔྨ !14 ڧ͍ܕ͚ ऑ͍ܕ͚ ಈతͳܕ͚ ੩తͳย͚ Ruby C/C++ Java Haskell
Python JavaScript Data typing Dynamic Static Weak Strong Machine code -
ςΩετ/ϏδϡΞϧ !15 ςΩετݴޠ ϏδϡΞϧݴޠ Scratch Ruby ͦͷଞɺ΄ͱΜͲͷݴޠ Haskell C/C++ Java
LabVIEW Simulink Text or Visual And most other languages Text programming lang. Visual programming lang. -
Πϯσϯτʹҙຯ͕͋Δ/ͳ͍ !17 Πϯσϯτʹҙຯ͕ͳ͍ݴޠ Πϯσϯτʹҙຯ͕͋Δݴޠ Python Haskell Ruby C/C++ Java Indentation
of code has meaning, or not ͦͷଞɺଟ͘ͷݴޠ And many other languages Indentation has meaning Indentation hasn't meaning -
۩ମྫ: Πϯσϯτ !18 Ruby Python Haskell def hello 3.times {
puts("Hello") } end def hello 3.times { puts("Hello") } end def hello(): for _ in range(3): print("hello") def hello(): for _ in range(3): print(“hello”) --- IndentationError: expected an indented block main = let hello 0 = [] hello n = "hello\n" ++ hello(n - 1) in do putStrLn $ hello(3) main = let hello 0 = [] hello n = "hello\n" ++ hello(n - 1) in do putStrLn $ hello(3) --- parse error (possibly incorrect indentation or mismatched brackets) ΠϯσϯτΛফ͢ͱ Example: indentation Remove indentation -
1࣍ݩ/2࣍ݩ !19 1࣍ݩͳݴޠ 2࣍ݩͳݴޠ Befunge Ruby Haskell C/C++ Java 1
or 2 dimensional ͦͷଞɺ΄ͱΜͲͷݴޠ And most other languages 1 dimensional 2 dimensional -
۩ମྫ: Befunge !20 v @_ v >0"!dlroW"v v :# <
>" ,olleH" v ^ < Hello, World! Example: Befunge Source code: Output: -
ؙׅހΛଟ༻͢Δ/͠ͳ͍ !21 ؙׅހΛదʹ༻͢Δݴޠ ؙׅހΛଟ༻͢Δݴޠ LISP Ruby ͦͷଞɺ΄ͱΜͲͷݴޠ Haskell C/C++ Java
Using parentheses a lot, or not And most other languages Using parentheses a lot Using parentheses moderately -
۩ମྫ: LISP !22 (dotimes (n 3) (format t "hello~%")) hello
hello hello (dotimes (i 100) (cond ((and (= (mod (1+ i) 3) 0) (= (mod (1+ i) 5) 0)) (format t "Fizz,Buzz~%")) ((= (mod (1+ i) 3) 0) (format t "Fizz~%")) ((= (mod (1+ i) 5) 0) (format t "Buzz~%")) (t (format t "~A~%" (1+ i))))) 1 2 Fizz 4 Buzz Fizz 7 8 ... Example: LISP Source code: Output: -
ݟ͑Δ/ݟ͑ͳ͍ !23 ݟ͑ΔʢҹͰ͖Δʣݴޠ ݟ͑ͳ͍ʢҹͰ͖ͳ͍ʣݴޠ Whitespace Ruby Haskell C/C++ Java Visible,
or not Visible (printable) Invisible (not printable) ͦͷଞɺ΄ͱΜͲͷݴޠ And most other languages -
۩ମྫ: Whitespace !24 SSSTSSTSSSNTNSSSSSTTSSTST NTNSSSSSTTSTTSSNTNSSSSSTT STTSSNTNSSSSSTTSTTTTNTNSS SSSTSTTSSNTNSSSSSTSSSSSNT NSSSSSTTTSTTTNTNSSSSSTTST TTTNTNSSSSSTTTSSTSNTNSSSS STTSTTSSNTNSSSSSTTSSTSSNT
NSSSSSTSSSSTNTNSSSSSTSTSN TNSSNNNN Hello, World! Source code: Output: Source code: Space -> S Tab -> T New Line -> N Example: Whitespace -
ΦϒδΣΫτࢦͰ͋Δ/Ͱͳ͍ !25 ΦϒδΣΫτࢦͳݴޠ ඇΦϒδΣΫτࢦͳݴޠ C-lang C++ LISP JavaScript Ruby Haskell
Object-oriented, or not Object-oriented Non-object-oriented -
Ϋϥεϕʔε/ϓϩτλΠϓϕʔε !26 ΫϥεϕʔεΦϒδΣΫτࢦ ϓϩτλΠϓϕʔεΦϒδΣΫτࢦ JavaScript Ruby C++ Smalltalk Self Lua
Io Class-based object-oriented, or prototype-based one Class-based object-oriented Prototype-based object-oriented -
ίϯύΠϧͷ༗ແ !27 ίϯύΠϧ͕ඞཁͳݴޠ ίϯύΠϧ͕ෆཁͳݴޠ C/C++ Java Haskell Ruby JavaScript :
࣮ࡍʹॲཧܥґଘ Need compilation, or not Python Need compilation Not need compilation Note: Actually, it depends on a system of implementation -
σʔλͷॴ༗ݖͷ༗ແ !28 ॴ༗ݖ͕͋Δݴޠ ॴ༗ݖ͕ͳ͍ݴޠ Rust Ruby Haskell C/C++ Java Incorporate
data with ownership, or not ͦͷଞɺ΄ͱΜͲͷݴޠ And most other languages Has ownership system Hasn't ownership system -
۩ମྫ: ॴ༗ݖ !29 Ruby def hello(name) printf("hello, %s!\n", name) end
name = "NAME" hello(name) hello(name) Rust fn main() { fn hello(name: String) { println!("hello, {}!", name); } let name = String::from("NAME"); hello(name); hello(name); } error[E0382]: use of moved value: `name` --> src/main.rs:7:9 | 6 | hello(name); | ---- value moved here 7 | hello(name); | ^^^^ value used here after move | = note: move occurs because `name` has type `std::string::String`, which does not implement the `Copy` trait hello, NAME! hello, NAME! Source code: Output: Example: ownership -
νϡʔϦϯάશੑ͋Γ/ͳ͠ !30 νϡʔϦϯάશͳݴޠ ඇνϡʔϦϯάશͳݴޠ Regular expression HQ9+ ʮνϡʔϦϯάશʯͱʁ ສೳνϡʔϦϯάϚγϯͱಉ͡ܭࢉೳྗΛͭܭࢉϞσϧ ʮສೳνϡʔϦϯάϚγϯʯͱʁ
ཁ͢ΔʹԿͰܭࢉͰ͖Δػցʢೖग़ྗʹ͍ͭͯൣᙝ֎ʣ Ruby Haskell C/C++ Java Turing-completeness ͦͷଞɺ΄ͱΜͲͷݴޠ And most other languages Turing-complete Non-turing-complete What is turing-complete? What is universal turing machine? In short, a machine which can calculate anything. A calculation model which has ability of calculation as equal as universal turing machine. -
ϧʔϓจͷ༗ແ !31 ϧʔϓͷ͋Δݴޠ ϧʔϓͷͳ͍ݴޠ Ruby Haskell C/C++ Java Has loop
statement, or not Has loop statement Hasn't loop statement ͦͷଞɺ΄ͱΜͲͷݴޠ And most other languages -
มͷ࠶ೖͷՄ൱ !32 ࠶ೖͰ͖Δݴޠ ࠶ೖͰ͖ͳ͍ݴޠ Haskell Ruby C/C++ (non-const) Java (non-final)
Possible that we re-bind on variables, or not ͦͷଞɺ΄ͱΜͲͷݴޠ And most other languages Re-binding is possible Re-binding is not possible -
ଞʹ • ؆ͷॱং͕ҟͳΔݴޠ • ԆධՁ͕ඪ४ͳݴޠ • λϓϧͷ͋Δݴޠ • ͳͲͳͲ !33
Something else A language which has peculiar order of reducing A language which always use lazy evaluation A language which has tuple type And so on... -
࠷ޙʹ • ੈքʹ༷ʑͳಛΛ࣋ͭϓϩάϥϛϯάݴޠ͕͋Γ·͢ • ৭ʑͳϓϩάϥϛϯάݴޠΛֶΜͰੈքΛ͛·͠ΐ͏ʂ !34 Epilogue There are many
distinctive programming languages in the world Let's learn those languages, and spread your world!