Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340

Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/hitowomusubu/www/wp/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340
プログラミングをはじめよう! | 夢を叶える塾
スポンサーリンク

プログラミングをはじめよう!

ホームページのリニューアルに伴い一部のページは新しいサイトにリダイレクトされます。

 

しばらくは連載のような形でプログラミングを学びたいという方向けのの話をまとめていきます。
一通りの初歩的な事が終わったらランダムに投稿していきたいと思います。

はじめに

冒頭にあります通り、
「これからプログラミングはじめるぞー!」
という方向けにしばらくは書いていきます。

私はとにかく時間は大切なものであると考えています。
ですから意味あるものにしたいと思って記事を書いています。
せっかく読み進めて頂いた方に「なんか違うな…」と思って欲しくありません。
そのため、読み進める前に特徴を記しておきたいと思います。
それを見て、読みやすそうとか、読んでみたいという方に読んでいただければと思います。
世の中にこの手の記事は山ほどありますから、私の記事でなくても学ぶことはできますからね。

文章の書き方

多くのブログ記事は行間を開けたり改行したりして読者の方へ読んでる感を与えます。
私の記事はそういう要素は余りありません。
ただただ文章や時には画像を用いて解説する事に注力しています。
無駄にスクロールすることなく読むことに集中頂けると思います。
スマホで読むのは余りおすすめできないかもしれないですね。

細かい所まで書く

出来るだけ細かい所まで書き、読者の方に行間を補って頂かなくても読めることを意識しています。
そのため、既に感じておられるかもしれませんが、くどく感じる事があるかもしれません。
ただ、幸い数学や理科の記事ではわかりやすいとコメント頂いております。
もちろんわかりにくいと言われてしまう事もあるのですが…。
文章を良く読んで本気でプログラミングを学びたいという方には良いのかなと思います。
文章を流し読みして感覚で分かった気になってしまう方だとあまり効果的ではないと思います。

対象者

もちろんプログラミングをはじめてみたい方向けです。
そして理系センスがあって物事の理解が早い方向けではありません。
そういう方はたぶんサンプルコードを眺めて理解した方が早いと思います。
ここではどちらかと言えばコツコツと理解を積み上げる事の出来る方に向けて書いていきます。

「習うより慣れろ」でプログラム言語でいきなりソースコードを書き始める方が良いという方も多いと思います。
ただ、これは中々難しくセンスが必要だと思いますので、私はプログラミングを学んでからソースコードに進む方法をお勧めします。

連載のゴール

連載のゴールは「プログラミングで何か動くものを作れるようにする」というものではありません。
「プログラミングでどんなものが作れるようになるのか」はわかるようになると思います。
「プログラミングやろうと思うとこんな大変なのかor意外と簡単なのか」もわかるようになると思います。
ただ、そこは実際やってみて変わるかもしれません。

知識がメイン

プログラミングで何かを作るには知識とアイデアと論理的な思考が必要です。
ここでは知識を学んで頂きます。
ただ、アイデアは知識の組み合わせですから、もちろんアイデアにもつながります。
論理的な思考も、知識を前提として構築しますから、論理的な思考にもつながります。
具体的にどんな事が出来るのかという知識を知っていただきます。
それをどう使うかはその後の経験が必要となるでしょう。

という事で

長くなりました。
この長さに耐える事の出来る方ならきっとこの後もお読みいただけるのかなと思います。

プログラミングをはじめよう!

ここからプログラミングの話になります。

何が嬉しいのか

「それができると何が嬉しいのか?」というものは学ぶ上でのモチベーションとなります。
まずそういった話から始めたいと思います。

自分専用のアプリを作れる

プログラミングはまず何と言っても「欲しいアプリを作れる」が最も大きいモチベーションになり得ます。
自分が必要とするものを実現する自分専用のアプリ、魅力的です。

私はこれを自分の仕事の中に取り入れています。
詳しくは書きませんが、普通にやったら1日掛けても終わらない作業を1時間で勝手に終わらせてくれます。
一度作ってしまえば、後はいくらでも動き続けてくれます。

仕事の幅が広がる

単純にプログラミングの仕事ができるだけでも大きな財産です。
加えてこれからのAI時代、AIに何ができるのか知っている事は大きな強みになるでしょう。
連載の中ではAIの解説をする予定は余りないのですが、出来る事の推測には役立つでしょう。

数学が得意になる

私が数学を得意とする要因となった一つがプログラミングです。
まだ解説していないのでわかりにくいかもしれませんがプログラムの中で変数というものがあります。
数学で使う文字みたいなものです。
小学校の頃からプログラミングに慣れ親しんでいましたので、中1で文字を習ったときは当たり前すぎました。
「x=x+1」なんて記述をプログラムではよくしますので、馴染みのない方は「こんな方程式間違っている」と思われるかもしれません。
しかしプログラミングの中で「=」の理解も正しくできていましたので、この「=」は方程式の「=」とは違うものだと直ぐに理解できました。
プログラミングの中でa^2等も出てきますから、指数も自然と覚えていましたし、ルートの概念も中1で持っていました。
sinやcosも画像を描画する時の座標計算に用いますので、極座標という概念も中学生の段階で持っていました。
小学生の頃からプログラミングを趣味として出来ると数学には強くなれると思います。

そもそもプログラミングとは何か

