クラウドの使い道

クラウドの説明会が近い

仕事で説明会があるので、予習も兼ねていくつかの記事を読んでみた。

振り返って

クラウドを使うということは、分散処理が特異で、スケーラブルなシステム構築を行うことができる。また、プラットフォームとして提供することで、アプリケーションやフレームワークを、独自でサーバーを構築せずに動作させることができる。

質問

クラウド上にフレームワークを提供すれば、そのフレームワークを使う人の利用が増えるだろう。それ以外に、クラウドを構築するメリットってなんだろう?融通の効く計算機貸出にあたるのかな。

1/13/02:13追記

まなめさんから、クラウドの説明記事をtwitterで紹介してもらったThanks,id:maname

クラウドといよりクラウドコンピューティングなんですね。GmailHotmailクラウドコンピューティングを使ったサービスの一種となると、既にwebを使っているユーザにとっては馴染みが深いものなんだ。

Ruby1.8系における1バイト(文字)と文字リテラルの関係

バイトってなんだろう?

Rubyを習得中、Stringクラスの演算子"<<"の説明に次の記述を見つけた。

0から255までのFixnumである場合はその1バイトを末尾に追加する。

言っている意味が分からない・・・。特に「1バイト」に関する理解が不足している。「『1バイト=8ビット』の単位のことでしょ?」という訳ではなさそうだ。
よく考えてみれば、今まで「『ひらがな』はマルチバイト文字。」と分かったように使っていたが、「バイト」とは「文字の表現方法」であり、その意味は深く考えたことがなかった。
というわけで、恥を忍んで、文字の中でも「1バイト」に絞って調べてみた。また関連して、Rubyの「文字リテラル」についても調べてみた。

1バイト文字とは*1

1バイト(8bit)のデータで表現できる文字。半角の英数字や記号、半角カタカナなどが含まれる。

Ruby1.8系における文字リテラルとは*2

その文字(バイト)の文字コード値のこと。

Ruby1.8系で1バイト文字を文字リテラルで表す

例えば、"a"は次のようになる。

# irb
irb(main):001:0> ?a
=> 97

ここまで理解したうえで、改めて、冒頭のStringクラスの演算子"<<"の挙動を調べてみる。

Stringクラスの演算子"<<"の挙動

定義

文字列(String)クラスの演算子"self << other"は、文字列オブジェクトotherが、0から255までのFixnumクラスの数値リテラルの場合、数値リテラルを1バイト(文字)として、selfに連結する。

動作例その1(1バイトの代入)

「はじめてのRuby」p.58 例4-1のコード"ex401.rb"を次に示す。

str = String.new
str << 72 << 101 << 108 << 108 << 111
p str
puts "str[0] = #{str[0]}"

ex401.rbを実行すると次のとおり。

# ruby ex401.rb 
"Hello"
str[0] = 72
動作例その2(文字列リテラルの代入)

続いて、文字列リテラルで各文字を記述して連結する方法"ex401r.rb"を次に示す。

str = String.new
str << "H" << "e" << "l" << "l" << "o"
p str
puts "str[0] = #{str[0]}"
p

ex401r.rbを実行すると次のとおり。

# ruby ex401r.rb
"Hello"
str[0] = 72
動作例その3(文字リテラルの代入)

最後に、文字リテラルで各文字を記述して連結する方法"ex401rr.rb"を次に示す。

str = String.new
str << ?H << ?e << ?l << ?l << ?o
p str
puts "str[0] = #{str[0]}"

ex401rr.rbを実行すると次のとおり。

# ruby ex401rr.rb
"Hello"
str[0] = 72

振り返って

Ruby1.8系では、「文字」は「文字リテラル」で表現すると「バイト」で表現される。「文字列リテラル」も、文字列の添字アクセスした際も、添字のバイト位置にアクセスし、その位置のバイト値を返す。マルチバイト文字の扱いや、1.9系の処理の違いは、またいつの日か。

シンタックスシュガーとは?

定義*1

言語を読み書きしやすくするための、機能的には本質でない構文。それができなくても他の構文で同じことを表現できるもの。構文糖とも.

つまりどいいうこと

本当は他の構文で書くことができるけれど、視認性を高めるために、別の方法を使って記述したコードのこと。見やすさ重視ってことですね。

試しにコードを書いてみる

シンタックスシュガー21選 - critbitの日記を見て、「15 - Nested Ternary Operators(ネスト三項演算子)*2」が今調べていることに近いので、21 Ruby Tricks You Should Be Using In Your Own Codeからコードを拝借して走らせてみる*3

qty = 1
var = qty == 0 ? 'none' : qty == 1 ? 'one' : 'many'
p var
#上記の式は次の式と同値である
var = (qty == 0 ? 'none' :(qty == 1 ? 'one' : 'many'))
p var

実行結果はこちら。

