introduction of programming language
TRANSCRIPT
INTRODUCTION OFINTRODUCTION OFPROGRAMMINGPROGRAMMING
LANGUAGELANGUAGE@NASA9084@NASA9084
2015/08/012015/08/01
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
1 / 70 2015年10月17日 15:28
INTROINTRO
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
2 / 70 2015年10月17日 15:28
自己紹介自己紹介
名前
北村壮大(Masahiro Kitamura)HN:nasa9084
所属
北海道大学
工学部
情報エレクトロニクス学科
コンピュータサイエンスコース
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
3 / 70 2015年10月17日 15:28
今日の内容今日の内容
いろいろなプログラミング言語の紹介
名前の紹介
分類は適当
サンプルプログラムの紹介
HelloWorld実際に書いてみよう
FizzBuzz世界のナベアツ問題
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
4 / 70 2015年10月17日 15:28
メジャーな言語メジャーな言語
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
5 / 70 2015年10月17日 15:28
コンパイラ言語コンパイラ言語
C/C++JavaC#VisualBasicObjective-CDelphi/Pascal
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
6 / 70 2015年10月17日 15:28
LL (LIGHTWEIGHT LANGUAGE)LL (LIGHTWEIGHT LANGUAGE)JavaScriptPerlPHPPythonRuby
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
7 / 70 2015年10月17日 15:28
関数型言語関数型言語
HaskellLISPSchemeCommon Lisp
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
8 / 70 2015年10月17日 15:28
マイナーな言語マイナーな言語
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
9 / 70 2015年10月17日 15:28
マイナーな汎用言語マイナーな汎用言語
AWKTcl/TkHSP (Hot Soup Processor)ひまわり/なでしこ
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
10 / 70 2015年10月17日 15:28
特殊な言語特殊な言語
ActionScriptVim ScriptEmacs LispShell Scriptbatch FileTeX
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
11 / 70 2015年10月17日 15:28
変態な言語/ジョークな言語変態な言語/ジョークな言語Brainf**WhitespaceGrassHQ9+Pxem
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
12 / 70 2015年10月17日 15:28
C/C++C/C++
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
13 / 70 2015年10月17日 15:28
Cの特徴Cの特徴古くからある言語
多分、最も使ってる人や資料が多い言語
割と何でもできる言語
単純な命令で大きなものを組み上げる
他の言語は割と複雑な命令もある
速い
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
14 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLD#include <stdio.h>
int main(void){ printf("HelloWorld\n");return 0;
}
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
15 / 70 2015年10月17日 15:28
C++の特徴C++の特徴Cを拡張して作られたオブジェクト指向言語ほとんどCの上位互換なのでC言語+α的な使い方もできる
C(強力)の拡張なのでもちろん強力難しい
複雑怪奇
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
16 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLD#include <iostream>
int main(){ std::cout << "HelloWorld" << std::endl;}
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
17 / 70 2015年10月17日 15:28
JAVAJAVA
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
18 / 70 2015年10月17日 15:28
JAVAの特徴JAVAの特徴どのOSで書いても、どのOSでも実行できるランタイムが必要
Webでも使えるオブジェクト指向
ぬるぽ
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
19 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLDpublic class HelloWorld{public static void main(String[] arg){
System.out.println("HelloWorld"); }}
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
20 / 70 2015年10月17日 15:28
JAVASCRIPTJAVASCRIPT
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
21 / 70 2015年10月17日 15:28
JAVASCRIPTの特徴JAVASCRIPTの特徴Javaとは別物ブラウザ上で動作する
主としてHTMLと一緒に使う昔はそうでもなかった→ライブラリでWebを席巻
jQueryとかNode.jsとか
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
22 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLD<!DOCTYPE html><html><head><title>JavaScriptテスト</title><script type="text/javascript">document.write("HelloWorld");</script>
</head><body><p></p>
</body></html>
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
23 / 70 2015年10月17日 15:28
PERLPERL
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
24 / 70 2015年10月17日 15:28
PERLの特徴PERLの特徴スクリプト言語
コンパイルは不要
テキスト処理が得意
There's mere than one way to do it.文法の自由度が高い
難解
多用な正規表現
cgi代表
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
25 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLD#!perlprint "HelloWorld\n";
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
26 / 70 2015年10月17日 15:28
PHPPHP
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
27 / 70 2015年10月17日 15:28
PHPの特徴PHPの特徴HTMLに埋め込む文法は平易
データベースとかが得意
割と速い
Perlに取って代わろうとしている言語仕様は・・・
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
28 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLDclass Hello{public static function main($args = array()){printf("HelloWorld");
}}Hello::main() ;
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
29 / 70 2015年10月17日 15:28
PYTHON/RUBYPYTHON/RUBY
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
30 / 70 2015年10月17日 15:28
PYTHONの特徴PYTHONの特徴オブジェクト指向言語
There's only one way to do it.インデントでブロックを記述
自然とキレイに書ける
読みやすい
入門向け
GUIツールキットも充実意外と何でも出来る
動作速度は・・・
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
31 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLDprint "HelloWorld"
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
32 / 70 2015年10月17日 15:28
RUBYの特徴RUBYの特徴日本人が作った言語
日本語に強い
オブジェクト指向言語
Ruby on Railsで有名に初心者向け
Pythonとよく比較される多様性は善
GUIツールキットも充実意外と何でも出来る
Windowsでは・・・
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
33 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLDprint "HelloWorld\n"
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
34 / 70 2015年10月17日 15:28
SCHEMESCHEME
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
35 / 70 2015年10月17日 15:28
SCHEMEの特徴SCHEMEの特徴LISP系言語仕様が簡潔
関数型言語教育で多用
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
36 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLD(display "HelloWorld")(newline)
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
37 / 70 2015年10月17日 15:28
なでしこなでしこ
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
38 / 70 2015年10月17日 15:28
なでしこの特徴なでしこの特徴
ひまわりの進化形
日本語でプログラムを書く
簡単(そうに見える)
理解しやすい
教育分野で活躍
意外と強い子
CGIやらオブジェクト指向やらGUI部品やらDLLやらAPIやら
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
39 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLD「HelloWorld」と表示。
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
40 / 70 2015年10月17日 15:28
SHELL SCRIPTSHELL SCRIPT
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
41 / 70 2015年10月17日 15:28
SHELL SCRIPTの特徴SHELL SCRIPTの特徴MacやLinuxでコマンドを実行するためのスクリプト変数、条件分岐、ループ
最近はWindowsでも(?)
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
42 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLDecho "HelloWorld"
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
43 / 70 2015年10月17日 15:28
TEXTEX
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
44 / 70 2015年10月17日 15:28
TEXの特徴TEXの特徴「てふ」または「てっく」
組版用言語
数式を簡単に書ける
理系の論文などで多用
しかし実はチューリング完全(C言語と同じ表現力)闇
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
45 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLD\documentclass{jarticle}\begin{document}HelloWorld\end{document}
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
46 / 70 2015年10月17日 15:28
GRASSGRASS
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
47 / 70 2015年10月17日 15:28
GRASSの特徴GRASSの特徴ちょっと草植えときますね型言語
「w」「W」「v」だけしかし実はすごく考えられた言語仕様
才能の無駄遣い
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
48 / 70 2015年10月17日 15:28
HELLOWORLDHELLOWORLDwwvwwwWWWwwWwwWWWWwvwWWwwwWwwvwWwwwWwwvwWWwWWWWWwvwWWWwwwwWWWWwWWWWwWWWWWWwWWWWWWWwWWWWWWWwWWWWWWWWwWwwwwwwwwvwWWWwwwwwWWWWWwWWWWWwWWWWWWWwWWWWWWWWwWWWWWWWWWwWwwwwwwwvwWWWWwwwwwwWWWWWWwWWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWwWwwwwwwwvwWWWWWwwwwwwwWWWWWWWwWWWWWWWWwWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWwWwwwwwwwvwWWWWWWWwwwwwwwwWWWWWWWWwWWWWWWWWWwWWWWWWWWWwWWWWWWWWWWWwWwwwwwwvwWWWWWWWWwwwwwwwwwWWWWWWWWwWWWWWWWWWwWWWWWWWWWWWwWWWWWWWWWWWwWWWWWWWWWWWWWwWwwwwwwwvwWWWWWWWWwwwwwwwwwwWWWWWWWWWwWWWWWWWWWWwWWWWWWWWWWWwWWWWWWWWWWWWWwWwwwwwwvwWWWWWWWWWWwwwwwwwwwwwWWWWWWWWWWwWWWWWWWWWWWwWWWWWWWWWWWWWwWwwwwwvwWWWWWWWWWWwwwwwwwwwwwwWWWWWWWWWWWWwWWWWWWWWWWWWWwWWWWWWWWWWWWWWwWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWwWwwwwwwwvwWWWWWWWWWWwwwwwwwwwwwwwwwwwWwwwwwwwwwwwwwwwwwwwWWWwwwwwwwwwwwwwwwwwwwWwwWWWWWWWWWWWWWWWWWWWWwvwWWwwwwWWWwwwwwwwwwwWWWWwwwwwwwwwwWWWWWwwwwwwwwwwwwwWWWWWWwwwwwwwWWWWWWWwwwwwwwwwwwWWWWWWWWwwwwwwwwwwwwwwwwwwwwwwvwWWWWWWWWWWWWWWWWwwwwwwwWwwvwWWWWwwwwwwwWWWWWwwwWWWWWWwwwwwwwWWWWWWWwwwwwwwwWWWWWWWWwwwwwwwwwwwwwwWWWWWWWWWwwwwwwwwwwwwwwvwWWwWWWWWw
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
49 / 70 2015年10月17日 15:28
EXERCISEEXERCISE
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
50 / 70 2015年10月17日 15:28
FIZZBUZZ問題FIZZBUZZ問題ルールルール
1から順番に数字を出力3で割り切れるときは代わりにFizz5で割り切れるときは代わりにBuzz両方で割り切れるなら代わりにFizzBuzz
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
51 / 70 2015年10月17日 15:28
世界のナベアツ問題世界のナベアツ問題
ルールルール
1から順番に数字を出力3の倍数または3のつく数字であれば代わりにAho
1 2 Aho 4 5 Aho 7 8 Aho 10 11 Aho Aho 14 Aho 16 17 Aho 19 20 Aho 22 Aho Aho
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
52 / 70 2015年10月17日 15:28
SAMPLESAMPLEC言語でのサンプルコードを紹介
実際に皆さんにはPythonで書いてもらう
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
53 / 70 2015年10月17日 15:28
FIZZBUZZFIZZBUZZ
#include <stdio.h>
int main(void){int i, n=40;for(i=1; i<=n; i++){
if(i%15==0){ printf("FizzBuzz "); }else if(i%3==0){ printf("Fizz "); }else if(i%5==0){ printf("Buzz "); }else{ printf("%d ", i); } }}
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
54 / 70 2015年10月17日 15:28
世界のナベアツ問題世界のナベアツ問題
#include <stdio.h>
int main(void){int i, n=40;for(i=1; i<=n; i++){
if(i%3==0 || (30<i && i<40)){ printf("Aho "); }else{ printf("%d ", i); } }}
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
55 / 70 2015年10月17日 15:28
PYTHONで書いてみるPYTHONで書いてみる
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
56 / 70 2015年10月17日 15:28
四則演算四則演算
+で足し算
-で引き算
*で掛け算
/で割り算
%で割り算の余り
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
57 / 70 2015年10月17日 15:28
変数変数
変数は箱やラベルとして説明される
ある値に名前をつけて受け渡したり再利用したり
特定の数値の意味をわかりやすくするために名前をつけた
り
変数=値で代入
x = 1
1という値にラベルxをつけた
または、xという名前のついた箱に1という値を入れた
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
58 / 70 2015年10月17日 15:28
変数=変数という書き方もOK
x = 1y = x
xの値は1
yの値は代入時のxの値=1
xの値もyの値も1
このあと、xの値を変更してもyの値は変化なし
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
59 / 70 2015年10月17日 15:28
ループループ
繰り返しの処理
一般にはwhileとforwhileは条件に一致する間繰り返しforは特定のまとまりに対して繰り返し処理(pythonの場合)forは言語によって動作が違うことも多い処理のまとまり(ブロック)はインデント(字下げ)で表現今回はforを使うfor i in range(1,40):
print i
1以上40未満をカウントアップしながら繰り返しその時のカウンタの値は変数iに入れてね
変数iの値を表示してね
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
60 / 70 2015年10月17日 15:28
条件分岐条件分岐
条件によって実行したりしなかったり
ifという文を使う条件に一致したら実行
複数条件はelifで指定すべての条件に一致しなかった時はelseのところを実行elseは省略できる==(等号)や>,>=,<,<=(不等号)などが使える!(否定)も使える等号の否定は!=
if x==1:print u"xは1です"
else:print u"xは1ではありません"
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
61 / 70 2015年10月17日 15:28
表示表示
画面に表示するにはprintを使う後ろに書いたもの+改行が表示される,区切りで複数のものを表示できる
改行されたくない時は後ろに,をつける
print "HelloWorld"
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
62 / 70 2015年10月17日 15:28
実行実行
source.pyという名前で保存したら、コマンドライン(Terminal,端末)から
$ python source.py
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
63 / 70 2015年10月17日 15:28
LET'S DO IT!LET'S DO IT!
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
64 / 70 2015年10月17日 15:28
実際にやってみましょう!実際にやってみましょう!
FizzBuzz問題
3の倍数はFizz5の倍数はBuzz両方の倍数はFizzBuzz
世界のナベアツ問題
3の倍数はAho3がつく数字もAho
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
65 / 70 2015年10月17日 15:28
解答例解答例
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
66 / 70 2015年10月17日 15:28
FIZZBUZZ問題FIZZBUZZ問題for i in range(1,40):
if i%15==0:print "FizzBuzz ",
elif i%3==0:print "Fizz ",
elif i%5==0:print "Buzz ",
else:print i, " ",
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
67 / 70 2015年10月17日 15:28
世界のナベアツ問題世界のナベアツ問題
for i in range(1,40):if i%3==0 or (30<i and i<40):
print "Aho ",else:
print i, " ",
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
68 / 70 2015年10月17日 15:28
THANK YOU!THANK YOU!
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
69 / 70 2015年10月17日 15:28
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
70 / 70 2015年10月17日 15:28