INTRODUCTION OFINTRODUCTION OF
PROGRAMMINGPROGRAMMING
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++
Java
C#
VisualBasic
Objective-C
Delphi/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)
JavaScript
Perl
PHP
Python
Ruby
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
7 / 70 2015年10月17日 15:28
関数型言語関数型言語
Haskell
LISP
Scheme
Common 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
マイナーな汎用言語マイナーな汎用言語
AWK
Tcl/Tk
HSP (Hot Soup Processor)
ひまわり/なでしこ
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
10 / 70 2015年10月17日 15:28
特殊な言語特殊な言語
ActionScript
Vim Script
Emacs Lisp
Shell Script
batch File
TeX
Introduction of Programming Language file:///mnt/A2C043EDC043C66F/Users/owner/Dropbox/digi-poro/out...
11 / 70 2015年10月17日 15:28
変態な言語/ジョークな言語変態な言語/ジョークな言語
Brainf**
Whitespace
Grass
HQ9+
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("HelloWorldn");
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
HELLOWORLDHELLOWORLD
public 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
#!perl
print "HelloWorldn";
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
HELLOWORLDHELLOWORLD
class 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
HELLOWORLDHELLOWORLD
print "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
HELLOWORLDHELLOWORLD
print "HelloWorldn"
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
HELLOWORLDHELLOWORLD
echo "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
HELLOWORLDHELLOWORLD
wwvwwwWWWwwWwwWWWWwvwWWwwwWwwvwWwwwWwwvwWWwWWWWWwvwWWWwwwwWWWWwWWWWwWW
WWWWwWWWWWWWwWWWWWWWwWWWWWWWWwWwwwwwwwwvwWWWwwwwwWWWWWwWWWWWwWWWWWWWwW
WWWWWWWwWWWWWWWWWwWwwwwwwwvwWWWWwwwwwwWWWWWWwWWWWWWwWWWWWWWwWWWWWWWWWw
WWWWWWWWWwWwwwwwwwvwWWWWWwwwwwwwWWWWWWWwWWWWWWWWwWWWWWWWWwWWWWWWWWWWwW
WWWWWWWWWwWwwwwwwwvwWWWWWWWwwwwwwwwWWWWWWWWwWWWWWWWWWwWWWWWWWWWwWWWWWW
WWWWWwWwwwwwwvwWWWWWWWWwwwwwwwwwWWWWWWWWwWWWWWWWWWwWWWWWWWWWWWwWWWWWWW
WWWWwWWWWWWWWWWWWWwWwwwwwwwvwWWWWWWWWwwwwwwwwwwWWWWWWWWWwWWWWWWWWWWwWW
WWWWWWWWWwWWWWWWWWWWWWWwWwwwwwwvwWWWWWWWWWWwwwwwwwwwwwWWWWWWWWWWwWWWWW
WWWWWWwWWWWWWWWWWWWWwWwwwwwvwWWWWWWWWWWwwwwwwwwwwwwWWWWWWWWWWWWwWWWWWW
WWWWWWWwWWWWWWWWWWWWWWwWWWWWWWWWWWWWWwWWWWWWWWWWWWWWWWwWwwwwwwwvwWWWWW
WWWWWwwwwwwwwwwwwwwwwwWwwwwwwwwwwwwwwwwwwwWWWwwwwwwwwwwwwwwwwwwwWwwWWW
WWWWWWWWWWWWWWWWWwvwWWwwwwWWWwwwwwwwwwwWWWWwwwwwwwwwwWWWWWwwwwwwwwwwww
wWWWWWWwwwwwwwWWWWWWWwwwwwwwwwwwWWWWWWWWwwwwwwwwwwwwwwwwwwwwwwvwWWWWWW
WWWWWWWWWWwwwwwwwWwwvwWWWWwwwwwwwWWWWWwwwWWWWWWwwwwwwwWWWWWWWwwwwwwwwW
WWWWWWWwwwwwwwwwwwwwwWWWWWWWWWwwwwwwwwwwwwwwvwWWwWWWWWw
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で割り切れるときは代わりにFizz
5で割り切れるときは代わりに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
SAMPLESAMPLE
C言語でのサンプルコードを紹介
実際に皆さんには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 = 1
y = 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とfor
whileは条件に一致する間繰り返し
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の倍数はFizz
5の倍数はBuzz
両方の倍数はFizzBuzz
世界のナベアツ問題
3の倍数はAho
3がつく数字も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

Introduction of Programming language