# ruby example.rb         
"one"
"one"

シンタックスシュガーなので別の構文で記述する

上記のコードを別の構文で書き換えると次のとおり記述できる。

qty = 1
if qty == 0 then
   var = 'none'
elsif qty == 1 then
   var = 'one'
else
   var = 'many'
end
puts var

実行結果はこちら

# ruby ex101.rb
one

振り返って

この調査は、1+2という式が、実際には1.+(2)というメソッド呼び出しで定義されていることを知りびっくりしたのが発端。シンタックスシュガーによっては、コードの視認性が上がるので、ただ書いて満足するだけでなく、そのうえで、「どうしたら読みやすいか」というところに注目していこう。*4

*1:「はじめてのRuby」p. 196

*2:ネストとはネストとは (nest): - IT用語辞典バイナリより、構造化プログラミングにおいてプログラムを構築する手法の一つで、あるルーチンやデータブロックの中に、別のルーチンやデータブロックがはめ込まれることである。入れ子構造とも呼ぶ。

*3:2010.1.12 コードが間違っていたので修正。本当ははてなで取り消し線とか - himadatenodeの日記などで一重線で取り消したいがrubyのコードブロックの中でははてな記法が無効らしい。

*4:そのためのペアプログラミングなんだろう

略語(e.g. cf. n.)の使い方、確認してますか?

脚注の使い方に悩む

公私を含め、今までは、記録を取るときに「『例えば』の時は『ex.』、『つまり』の時は、『→』」などと独自のルールで使用していた。特に、脚注(ex.新しい単語が出た場合の意味)等を「すぐ側に書いていいのか」「末尾に書くべきなのか」悩みながら書いていたのも事実だった。
そこで、後で記録を読み返したときに、正式な使い方に則っておくと、読み返したときに「復習しやすい」と思い、まずは、何気なく使いがちな「略語の正式な使い方」について調べてみた。

参考サイト

略語の使用例を整理

使用頻度が高い略語は「例えば」「つまり」「参考」「脚注」の4点である。このため、この4つの略語の対応表を次に示す。使用例はRubyに関連した文章にするため「はじめてのRuby」に掲載されている文書を引用させてもらった。*1

意味 略語 使用例
例えば e.g. , ex. Rubyコマンドの実行の際、「--」でオプションの終了を明示する。(e.g. プログラム名が「-hoge.rb」等の場合は、「--」を付けることで実行可能。)
つまり i.e. ローカル変数はスコープの狭い変数だ。(i.e.特にに理由が無い限り、ローカル変数を使用するのが良い習慣だ。)
参考 cf. 否定演算子!,!=,!~ はRuby1.9系では再定義可能になった。(cf.はじめてのRuby p.110)
脚注 n.,fn.*2 条件演算子?は条件によって値を振り分けるような式を提供する。(n. Rubyのif式は値を持つため、実のところ条件演算子はif式の別の書き方に過ぎません。)

振り返ってみて

当たり前だけど、「分かりやすい」「相手に分かる」文章を書くには、その文章で使用する語句の意味を理解して使用することが大切です。脚注については、一般的な文書の書き方に則って、ページの末尾に表示される方式で記述するようにします。

*1:はてな記法で脚注を付ける場合は、はてな記法一覧 - はてなダイアリーのヘルプを参考にした。

*2:複数がnn.と書いてあるが、そもそも「複数」とは何なのか不明。注釈が複数個ある場合なのか?

MacPortの更新Tips

raydiveさんより、この方法だと時間がかかってしまうことが判明。やり方としては次の2パターンがあるとのことでした。

  1. 急ぎのとき
    1. port upgrade 必要なports
  2. 時間があるとき
    1. port upgrade outdated で更新かかっているport

id:raydiveさん、ありがとうございました。他のコマンドもMacPorts-JPを見て調べてみます。

MacPortsのupdateの注意点。

発端

いつものとおりMacPortsにインストール済みのライブラリをupgradeしようとしたら次のエラーが発生した。

# sudo port upgrade installed
      • > Computing dependencies for aquaterm
      • > Building aquaterm
Error: Target org.macports.build returned: shell command "cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm" && xcodebuild -target "AquaTerm" -configuration Deployment build OBJROOT=build/ SYMROOT=build/ MACOSX_DEPLOYMENT_TARGET=10.5 ARCHS=i386 SDKROOT= USER_APPS_DIR=/Applications/MacPorts FRAMEWORKS_DIR=/opt/local/Library/Frameworks" returned error 1 Command output: === BUILDING NATIVE TARGET AQTFwk OF PROJECT AquaTerm WITH CONFIGURATION Deployment === Checking Dependencies... Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'AquaTerm.framework-Info.plist'. CopyPlistFile /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.framework/Versions/A/Resources/AquaTerm.framework-Info.plist AquaTerm.framework-Info.plist cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copyplist AquaTerm.framework-Info.plist --outdir /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.framework/Versions/A/Resources error: can't exec '/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copyplist' (No such file or directory) === BUILDING NATIVE TARGET AquaTerm OF PROJECT AquaTerm WITH CONFIGURATION Deployment === Checking Dependencies... Warning: Multiple build commands for output file /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.app/Contents/Resources/help.html CopyTiffFile /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.app/Contents/Resources/Cross.tiff English.lproj/Cross.tiff cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copytiff English.lproj/Cross.tiff --outdir /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.app/Contents/Resources error: can't exec '/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copytiff' (No such file or directory)

