Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rubyはなぜ楽しいのか? 〜Cと比較してみよう〜
Search
sasabo
June 27, 2020
Programming
94
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rubyはなぜ楽しいのか? 〜Cと比較してみよう〜
Rubyが楽しいの感じる理由をCと比較して考えてみました。
sasabo
June 27, 2020
Other Decks in Programming
See All in Programming
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
35
17k
Railsバージョンを4倍にした話
optim
0
350
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
0
880
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.5k
ActionController meets Protocol Buffers
sorah
0
520
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
150
すこし踏み込む CancellationToken
htkym
2
1.7k
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
300
Workers Cache を知る
syumai
0
360
phperだってパンチカードでコーディングしたい
o0h
PRO
0
330
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
Featured
See All Featured
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
270
Large-scale JavaScript Application Architecture
addyosmani
516
110k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Discover your Explorer Soul
emna__ayadi
2
1.3k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
Skip the Path - Find Your Career Trail
mkilby
1
260
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Abbi's Birthday
coloredviolet
4
10k
Designing for Timeless Needs
cassininazir
1
530
Transcript
Rubyはなぜ楽しいのか? 〜Cと比較してみよう〜 笹原冬月 @sasabo 2020年06月27日 フィヨルドブートキャンプ オンラインLT会
自己紹介 • 笹原冬月(ささはらかずき)@sasabo • 今年34歳 • 2020年03月09日よりフィヨルドで学習開始 • 現在Vue.jsのプラクティスまで完了 •
大学4年生から大学院卒業までC言語を使ってニュー ラルネットと強化学習の研究 (※1)
事前にご理解いただきたいこと 発表の中でCとRubyを比較します。これは私がRubyを楽しいと思う理由を深 堀りするためであり、言語の優劣をつけるためではありません。 IDEやプラグインで解決する話もあるかもしれませんが、今回は使わない前 提で話します。
楽しい理由を分析 Rubyは楽しい 書き味が気持ち良い どんどんコードを 書いて実行できる コンパイルが不要 初見のコードでも理解しやすく学習 がはかどる なぜ? なぜ?
なぜ? なぜ? なぜ? 構文がシンプルで簡単にコードが書ける
Rubyの場合 初心者ならこう思う? putsが表示するためのコマンドみたいだ な (コードの出典※2) RubyとCの比較(Hello, Woldの場合) Cの場合 初心者ならこう思う? 赤枠の部分は表示するためのコマンド
みたいだけど、他は呪文みたい (コードの出典※3) #include <stdio.h> int main(void){ printf("Hello, World\n"); return 0; } puts “Hello, world”
Hello Worldからの気づいたRubyとCとの違い #include <stdio.h> // 1. printfを使うためのヘッダファイルが必要 int main(void){ //
2. main関数が必要(printfだけで実行できない) printf("Hello, World\n"); // 3. 行末にはセミコロンが必要 return 0; // 4. 正常終了したら0を返すように返り値が必要 } // 5. (Rubyならendで終わる) Rubyのputs “Hello world” に対してC言語は… C言語に対してRubyのほうがシンプルで簡単にプログラムが書けました。 構文がシンプルで簡単にコードが書ける。 => 自然言語のようにどんどん書ける。 => 楽しい
CとRubyの比較(Hello, Worldの場合) Cの場合 初心者ならこう思う? また呪文がでてきた… 実行まで hello_woldと3回も書いたけどなぜだろ う? 分からないことが多かった… Rubyの場合
初心者ならこう思う? hello_world.rbがファイル名なので、 ファイル名の前にrubyと書けば実行で きるのかな? なんとなく理解できた! 先程のHello Worldのコードを実行してみましょう! $ gcc hello_world.c -o hello_world $ ./hello_world Hello World $ ruby hello_world.rb Hello world
Hello Worldからの気づいたRubyとCとの違い $ gcc hello_world.c -o hello_world // 1.gccでコンパイルして実行ファイルを作成 $ ./hello_world
// 2.実行ファイルを実行 Rubyの$ ruby hello_world.rb に対してC言語は… C言語は自分でコードをコンパイルして実行したのに対し、Rubyは自分でコード をコンパイルせずにコードを実行できました。 コンパイルが不要 => コードを書いて実行のサイクルが短くなり、テンポよく進められる。 => 楽しい
RubyとCの比較(配列のループ map vs. for) Rubyの場合 =>mapメソッドで簡単に書ける Cの場合 => 型や配列の要素数を意識したり、事前に twice_numsを用意したり考えることが多い
nums = [1, 2, 3, 4, 5] twice_nums = nums.map { |num| num * 2 } 配列 nums[1, 2, 3, 4, 5] の各要素を2倍した配列 twice_nums[2, 4, 6, 8, 10] を作るとき int main() { int nums[5] = {1, 2, 3, 4, 5}; int twice_nums[5]; for(int i = 0; i < 5; i++){ twice_nums[i] = nums[i] * 2; } return 0; } 複雑なことを考えずに思った 通りに書ける =>どんどん書ける =>楽しい! どんどん書いていくには経験が必要 => 初心者のうちは難しい => 楽しく感じるまで時間が必要?
まとめ シンプルさを実現するRubyの特徴 • 使いたい関数が含まれるヘッダファイルの記述が不要 • main関数の明記は不要 • 行末にはセミコロンが不要 • 正常時の返り値の記載が不要
• コンパイル作業が不要 • 変数宣言が不要 • 配列の要素数の宣言が不要 • mapのような便利メソッドがある Rubyを楽しいと思う理由:どんどんコードを書いて実行できるからです。 => Rubyはコンパイル作業が不要 => 構文がシンプルで簡単にコードが書ける
参考資料 ※1 学生時代の研究:ニューラルネットと強化学習を組み合わせた画像入力コミュニケーション http://shws.cc.oita-u.ac.jp/~shibata/pub/SSI12.pdf https://www.youtube.com/watch?v=8eToHd6MhF8&feature=emb_logo ※2 RubyのHello worldのコードと実行結果 http://programming-tips.info/hello_world/ruby/index.htm ※3
CのHello worldのコードと実行結果 http://programming-tips.info/hello_world/c/index.html ※4 Rubyドキュメント C・C++からRubyへ https://www.ruby-lang.org/ja/documentation/ruby-from-other-languages/to-ruby-from-c-and-cpp/
ご清聴ありがとうございました