インデントにタブではなくスペースを使う理由


コードを書く際によく話題になるインデント。タブを使いますか?スペースを使いますか?それともほかのなにかを使いますか?

私はスペースを使います。 それはインデントが見易さのためのものだからです。

タブは制御文字

タブは制御文字で見易さの調整に使われるものではありません。確かに昔はタイプライターの位置調整のために使われていたそうですが、今はそういった使われ方はしません。もしタブ文字がタイプライターにおける水平タブと同じ意味を持つのなら、タブ幅を個人で変えられるようにはしなかったでしょう。

TSV では、 タブは異なる属性だとか、異なる種類だとかいう意味を表すための区切り文字になります。 タブでインデントを行ったソースコードをコピーしてExcelに貼り付けると、タブでインデントされた文字は別の列に貼り付けられます。 そういった情報の制御文字として タブは使われています。

ありがちな誤解

このようにタブを制御文字として扱うと、「インデントは情報の深さを表すものだから、タブでインデントしてもいいじゃないか」と考えてしまうこともあるかもしれません。 たしかにタブを使っていれば、先ほど例に挙げた Excel にコードを張り付けるケースでは、インデントされた行はそれだけ右のカラムに貼り付けられます。

しかし、情報の深さはインデントだけで決まるものではありません。 そのため、仮にすべてのコードがきれいにインデントされているとしてもタブを使うべきではないです。

下に情報の深さをインデントを使って表した例を示します。 (都合上 下の例ではインデントをスペース2つで現しています。)

インデントを情報の深さとしてとらえると、1つ目では特に深い情報がなく、2つ目では1行に書ける関数でも、仮に引数が1つでも改行とインデントが必要になります。 また2つ目ではカンマの存在意義がありません。

最後に

最初に書いた「私はスペースを使います。 それはインデントが見易さのためのものだからです。」というのはわかっていただけたでしょうか。 インデントは見易さの問題を解決する目的があるので、見える文字であるスペースを使っています。


Android アプリ Your Place のコードを公開します


東京メトロ オープンデータ活用コンテストがありました。 そのとき私が応募したアプリのソースコードを公開します。

概要

東京メトロの駅の中から行き先を決めてくれるアプリです。 家にいたくないけれど行き先が決まっていないときに使えます。 Android Wear とも連携し、 Android Wear で行き先や周辺スポットを見ることもできます。

理想

開発に使える時間の制約などから、単純に「行き先を決めてくれるアプリ」になっていますが、次の機能も実装したいと思っていました。

  • 気学を用いて運勢のいい方角のなかから行き先を決める。
  • 運勢のいい方角と現在地をマップ上で見られるようにする
  • 行き先を決める中で、そのときの気分を考慮する。
  • 行ったことのある東京メトロの駅を記録し、全駅コンプリートしたらなにかを出す。
  • 目的地の駅や乗り換えの駅に接近したら、 Android Wear に通知を出す。
  • 複数人で出かけるときの設定項目を考える。
  • タップだけでなく、 シェイク して行き先を決められるようにする。

要するにパーソナライズして本当におすすめの駅を探すということです。

振り返って

初めて作った Android アプリ にしてはそれなりによくできたのではないでしょうか。

class の名前などは知識不足もあり、 修正した方がいいものもあります。


ruby multi varsion control with pik


pik is a multi version control tool, which can be used in windows. When the time I wrote this article, pik on github says No longer maintained but I prefer to use pik on windows.

Pitfall

Tested on Windows 7 32bit.

Execute msi installer and install it to windows, but you can’t use pik. Some modification are required.

First, get new installer pik-0.3.0.pre.msi, which is the newest on writing this article, from the page of installer, and execute it.

It is installed into C:\pik as default. Then, open C:\pik\pik.bat and change %HOME% to %USERPROFILE% on 7th line.

In Windows, environmental variable %HOME% is not defined. %USERPROFILE% works well. It’s the same on Windows 8.1.


How to involve those who are taciturn into discussion


There is taciturn person in discussion. I introduce the way to let such a person speak. (I omit ice-breaking because it is the method for all persons.)

Premise

Preparation for discussion like clarifying the goal of it is already done. I suppose 1 or 2 person is taciturn in discussion.

( If any valuable opinion doesn’t appear, you may have problem in preparation or proceeding.)

Why you want to hear opinions from all members?

What does occur when there is taciturn person?

  • He say “I thought XX is the best solution” after the discussion.
  • You can’t reach everyone’s agreement and you can’t reach best solution.

Namely, discussion purpose fades away, I think.

Control the number of discussion members, first. It is difficult to discuss over all members when the number of members is greater than 10. I think appropriate number is 6. Please rethink it according to discussion format and content.

Now, I introduce the way to involve everyone into discussion.

Method

Give a role to the person

“I would be appreciated if you could talk from the aspect of XXX in the next discussion. So please join.”

The word should be changed according to your position. Like above, telling “What I want to do” in advance helps him to understand what kind of opinion to speak and how to look the discussion, and make it easy for him to express his opinion.

Ask the person for his opinion in advance

Ask him “What do you think about it?” in advance, individually. Then, if he become taciturn in discussion, you can spread discussion by saying “You have opinion that XXX is YYY, right?”.

Give a task to the person in advance

Opinion doesn’t appear if there is no hint. So give him a task in advance. “Prepare 2 or 3 solution about XXX.” In the discussion, you can proceed with prepared opinions.

That’s a matter of course to prepare for discussion in advance, but some people never prepare until they said to prepare.

Workshop for a small groups

This is effective when discussion member is many. Divide members into groups consists of 3 members and ask them write opinions on post-it. (Or write opinions individually.) In this way, the person who can’t speak in discussion tend to write opinion. Paste written post-it to whiteboard and make discussion deep. It relates to affinity diagram.

You can make discussion deep for each opinion (or selected opinion or categorized opinion), so you can trigger to make him speak by saying “Could you explain what this opinion saying?”

It is OK to write opinion onto post-it by 3 member group with discussing, and to write opinion individually.

Ask the person about his specialty

Suppose members gathered from several sections. Then, ask him “Mr. X, how can you see this issue from YYY aspect?” And after his answer, “Thank you. I was really helped, there’s no person with YYY specialty knowledge.” Thus, involve taciturn persons.

The case this method can be used is may be limited.

Make a rule

Make a rule, “Everyone should put opinion”. Opinion doesn’t appear however strongly he said to put, but such rule make him think about to putting opinion.

Expect Next Time

If he didn’t put any opinion in spite of your really struggling, ask him “Was there something wrong, you looked somehow curious?” Please, take attention to the telling way. This method tells him “we want you to put your opinion” softly.


A Life Summary of an Gypsy