BUILD FAILED **

The following build commands failed: AQTFwk: CopyPlistFile /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.framework/Versions/A/Resources/AquaTerm.framework-Info.plist AquaTerm.framework-Info.plist AquaTerm: CopyTiffFile /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.app/Contents/Resources/Cross.tiff English.lproj/Cross.tiff (2 failures) Error: Unable to upgrade port: 1 Before reporting a bug, first run the command again with the -d flag to get complete output. [kynbit@Razza] # sudo port upgrade installed -d
      • > Computing dependencies for aquaterm
      • > Building aquaterm
Error: Target org.macports.build returned: shell command "cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm" && xcodebuild -target "AquaTerm" -configuration Deployment build OBJROOT=build/ SYMROOT=build/ MACOSX_DEPLOYMENT_TARGET=10.5 ARCHS=i386 SDKROOT= USER_APPS_DIR=/Applications/MacPorts FRAMEWORKS_DIR=/opt/local/Library/Frameworks" returned error 1 Command output: === BUILDING NATIVE TARGET AQTFwk OF PROJECT AquaTerm WITH CONFIGURATION Deployment === Checking Dependencies... Warning: The Copy Bundle Resources build phase contains this target's Info.plist file 'AquaTerm.framework-Info.plist'. CopyPlistFile /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.framework/Versions/A/Resources/AquaTerm.framework-Info.plist AquaTerm.framework-Info.plist cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copyplist AquaTerm.framework-Info.plist --outdir /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.framework/Versions/A/Resources error: can't exec '/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copyplist' (No such file or directory) === BUILDING NATIVE TARGET AquaTerm OF PROJECT AquaTerm WITH CONFIGURATION Deployment === Checking Dependencies... Warning: Multiple build commands for output file /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.app/Contents/Resources/help.html CopyTiffFile /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.app/Contents/Resources/Cross.tiff English.lproj/Cross.tiff cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm /Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copytiff English.lproj/Cross.tiff --outdir /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.app/Contents/Resources error: can't exec '/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/copytiff' (No such file or directory)

BUILD FAILED **

The following build commands failed: AQTFwk: CopyPlistFile /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.framework/Versions/A/Resources/AquaTerm.framework-Info.plist AquaTerm.framework-Info.plist AquaTerm: CopyTiffFile /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_aquaterm/work/aquaterm/build/Deployment/AquaTerm.app/Contents/Resources/Cross.tiff English.lproj/Cross.tiff (2 failures) Error: Unable to upgrade port: 1 Before reporting a bug, first run the command again with the -d flag to get complete output.
どうやら、AQRFwkとAquaTermが悪さをしているらしいので削除しようとすると次のエラーが出る。
sudo port uninstall AquaTerm
      • > Unable to uninstall aquaterm 1.0.1_3, the following ports depend on it:
      • > gnuplot
Error: port uninstall failed: Please uninstall the ports that depend on aquaterm first.
ニコニコ動画研究会の時にいれたgnuplotに依存しているようなので、gnuplotから削除。*1 *2
#sudo port uninstall gnuplot 
# sudo port uninstall AquaTerm
      • > Deactivating aquaterm @1.0.1_3
      • > Uninstalling aquaterm @1.0.1_3
# sudo port uninstall AQTFwk
そして、いつもどおり、MacPortsのupdateをかける。
#sudo port -d selfupdate
略
#sudo port -d sync
略
これで、MacPortsの情報は最新となった。

*1:しばらく使わないと思うので。他のライブラリをupgradeさせることを優先しました。

*2:もし、途中でインストール失敗したらMacPortsでのffmpegのインストールで必要なさそうな苦労をした話 - Bouldering & Com.のコマンドを参考にして、一旦cleanしないといけないようです。

デザイン更新

前までのデザインを数年使っていたので、心機一転今の自分が好みのものに更新。
更に、http://d.hatena.ne.jp/yuzuchikin/20090731/1249041633を参考にして、twitterの発言をサイドバーに表示させた。id:yuzuchikinさん、ありがとうございます。
また、flickrからこちらからブログパーツを作って写真も表示してみた。
twitterflickrは、id:kynbitを紹介するうえで外せないので満足。