一つの解釈としてはパソコンやスマートフォン上で動作するソフトウェアやアプリを作成する事ですね。
ソフトウェアやアプリを動かすためのプログラム(ソースコード)を作成する事がプログラミングです。
でも知りたいのはそういう事ではないはずです。
「パソコンに演算や画面操作を行う支持を与えるプログラム言語に従った命令文の集合」
というと伝わるでしょうか?
命令文一つ一つがプログラムの要素になります。

プログラムの例

まず「1+1を計算した結果を画面に表示させなさい」という命令文を書いたプログラムを考えてみます。
もちろんこの命令文は日本語で記述するのではなく、プログラム言語の書き方に沿った命令文が必要です。
正しく記述できていれば、実行すると画面に1+1の結果の2が表示されます。

「GPSにより現在位置の地名を表示する」というアプリはどのようなプログラムになるか?

  1. GPSによる現在位置(緯度経度)の取得
  2. 現在位置を地名に変換
  3. 変換した地名を表示する

こんな命令文を順に実行するプログラムになるでしょう。
わかりやすくするためにこのような記述をしていますが、ここで書いた1つの命令文は、プログラム言語の命令文1つに必ずしも該当しません。
この順序で進めていくと、現在地に関わらず必ず現在の地名が表示されます。

このように書くとかなり簡単なように見えてしまいます。
しかし本当に必要なプログラムはこの3つの命令文にとどまりません。
GPSで位置情報を取得する命令文は、その命令をスマホ等に与えるための手続き(準備)が必要になりますがそういう命令文を入れていません。
もしGPSの機能が使えないときはGPSを使えるように促すアラートを出さなければならないかもしれません。
「GPSが使えるか確認して、その結果使えないときはどうする、使えるときはどうする」という判断するような命令文が本来必要になります。
取得する位置情報を地名に変換するためには、そのようなサービスを提供しているAPIを使わなければなりません。
いきなりこう言ってしまうとわけがわかりませんが、GPSの利用や緯度経度を地名に直す方法はそう単純にはいかないのです。
ここでは「そう単純じゃないんだー」という事だけわかっていただければと思います。

これらをもう少し詳しく説明するためにはプログラミングの知識が必要になります。
この連載でプログラミングについて学んで頂くと、ソフトウェアやアプリがどのような命令で動いているのか想像できるようになると思います。

プログラム言語とアルゴリズム

「パソコンに演算や画面操作を行う支持を与えるプログラム言語に従った命令文の集合」
と書きました。
「プログラム言語に従った命令文」という点もポイントになります。
プログラム言語はいくつも種類があります。
おそらく現在最も有名なプログラミング言語はJavaでしょう。
そのほかC言語、VisualBasic、様々な言語が存在しています。
同じ「1+1を計算した結果を表示する」という命令文であっても、それぞれの言語で違った記述が必要になります。
しかし基本となるルールはおおよそ同じですのでご安心下さい。
※ただ、Javaだけは「オブジェクト指向」という考え方を使うので、少し特殊になりますね。
いずれもその言語で使える記述を組合せて一つのソフトウェアやアプリを作っています。
この連載ではこのプログラミング言語を意識しない部分をまとめていきます。

ソフトウェアやアプリの根幹となる命令文の流れは、どのプログラム言語で作ろうと思ってもほぼ同じものが使えます。

  1. GPSによる現在位置(緯度経度)の取得
  2. 現在位置を地名に変換
  3. 変換した地名を表示する

この流れはどのプログラミング言語を使っても流用できます。
このような目的を達成する事の出来る命令の流れを「アルゴリズム」と言います。
アルゴリズムは正解が1つではありません。
GPSの例ではこのレベルであればこの流れに決まってしまいそうですので違う例を考えてみます。
例えばナスとカボチャを複数個買う時の合計金額を表示するプログラムを考えてみます。
ある人は次の様に考えました。

  1. ナスの個数分の金額を計算する
  2. カボチャの個数分の金額を計算する
  3. それぞれのの金額を足して表示する

また、ある人は次のように考えました。

  1. カボチャの個数分の金額を計算する
  2. ナスの個数分の金額を計算する
  3. それぞれのの金額を足して表示する

更に、ある人は次のように考えました。

  1. カボチャの個数分の金額とナスの個数分の金額を足して表示する

いずれも同じ結果が得られます。
全て正しいアルゴリズムになります。

はじめのうちは余りこの違いを意識しなくても良いでしょう。
正しい結果の得られるアルゴリズムを作ることに注力して良いと思います。
ただ、いずれはこの違いを意識して、よりベターなアルゴリズムを選択できるようにならなければなりません。
計算速度に大きな差が出てしまう場合がありますので、慣れてきたら意識できると良いですね。

終りに

まずは初回という事で「プログラミングをはじめよう!」というタイトルでしたが、プログラミングとアルゴリズムについてのお話しまでしてしまいました。
記事の中にも書いていますが、ソフトウェアやアプリがどのような命令で動いているのか想像してみると、アルゴリズムの習得が早まります。

にほんブログ村 地域生活(街) 東北ブログへ にほんブログ村 地域生活(街) 東北ブログ 米沢情報へ にほんブログ村 教育ブログへ にほんブログ村 教育ブログ 塾教育へ
スポンサーリンク