ときどきの雑記帖 原石編

最新ページへのリンク
目次ページへのリンク

一つ前へ 2011年8月(中旬)
一つ後へ 2011年9月(上旬)

ホームへ

2011年08月31日

■_

ジュンク堂新宿店
今の場所からなくなるのは確定と。 コンピューター関連の洋書の扱いが徐々に少なくなってきてて それにあわせてあまりいかなくなったなあ。 交通費からいうと新宿店も池袋店も変わらないし。 新宿店だと代々木の方へ行って紀伊國屋書店の新宿南店も回るというのができるけど (池袋店だと電車降りないと)。

蘭陵王 奔流 (祥伝社文庫) 呉越春秋 湖底の城 第二巻

4年間続いた「さよなら絶望放送」が本日の配信でさよなら~ :おた☆スケ
こもりきりぞうさんが…

■_ カウボーイ流

カウボーイプログラマーのやり方。

The Cowboy Coder
The Cowboy Way (from c2.com):

   The speed with which I can hack something together determines my worth

   People who need comments in order to understand my code are too dumb to be working with me
   俺のコードを理解するのにコメントを読む必要がある奴は一緒に仕事をするにはxxxすぎる

   People who ask me questions about my code are too dumb to understand it, and (therefore)
   are too dumb to be working with me

   俺のコードについて質問してくる奴はそのコードを理解するにはxxxすぎで、
   一緒に仕事をするにはxxxだ。

   Other people's code is just crappy, but mine is self-descriptive and beautiful
   ほかの奴の書いたコードは単なるくずだが俺のは self-descriptive で美しいものだ

   Exploiting a compiler-dependent language feature to save a line of code is "elegant"

   Other people on my team cause all of the bugs; I'm the one that fixes them
   チームのほかの奴はすべてのバグを作り出す。おれはそれを修正する人間だ

   My code is never at fault, always perfect, and I don't make mistakes
   俺のコードは決して間違うことはなく、常に完璧。俺は間違うことはない

   Since my code is never at fault, I don't need to test it thoroughly, if at all
   俺のコードは決して間違わないのだから、テストをする必要なんてない

   Since my code is always perfect, it never needs to be refactored no matter how long it's
   been in the codebase or how much has changed around it
   俺のコードは常に完璧なので、リファクタリングの必要は絶対にない。

   Since I never make mistakes, I can yell at anyone else who does

   Since my code is perfect, if the program crashes due to unexpected data, it's the user's
   fault for entering bad data.
   俺のコードは完璧なので、予期せぬデータによってプログラムがクラッシュしたのなら
   それは変なデータをつっこんだユーザーのミスだ

   Since my code is perfect, if the program fails after a minor machine configuration change,
   it's the sysadmins fault for changing it.

   俺のコードは完璧なのだから、マシンのコンフィグレーションをちょっと変えた後で
   プログラムがおかしくなったのなら、それはそんな変更をしたシステム管理者が悪い

   Since my code is perfect, if the program runs too slowly, it's the managements fault for
   not providing a faster machine.

   俺のコードは完璧なのだから、プログラムが遅すぎるというのならそれは
   高速なマシンを用意しなかったというマネジメントの落ち度だ

■_

How to guide your project towards failure


    I was chatting with some co-workers of mine today on Project X and the discussion turned
    to:  Why is our project having so much trouble completing all its goals?  The answer that
    I came up with is structural, and drove this blog post.

    In short, here's how to structure a project for failure.

    Step 1:  Create a project with goals A, B, and C.   Fund it reasonably to accomplish
    those goals. 

    At this stage, everything is working very well.  Proceed to step 2!

    Step 2:  Involve more than one person in the management and direction of the project.

    This step takes many forms.  Sometimes it's a committee or board that runs the project,
    other times it's reporting to multiple bosses and/or centers for guidance.  Either way
    it's critical to ensure that there are at least two people with differing priorities,
    all of whom have some sort of say in the project.

以下ステップ7まで。


■_ あーありがち

繰り返しの中に繰り返しがあるな。

正規表現 Part8 [chaika]

414 デフォルトの名無しさん [] 2011/08/31(水) 23:22:12.28 ID: Be:
    ttp://msdn.microsoft.com/ja-jp/library/ff650303.aspxから拝借した
    ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
    を使ってメールアドレスの書式チェックを行っているんですが、
    40文字とか多めの文字数で不一致の文字列を試すと、
    フリーズしてしまいます。

    一致するケースは問題ないんですが。。。
    一致しない時はバックトラッキング?が発生している?
    実装言語はaspです。

    対象文字列が長くて不一致のケースでも、
    動作に問題のない一般的なメールアドレスを許容する表現があれば教えて下さい 

415 デフォルトの名無しさん [sage] 2011/08/31(水) 23:49:58.59 ID: Be:
    組み合わせ爆発が起きてるかな? 

たぶん415の見立てで間違いないと思います。 一致しない場合は無用にバックトラックせずにすむようにすべきなんですが さてこれは

■_

■_

一年の 2/3 が過ぎました。と。 はて、今年の目標なんだっけ?w

2011年08月30日

■_

買った
って、けっこうあるな(^^;
MASTERキートン 1 完全版 (ビッグ コミックス〔スペシャル〕) MASTERキートン 2 完全版 (ビッグ コミックス〔スペシャル〕) ナポレオン~覇道進撃 1 (ヤングキングコミックス) THE SEA OF FALLEN BEASTS -滅びし獣たちの海- (ビッグ コミックス〔スペシャル〕) 電波の城 13 (ビッグ コミックス) 成恵の世界 (12) (角川コミックスエース)

今月の皇帝陛下
YOUNGKING OURS (ヤングキングアワーズ) 2011年 10月号 [雑誌]
結構大きな判断ミスを何度かやってるんだよね>皇帝陛下 それがリカバリできなくなったときが終わりだったということなんだろうか。

■_ SWIG

Why the author of SWIG 'hates' SWIG とか

Why the author of SWIG 'hates' SWIG... : Python

Why the author of SWIG 'hates' SWIG... (code.activestate.com)


Everything he has said here makes perfect sense. In order to correctly parse C++ code 
you basically need a full C++ compiler. What's more, you need the compiler to be the 
same compiler as the compiler you are actually using (due to differences in different 
C++ compiler parsing).

This is one of the reasons I really approve of the approach that boost::python takes 
to python binding: It uses the built-in C++ knowledge of the type system and code 
structure that the compiler itself uses to bootstrap the binding code.


But building your import module, packaging, etc become a huge pain.

I much prefer either ctypes or Cython/Pyrex myself.


I agree with the ctypes approach - you provide the linkage info by defining the interface
between the library and python, you make it work. No huge expectations that the binding
between one extremely complex system (C++) and another very complex system (python) should
be easy or magical. If it's hard, it's hard, and you don't get to turn your problem into
someone else's (and then complain that free software doesn't have any support for simple
things like reading your mind :)


Building is a pain, particularly on Windows where you don't have a packager to deal 
with Boost for you, because Boost is an asshole. It's one of those problems you just 
need to solve once, though. (And take good notes.)

I had a much better time of things after I decided to ditch bjam and use waf.


Having recently used SWIG, I was very much interested in the idea of being able to 
write a single definition file that produces bindings for a variety of languages.

The first problem I encountered was that SWIG doesn't handle callbacks, but the 
library I was wrapping used callbacks. I figured this out, but it required some 
Python-specific typemaps. "No problem," I thought, "at least I can just 
write the callback stuff for each language, and SWIG will take care of the rest."

However when I got to looking at Java and dealing with representing callbacks in 
listener objects, I went and learned a little about JNI and realized it wouldn't be so 
hard to just write the wrapper directly in JNI.

Then I looked at other languages, and realized the number of corner cases I'd have to 
handle with SWIG for each language, and sort of threw up my hands... I also realized 
it might have been less work to use ctypes in the first place for Python.

So in the end I have a SWIG binding which is Python-specific and a Java binding, and 
haven't really gotten around to thinking about other languages because I'm scared off 
by the idea of having to learn the ins and outs of n runtime engines.

I still think a multi-language binding generator is a great idea and would be 
immensely beneficial. However, SWIG doesn't go far enough, as it's too tied to C types. 
Higher-level languages require higher-level types. For instance, in a sort of 
Haskell-inspired way, in my SWIG binding I defined a "maybeFloat" typemap 
for functions that took a pointer to a float, where the pointer could be NULL. Then I 
just had to define a typemap that translated Python numbers to float and passed in its 
address, or translated None to NULL, or threw an exception otherwise.

If higher-level typemaps like this can be used to describe the semantics of a C 
function beyond the C semantics but instead cover the semantics of the target language, 
then perhaps this approach could work. The lack of callback support was a show-stopper 
for me, though, in terms of using SWIG for multiple languages.


I love C++, I really do. I think C++ is an amazing language. That being said, C++ is a 
horrible thing to use in a library. If I would want to write a library in C++ I would 
do it like zmq does and provide a C API from it.

As such I would write a tool that automatically generates a C API/ABI from a C++ API 
and then automatically generate Python bindings for that via ctypes. And yes, clang 
would be the tool of choice for both parts.


Also, you can't dynamically link to C++ API.


Regarding writing libraries and plugins in C++..

I do like C++ for giving me features that save me time while developing. Foremost the 
STL (yay std::vector<T> and algorithms). I really don't want to implement and 
maintain these basic data structures myself, like you see in so many C programs. 
Another thing I love is being able to define interfaces via abstract classes. If I 
screw something up while i.e. doing heavy refactoring the compile just tells me. A 
real time saver.

But what drives me nuts is when you compile a C++ plugin and the proprietary host 
program, written at least partly in C++ as well, crashes randomly all of the sudden. 
The reason: STL implementation/version mismatches. This happens even if you're using a 
C API provided by this C++ host. Debugging these issues is a nightmare, require deep 
knowledge and determination. Many of my colleagues aren't even C++ coders and it would 
be virtually impossible for them to handle these situation, let alone within a 
reasonable amount of time.

I'm sure one can work around all these issues. Boost.org's unholy trend to have header 
only libraries is one way to solve this issue and make compile times binary sizes 
explode.

The question is if it's worth the hassle. These days I still write i.e. python modules 
in C++ when I hit a bottleneck, since the code just flows out of my fingers. But when 
I know something will be used outside of my machine I rather sit down I learn how to 
write yet another C implementation of a basic data structure, knowing that my code 
will work just fine for the next 10 years.

元記事を読まないと何がなにやらw

■_

I'm starting Functional Programming class next semester and I have few questions. (repost from /r/compsci) : lisp

(Repost from http://www.reddit.com/r/compsci/comments/jy4tn/askcompsci_im_starting_functional_programming/)

In October, I'm going to attend FP class (last year of MSc studies). As far as I heard 
from friends, there will be two major assignments for this class: one Haskell project, 
and one report on some other functional programming language, each student picks one. 
Moreover, the class will also cover theoretical aspects of FP, such as lambda calculus.

十月に、わたしはFPクラス (last year of MSc studies) に参加しようと思っています。
友人から聞いたところでは、このクラスには二つの majro assignments があるのだそうです。
ひとつは Haskell project で、もうひとつは何か別の関数プログラミング言語についての
report です。学生はそれぞれひとつ選択します。
加えてこのクラスでは、ラムダ計算のような FPの理論的な背景もカバーするそうです。

I have only little experience with FP, mainly some Haskell and Scala, nothing serious though.
わたしはFPについてはほんのわずかの経験しかなく、HaskellとScalaを
ちょっと使ったことがあるだけです。

My questions are:
わたしの疑問は以下の通りです:

    * Which other FP language should I pick and why? (it doesn't have to be Lisp) I'd like to
      know how they compare in terms of popularity, difficulty, tool support, novel ideas,
      non-standard ways of problem solving. I want my choice to be potentially useful in my
      career and/or to help me broaden my horizons.

      Haskell 以外のFP言語としてどれを選択すべきで、またそれはなぜでしょうか?
      (これはLispである必要はありません)

    * What good on-line and/or printed materials on FP would you recommend? Language tutorials
      and also more theoretical stuff? I'd especially appreciate good materials on lambda
      calculus, because apart from the name I don't know anything about it.

    * Is there anything I should keep in mind when trying to understand all of it, especially
      if it's counter-intuitive for someone used to imperative programming or typical maths?

    * Apart from FP languages and lambdas what else should I expect?

    * Full name of the class is actually "Equational and Functional Programming". What
      does "equational programming" mean and does it differ from FP?

Thanks in advance.


It must be Lisp. (disregard username)


    Apart from FP languages and lambdas what else should I expect?

Purely Functional Data Structures.


As soon as I take a photo of it at faculty building and translate it to English, so not sooner
than in 20 hours. Our faculty does a rather sloppy job with updating the website, some subjects'
syllabi are not available on-line.

I managed to find a part of recommended literature list:
J.Fokker's Functional Programming,
Hugs98 User Manual,
R.Page's Two Dozens Short Lessons with Haskell and The Craft of Functional Programming

EDIT: and also L.C. Paulson's Foundations of Functional Programming,
and H. Barendregt's Lambda Calculi With Types and The Impact of Lambda Calculus in Logic and Computer Science

As I said, I'll post more tomorrow.

Purely Functional Data Structures Haskell: The Craft of Functional Programming (2nd Edition) (International Computer Science Series) Haskell: The Craft of Functional Programming (3rd Edition) (International Computer Science Series)

■_

5 Reasons To Write Tests For Your Code - Master Nerd's Guide to the Force

August 29, 2011

5 Reasons To Write Tests For Your Code
あなたのコードのためにテストを書く五つの理由

I hate to admit it, but I wasn't always an advocate of writing tests.  My past self 
understood tests to be good practice; but typically saw them as a luxury.  Like fine 
china, they were shiny, but not something I could afford.

That being said, if I could go back I would certainly have some brutal lessons to share.

So as my first post, here are five arguments that I believe would convince my past self
to write programmatic tests.  I hope that these can convince others who are debating
whether tests are worth the time.


1. Tests use programming skills to check programming skills.
   テストはプログラミングのスキルをプログラミングのスキルをチェックするために使う

以下略

■_

2011年08月29日

■_

「さかのぼり日本史」再放送していたのか。 昭和 とめられなかった戦争(アンコール放送)|今月の放送|さかのぼり日本史|NHK もう最後だけど。 とりあえず9月の分からは録画設定しといた。

ヒトラー『わが闘争』がたどった数奇な運命
という本を読んだのですが、なんとも考えさせるものが。 「わが闘争」については高校生くらいのときに翻訳本を読んだ覚えがあるのですが (といってほとんど内容は覚えてない)、確かにその後の行動に現れたことが書いてあったりしたのですよね。 そしてその本(原著ね)は当時大ベストセラーになっていたと。

そういや二年か三年位前に、新訳の「わが闘争」が出るって 歴史群像に広告がでてたのだけど結局あれどうなったんだろう。 出版されてないことは確実だと思うんだけど (ドイツでは今でも発禁だそうです>「わが闘争」)。

■_

■_

やるきーぜろー

Ingrater’s 3D Blog ≫ Suggestions for the D 2.0 Programming Language

August 27th, 2011
Filed under: D programming ? admin @ 7:09 pm

First of all don't take this article to negative. I really like the D programming
language and often when I have to go back to C++ coding im sitting in front the code
thinking "Oh this would be so much easier in D" or "This could be
solved much cleaner in D".

I recently completed 3 Projects using the D 2.0 programming language:
- A implementation of the Light Propagation Volumes algorithm
- A 3d multiplayer cross platfrom (windows / linux) space shooter
- A lisp interpreter (with almost all Scheme features)

(以下略)
No Policy Can Save Wrong Code - Modern Perl Books, a Modern Perl Blog

No Policy Can Save Wrong Code

By chromatic on August 23, 2011 10:33 AM

I've written before that software projects need sane, published deprecation policies,
and I still believe that...

... but listen to a tale of two intertwined projects with a seemingly-sane and
published deprecation policy that sounds great but doesn't actually work.

(以下略)

No Policy Can Svae Wrong Code ってのは 「間違ったコードを救うポリシーは存在しない」 ってことでいいのかしらん。

■_ 不思議な不思議な

池袋JavaScript

A humorous list of JavaScript oddities : programming

wtfjs - a little code blog about that language we love despite giving us so much to hate

min less max
june 1 , 2011

This beauty is courtesy of TiTi ...lets look at some code.

    Math.max();
    // -Infinity

    Math.min();
    // Infinity

Ok, so, there is a good reason for this behaviour. It might even make sense if you 
happen to occasionally omit args from your min/max calls. ;)

You see, the min/max implementations need something to compare to and Infinity and 
-Infinity are the only safe values to use for that comparison. @kriskowell goes into 
more better detail here and was quickly followed by @brendaneich whom not only wrote 
js in 10 days but can rock out unicode Infinity symbols without looking them up ...I 
shit you not.

Of course, due to this behaviour js allows for this code humour:

Math.min() < Math.max();
// false

Oh JavaScript, I still love you.

↑こーゆーのがたくさんあります。 Math.max() が +Inf とか Math.min() が -Inf というのはなんとなく 納得できそうな気がしないでもw

■_

釘がないので For want of a nail :マザーグースの歌

2011年08月28日

■_

サクサクわかる世界経済の仕組み (メディアファクトリー新書)
を買って読むなど。 この二人の組み合わせで以前にも二冊くらい(歴史関連で)出ていたと思うけど、 それはB6サイズの単行本だったような。 内容はわかりやすいっちゃあわかりやすい。

■_ xor

さてと。 要するに、自分が矢沢さんの記事で気になっているのは 限定的(といってもわりと範囲が広かったりするのですが)な状況における最適解を、 さも汎用的な(普遍的な)ものであるかのように書いている点だと思います。 確かにニーモニックを見れば x86であることは明確にわかるわけですが、 にしたって「アセンブラの定番」とか 「アセンブラを知っているプログラマは当たり前のように使います」 ってどーにもひっかかります。 世の中、x86だけじゃないでしょ?と

結局のところ

melancholic afternoon

xor eax, eax vs. mov eax, 0

ときどきの雑記帖で呼ばれたので. 私はxor使うなあ. movを使うのはフラグを変更したくないと
きぐらい. 「xor eax, eaxが演算するので遅い」というのはどのCPUだろ. むしろ, Sandy 
Bridgeだとそういうxor eax, eaxなどのzero idiomは実行ユニットを消費しないとありますね
(最適化マニュアルの2.1.3.1とか「Intelプロセッサ最適化マニュアルを読もう」の
out-of-orderエンジンのリネーマ付近). Pentium4もそれようの特殊なサポートをする, Core 
Duoは実行ユニットを消費するとある. でもどれも殆ど分からないレベルだと思います. 実際,

みたいな単純ループで試すとi7, Xeron, Core2Duoで有為な差は見られませんでした. むしろ, 
mov eax, 0なら5byte, mov rax, 0なら7byteも消費する方が痛いんじゃないかと.

試しにコードサイズと実行速度の関係に関する話で試したicache.cppで大量のxor eax, eaxと
mov rax, 0を連続実行したときの速度を計ってみる. するとxor eax, eaxはコードサイズに関係
なくコンスタントに速いけどmov rax, 0は数十KBを超えたあたりで速度低下が発生しました(i7, 
Xeon, Core2Duo). 命令長が長いのでデコードが追いついてないんでしょうね. 

確かにコードサイズの問題はありますね。レジスターのサイズが16ビット程度ならともかく、 32ビット、64ビットとなるとその長さの定数値をロードするのは…というのは確かです。 RISCプロセッサーではゼロレジスターなんてものもありますし、 わたしの愛してやまない 680x0 では0~7の範囲の数値のロードを短い命令コードで 実行できる moveq (アセンブラーによって多少表記が変わったりする)なんてのがあります。 そして、上記の引用部でも触れられていますが

【レポート】IDF Fall 2010 - 「Sandy Bridge」アーキテクチャの詳細 - IDFで判明した情報を総括 (1) 全体の概要~CPUコアの詳細 | パソコン | マイコミジャーナル

ここに新機能として「Zeroing Idioms」がある。x86系でのZero Idiomとは、レジスタをゼロに
するようなXOR EAX,EAXなどの命令のことをいう。この命令はオペランドを持たず、高速に実行
でき、EAXにゼロをロードするよりも早いからである。しかも、この命令は、レジスタの以前の
値に関わらず常に一定の結果(ゼロ)となる命令である。「Zeroing Idioms」とは、おそらく、
こうした命令を正直に演算するのではなく、単にレジスタクリアしてしまうような動作を行わせ
るものではないかと思われる。この処理はμopを実行ポートへ転送するスケジューラの段階で行
われるため、μopは、ポートには発行されず、リネーミング機構でのゼロクリアとレジスタ
確保だけおこなうようだ(図07)。

インテルさんすげーっす ○| ̄|_

だいぶ以前の書き込みですが、こんなのもありました。

flat assembler - View topic - "mov eax,0" or "xor eax,eax"

    "mov eax,0" or "xor eax,eax"

which is faster? xor is smaller and simpler, but i've heard it somehow slowdowns with 
some dependancy lines or whatever... somebody has deeper knowledge on this?
There has been a debate on that before on these boards and we came to a conclusion 
that the best in speedwise/sizewise is AND EAX,00h because XOR EAX,EAX is more 
complicated and MOV EAX,00000000h is too long.

When you read agner's manual you should note that SUB EAX,EAX is bad because it is not 
bit-independent it could get as bad as one bit overflow carries to all 31 other bits. 
That is not the case with XOR.

EDIT:
NB! There are special cases though where AND EAX,00h crosses DWORD fetch boundary 
while XOR EAX,EAX doesn't. So the conclusion is not final Razz and is 3 bytes, where 
xor is 2 bytes.

Sorry for the type'o


That is because AND can be derived from regular switches two or more in a row, but XOR 
logic is very controversial to natural human brain. You could think of it as a 
carryless adder. And when you consider XOR and adder, then adders are a lot more 
complicated than AND

...and MazeGen - the thread you posted - at the very end I put some test results from 
a CLI/4Giga loops/STI test case.

Code:

times_4294967295:
XOR EAX,EAX ;111124clk 100.0% xor's got a very tricky logic
SUB EAX,EAX ;109257clk  98.3% carries make a long dependancy
MOV EAX,0   ;105052clk  94.5% too much memory overhead
AND EAX,0   ; 85680clk  77.1% and's got the sweetest logic 



I really hoped the XOR would be at least as fast as SUB, but wow...

Copyright © 2004-2010, Tomasz Grysztar.

自分も知識アップデートが必要だった○| ̄|_ > zero idiom

■_ History

こんなん見かけまして。

A History of Haskell

A History of Haskell: being lazy with class

"A History of Haskell: being lazy with class", Paul Hudak (Yale University),
John Hughes (Chalmers University), Simon Peyton Jones (Microsoft Research),
Philip Wadler (Edinburgh University), The Third ACM SIGPLAN History of Programming Languages
Conference (HOPL-III) San Diego, California, June 9-10, 2007.

Abstract This long (55-page) paper describes the history of Haskell, including its genesis
and principles, technical contributions, implementations and tools, and applications and
impact.

    * Paper: PDF (1Mbyte) and Postscript (8Mbyte)
    * Video of the talk (630Mbyte). The video starts a minute or so into the talk, but
      nothing important is missing.

You might also be interested in Simon's POPL'03 talk: A retrospective on Haskell. 

The Third ACM SIGPLAN History of Programming Languages Conference (HOPL-III) これの、IとIIはすべての講演(論文?)がまとめられた本が出ているんですが、 IIIは出ていないんですよね。 Haskellのこれみたいにぜんぶpdfなんかで公開されているんだろか。

うおっ、円高のせいか自分が買ったときよりすげー安い○| ̄|_
History of Programming Languages (Acm Monograph Series)
History of Programming Languages (Acm Monograph Series) History of Programming Languages, Volume 2 (ACM Press)

■_ PHP 5.3.7

まだ引っ張りますw

cryptがsaltしか返さないバグ・解説 | 水無月ばけらのえび日記

2011年8月24日(水曜日)
cryptがsaltしか返さないバグ・解説

(略)
興味深いのはこのあたり。

    The crypt change did trigger a test to fail, we just went a bit too fast with the 
    release and didn't notice the failure. This is mostly because we have too many test 
    failures which is primarily caused by us adding tests for bug reports before actually 
    fixing the bug.

以上、Rasmus Lerdorf - Google+ - If you are using crypt() in your code you might want 
to… より

テストに失敗していたのに、普段からテストが通らない状態だったから気にならなかったという
ことのようで。無視しても良い警告が常に出る状態になると、警告を無視する癖がついてしまっ
て警告が形骸化します。それが、今回のバグ版がリリースされてしまった要因の一つと言えるで
しょう。

コメントには続きがあり、

    I still like the practice of adding test cases for bugs and then working towards making
    the tests pass, however for some of these non-critical bugs that are taking a while to
    change we should probably switch them to XFAIL (expected fail) so they don't clutter up
    the test failure output and thus making it harder to spot new failures like this crypt
    one.

以上、Rasmus Lerdorf - Google+ - If you are using crypt() in your code you might want 
to… より

ということで、今後は予期された失敗を別のステータスにして区別するようですね。
PHP 5.3.7のcryptについて、作者のメモ @ val it: α → α = fun

PHP 5.3.7のcryptについて、作者のメモ
This entry was posted by Jun Mukai on Saturday, 27 August, 2011

(略)

コードカバレッジ、テストの失敗、valgrindのレポートなどをきちんととっている。だけど、テ
ストの失敗を調査せずにリリースをしてしまったというわけだ。やっていても見なければ意味が
ない、という残念な結果になっているが、どうしてそうなのかというのが面白い。つまり、バグ
レポートが上がってくると、その時点で(直す前にまず)テストケースを足していくという開発ス
タイルなのだと。したがってテストの失敗が無数にあるのが常態化していたというわけだ。

このスタイルを崩すつもりはないが、バグレポートによる失敗ケースは基本的に失敗するのが前
提なので、これをXFAIL(expected fail)なんかに変えることで、失敗することが期待される部分
と、本当のバグが分離できるだろうとのこと。

何が言いたいかというと、別にテストがされてないわけではないし、単にテストを無視してリリ
ースしたといった残念な話でもない。それなりの哲学を持った開発スタイルをしていたわけで、
ただこういう回帰バグをあんまり想定した作りになっていなかった。今後どうしたいかも一応視
野に入っている。といったあたりが興味深いなあと。


なーるほど(会社ではGoogle+がブロックされてて読めず、そのあとすっかり忘れてたので Rusmas の発言はきちんと追いかけていなかった)。 表面的な、目を引く部分だけにとらわれて disたりしてはいけないということですね。

■_

■_

2011年08月27日

■_

PyCon JP 2011
盛況だったようで。 興味はあったのですが、今ひとつ参加しようという気になれず。 その理由はまあ思いつかなくもないのですが書きません。 PyCon JP 2011 #pyconjp – Topsy Tweet Search

DOS辺りで苦労した人は nari3 さんにその話をガンガン聞かせましょう :) 『はじめて読む486』ではじめて理解するコンピュータ - I am Cruby!

買った
Founders at Work 33のスタートアップストーリー
来週辺りの発売かと思ったらすでに発売されていたという。 ということで早速買って、ブリックリンとウォズニアックのところだけ読んだ。 ブリックリンのところではセルの番地の振り方がなぜ A1 のような形式になったのかとか、 コマンド入力で / を使っていたのはなぜかということがわかったりして面白かった。 VBAでごにょごにょするときは正直言って R1C1 形式の方がいいと思うし、 なんで A1 形式なんてのがあるのかと疑問に感じていたのですがいやいやそういう理由であったとは! (と肝心なことを書かないでじらす :)。

しかしこうなると、新・電子立国でビジカルク開発のエピソードがあった回をもう一度観たいものだなあ
新・電子立国〈3〉世界を変えた実用ソフト (NHKスペシャル)
電子立国はDVDになったのに(あからさまなアサマシ)。 NHKスペシャル 電子立国 日本の自叙伝 DVD- BOX 全6枚セット
まあなんとなーくDVD化されない理由が思いつかないでもないけどねえ。

そのほか
コンピュータの発明
Founders at Work を買うときに目についてしまって買ってしまった(笑) 2003年の本なんですけど、ざっと見た感じとても面白そうだったので。 この本は知らなかったなあ。 この本の紹介リンク作るときにでてきたのもついでに貼っておこう シリコン・バレーの百年 [DVD] ディスカバリーチャンネル アップル再生: iPodの挑戦 [DVD]

そういえば、Founders at Workの翻訳本はアスキー(アスキーメディアワークス?)からの発売ですが、 なんで
Coders at Work プログラミングの技をめぐる探求
と違ったんですかね。

■_ PHP

5.3.7のバグ騒動を最初に知ったときには strcat を strlcat に置き換えたと勘違いしていたので なんじゃそりゃあと吃驚仰天したんですが、 実際には strcat → strncat → strlcat だったらしいですね。 であればまあわからないでもないのですが、 この一件だけに限らず、この種のミスを防ぐにはどうするのがいいのでしょう。 ユニットテストもまともにしていないから~ とか、そもそも C で書いているのが~ とか様々な意見を見かけましたけど、それで(それだけで)いいのかなあと 特に明確な根拠もなくぼんやり考えたりします。

そんな PHP に絡んだ別のお話。

Believe or not Believe : PHP

So i'm working with a couple new hire programmers. They claim to have worked with php for
12 years. They are just now learning to install wamp server on their local dev machine. The
site uses mod_rewrite. however they are having a ton of problems figuring out how to get
it to work on their local dev machine.

わたしは新規に雇われたふたりのプログラマーと仕事をしています。
彼らは PHP を使って12年働いてきたと主張しています。
今現在、彼らは自分たちのローカル開発マシンに wamp サーバーをインストールしています。
そのサイトでは mod_rewrite を使っているのですが、ローカル開発マシンできちんと
動作させるのに山ほど問題を抱えています。

So how does one work with php for 12 years, never install an apache service (on any 
platform), and never use mod_rewrite. We even have a web.config for IIS developers and 
they're like web.what?

PHP で12年働いてきている人間が、apache のサービスをインストールしたこともなければ
mod_rewrite を使ったこともないというのでしょうか。
わたしたちには IIS 開発者向けの web.config すらあるのに
彼らはいったいなんなのでしょうか?
#ちょっと最後あぶない

TL;DR .. new programer says been coding php for 12 years, they can't get their local 
dev environment to do any url rewrites. am i being lied to?


You should of tested them before you hired them. One company I applied for made me go 
through 4 rounds of testing. The companies with the shitty devs don't test the people 
they hire. Usually because the people hiring don't know code.

If you are a web developer you have configured an htaccess file at one point or 
another. You should of configured a local webserver. Especially if you have been doing 
it for 12 freaking years. Yes they are lying.


I completely agree. I test all hires with a few decent programming challenges which 
are usually concise but slightly complicated and I only let them use pen and paper (I 
ask for pseudo-code). If you can't rationalize an algorithm in your head or how you 
would go about it without sitting there and changing two characters at a time then 
re-testing I can't begin to imagine how long it would take somebody to write a full 
application.

In regards to .htaccess files.. I would say that somebody who has been a developer for 
12 years, would DEFINITELY have used an htaccess file at some point. Even if that 
means you were trying to do a joomla! or wordpress install and you started freaking 
out because whenever you navigated to your file it came up as something else. At the 
same time, just because he has known PHP for 12 years doesn't mean that he is avidly 
learning PHP and writing in it. He probably just dicks around from time to time.

Finally, I would definitely expect that they should know how to install an XAMP stack. 
There are tons of times where you need to install a 3rd party application (I just had 
to do this to combine PDF and FDF files) and you will need to understand things like 
chmod, chown, and how to access the application. This guy is full of shit.


Would you mind sharing a few of your programming challenges? I've been writing a 
little PHP since the beginning of the year and was just interested in what sort of 
puzzles you let your applicants solve in order to test them.


Ya sure, I'll sum up some of the stuff

PHP Questions

    * What is the difference between include and require?
      include と require との違いはなんですか?

    * What does something like this do:
      次のような操作で行っていることは何ですか?

      $a = "b"; $b = "c"; echo $$a;

    * What is the difference between single and double quotes? When should you use one
      over the other?
      シングルクォートとダブルクォートの違いとは?
      どちらかを優先して使うべきなのはどのようなとき?

    * What is the difference between print and echo?
      print と echo の違いとは?

    * Which is faster? echo 'hello' . 'world'; echo 'hello', 'world'; print 'hello' . 'world';
      どれが一番速い?

    * etc.

Algorithms

    * Write a function that returns the factorial of a number. (I describe a factorial as
      being 5 x 4 x 3 x 2 x 1 etc, factorial of 1 and 0 are 1) Without the use of loops. 
      (Meaning you need to write it recursively)

    * Write a function that takes in an array and outputs that array in reverse order WITHOUT
      the use of a second array. (Just one temporary variable as I explain that reversing a
      large array can take up a lot of memory if you create a whole new one)

SQL

    * I will typically ask them to join two tables and use an aggregate function such as SUM()
      to test that they know how to join tables, use aggregate functions, and know about the
      GROUP BY

Others

    * Sometimes I've asked people to write a basic CRUD interface that can add people's
      names, and then search for them (So I guess not all of CRUD). Hence why it is a good
      idea to have your localhost setup!!

    * We've also shown people a bug that we found in a wordpress template that one of our
      clients was using and asked them to debug it.

Most of this stuff isn't very complicated but I'll just watch how they do certain things
and ask them either why they did it or what they were thinking etc. so I can actually get
a grasp of how they work. Sometimes they get nervous and can't think and I help them along,
it's not to sit there and grill them.


I don't particularly like the second bullet for this reason: Having the right answer 
can be worse than them not knowing. Why? Because if I see someone use that in their 
codebase and it isn't absolutely required/documented I'll punch them in the throat.

No one gives a shit about the 4th bullet, and the 5th bullet doesn't matter (There are 
a billion more places to optimize than your damn echo statements)

For algorithms maybe the first one is useful, the second is checking to see if you 
have a CS degree not if you know what you're doing. The correct answer to the second 
algorithm bullet should be array_reverse(), if it's not they're doing it wrong.

SQL stuff, useful if they're going to be working with raw SQL, if not an appropriate 
question for your ORM/other abstraction layer

The first bullet in (Others) is the most important of the whole set, it shouldn't take 
a halfway competent developer more than maybe a half hour to setup the entire stack if 
you don't want anything fancy


A) LAMP != WAMP, so they might have used a GNU/Linux machine before. OK, but they haven't
   ever installed Apache?

B) PHP runs in environments that are not Apache. Any web server can run it, in theory. In
   fact, you can run it without a web server.

C) Many PHP devs probably FTP into a third-party hosting site and use their
   already-configured environment to build a site. That allows them to circumvent having 
   to install anything, so even if they haven't installed a web server, they might have 
   used one.

D) I've been using PHP for years, and have never used mod_rewrite. I've heard of it, but
   never used it. Then again, I wouldn't say I was a PHP developer.

Some companies have sys admins that handle server configuration issues, including 
Apache setup. In fact, some companies don't let programmers have a say in server 
configurations (web server and DB server).

■_

言語設計者のノート: 何よりもまず害をなさないこと に書かれていることについて、 みずしまさんやいなばさん、やのさんなどがいろいろついったで話していたみたいですが とぅぎゃったりするの面倒なのでぼつ。

■_ ソート

いや、その回答はどうなのよシリーズ。

数値を含む文字列の並び替えについて | OKWave

数値を含む文字列の並び替えについて

$xxxx[0]='なんとかかんとか'."\t".'なんとかかんとか'."\t".'12345'."\t".'なんとかかんとか';
$xxxx[1]='うんたらかんたら'."\t".'うんたらかんたら'."\t".'12346'."\t".'うんたらかんたら';
…
のように、数値がタブ区切りで中間に入った文字列が幾つかあります。
この文字列を数値の部分で比較し並び替えることは可能でしょうか?
数値の位置は固定、3番目です。

よろしくお願いします。
<?PHP
$x[0]="aaaa\tbbb\t130\tccc";
$x[1]="g\th\t2\tiiiiiiii";
$x[2]="jjjjjjj\tk\t14\tll";
$x[3]="ddd\tee\t1\tfffff";

usort($x,"mysort");
function mysort($a,$b){
$a_array=explode("\t",$a);
$b_array=explode("\t",$b);
if($a_array[2]==$b_array[2]) return 0;
return $a_array[2]>$b_array[2]?1:-1;
}

print_r($x);
?>

Copyright © OKWave. All rights reserved.

比較関数(なのに名前が mysort ってのも違和感あるけど)で 毎回毎回 explode しちゃあよろしくないと思うんですが もうそんなの気にしないでもいい時代なんですかねえ。

■_

■_

しまった。xor eax, eax ネタを書いている余裕がなくなってしまった。

2011年08月26日

■_

夕方の豪雨で一時間ほど足止め食らった。 というか自主的にそうしたんだけど。

・~ at Work
Founders は読まないでいいかなあと思っててスルーしてた(そして翻訳されるとは知らなかった) のですが、arton さんのところ (創立者は仕事する(創業者仕事中) - L'eclat des jours(2011-08-26)) に忘れがたいソフトウェア・アーツのダンブルックリンのも実に良い なんてあるのを見つけてこれは読まねばという気に。 どんな人かはこの辺参考 ダン・ブリックリン - Wikipedia

■_ 即

自分もまあ「即時」はなんか違うような気がするんですが、 2011-08-24 - このブログは証明できない。彼氏が(function(){...})()を即時関数って言ってた。別れたい。 知ってて当然?初級者のためのJavaScriptで使う即時関数(function(){...})()の全て - 三等兵

"immediate function" - Google 検索

Immediate Functions in JavaScript - The Basics | JavaScript Mountain

Functions are a very powerful feature in JavaScript; they provide modularity and scope. 
The immediate function is an often overlooked feature of JavaScript that offers a 
heightened level of functionality.

An immediate function is a function that executes as soon as it is defined. Creating 
an immediate function is simple: you add the open/close parentheses after the closing 
curly bracket, and then wrap the entire function in parentheses. That’s it!

↑に限らず、immediate function という使い方はそこそこあるようです。 そして、その immedeate function をどう訳すかですが

Wataru's memo
即値という命名が不幸を生んでいる

(略)

このように、命令語の直後の値を定数として扱うことを専門用語で "immediate addressing"
と言いますが、その定義を英語で表現した箇所を名著 "Digital Computer Electronics,
McGraw-Hill, 1993, 絶版" から引用します。

     Immediate addressing tells the microprocessor that the data it needs will be coming
      immediately after the op code.

明快に言い切られている通り、immediate とは、オペコード(正確には命令語)の直後に続いている
データのことなのです。日本語であれば、"後続値" と表現した方がより的確でしょう。
ところが、国語力のない誰かがこれを「即値」と訳出してしまった。この時点から、悲劇がはじま
ったと言って良いでしょう。続く著者達が、盲目的に即値を使ったものだから、悲劇は拡大生産さ
れ続けています。

「すなわちの値」こんなおかしな日本語はありません。技術用語で、意味不明瞭の日本語に出会っ
たならば、必ず英語表記に立ち戻らなければなりません。あやふやな言葉や文章の影には、必ず著
者の誤解や無理解が隠れています。大切なことは、日頃から自分の国語力を磨き、これを信じるこ
とです。たとえ相手が教科書やリファレンス書であっても、奴隷的態度は捨てなければな
りません。

さてどうしましょ。

■_ Compare-And-Set in Memcache

Guido パパが新しい記事書いてると気づいて見に行ったものの あまり自分の興味が向いている方面の記事ではなかった。

Neopythonic: Compare-And-Set in Memcache

With the most recent release (1.5.3, last week) App Engine's Python API for Memcache has
added a new feature, Compare-And-Set. This feature (with a different API) was already
available in Java; it has also been available in the non-App-Engine pure-Python memcache
client. In fact, I designed the App Engine Python API for this feature to be compatible
with the latter, since most of the rest of the App Engine Python API also strives to be at
least a superset of that package.

(以下略)

■_ xor

調べてみたら衝撃の事実が!(つづく)

melancholic afternoon ありがとうございます。 ここでも触れられていましたが、諸々含めて改めて。

■_

■_

C言語なら俺に聞け(入門編)Part 88 [chaika]

807 デフォルトの名無しさん [sage] 2011/08/26(金) 13:23:55.10 ID: Be:
    これいくらreの正規表現を変えてもbuf.re_nsubの値が0になるんですが
    何か間違えてるんでしょうか? (コンパイル&実行環境はubuntuです)



    #include <stdio.h>
    #include <string.h>
    #define __USE_GNU 1
    #include <regex.h>

    int main(int argc, char **arg)
    {
     const char re[] = "((a*)b)*"; 
     struct re_pattern_buffer buf;

     buf.translate = NULL;
     buf.fastmap = 0;
     buf.buffer = NULL;
     buf.allocated = 0;

     if ((re_compile_pattern(re, strlen(re), &buf))==0)
      printf("re_nsub -> %d\n", buf.re_nsub);
     regfree(&buf);

     return 0;
    } 

808 デフォルトの名無しさん [sage] 2011/08/26(金) 14:05:25.94 ID: Be:
    正規表現を格納するバッファにNULLを設定して、なにをどう評価しようってんだ? 

814 デフォルトの名無しさん [sage] 2011/08/26(金) 14:51:55.47 ID: Be:
    >>808
    re_compile_patternの資料が余りないので、古いtexinfoを読んでみると
    http://www.cs.utah.edu/dept/old/texinfo/regex/regex.html#SEC46

    buffer
    allocated
    If you want re_compile_pattern to allocate memory for the compiled pattern, set both of these to zero.
    If you have an existing block of memory (allocated with malloc) you want Regex to use, set buffer to its address and allocated to its size (in bytes).
    re_compile_pattern uses realloc to extend the space for the compiled pattern as necessary.

    re_compile_patternに勝手にメモリ割付けさせたいならこの両方の値に0を入れろという事なので0(NULL)を入れました。
    試しに

    buf.buffer = malloc(256);
    buf.allocated = 0;

    としても結果は同じでした。 

815 814 [sage] 2011/08/26(金) 14:53:37.60 ID: Be:
    >>814
    済みません間違えました

    buf.allocated = 0;

    じゃなくて

    buf.allocated = 256;

    です 


807 のプログラム、正規表現の syntax を設定してないんだけど そうすると Emacs の syntax が採用されることになるんじゃなかったかなあ。 であれば、capture のためのカッコは \( \) だから、( ) では期待通りにはならんような。

Regex

Regular expressions match according to the syntax with which they were compiled; with 
GNU, you indicate what syntax you want by setting the variable re_syntax_options 
(declared in `regex.h' and defined in `regex.c') before calling the compiling function, 
re_compile_pattern (see below). See section Syntax Bits, and section Predefined Syntaxes. 

自分で貼ってるリンクの辺りにこういう記述あるんだけど見落としてんのかな。

2011年08月25日

■_

Rasmus Lerdorf - Google+ - If you are using crypt() in your code you might want to…

■_ Why Rakudo needs NQP

Perl 6のおはなし。

blog | Perlgeek.de :: Why Rakudo needs NQP

Wed, 24 Aug 2011

Why Rakudo needs NQP (なぜRakudoはNQPが必要なのか)


Rakudo, a popular Perl 6 compiler, is built on top of a smaller compiler called "NQP",
short for Not Quite Perl.

Reading through a recent ramble by chromatic, I felt like he said "Rakudo needs NQP to
be able to ditch Parrot, once NQP runs on a different platform" (NQP is the "another
layer", which sits between Rakudo and Parrot, mentioned in the next-to-final paragraph).

I'm sure chromatic knows that VM independence is the least important reason for having 
NQP at all, but the casual reader might not, so let me explain the real importance of 
NQP for Rakudo here.

わたしは chromatic が VM independende といったものが NQP を持つことの
least important reason であることを理解しているであろうと確認しています。
けれども casual reader はおそらくそうでないでしょうから、NQP for Rakudo の
本当の重要性といったものをここで説明することにしました。

The short version is just a single word: bootstrapping.
短い回答はただ一言: ブートストラップ です。

The longer version is that large parts of Rakudo are written in Perl 6 itself (or a 
subset thereof), and something is needed to break the circularity.

長い回答は、Rakudo の大部分が Perl 6 自身(もしくはそのサブセット)で記述されている
ので、その circularity を破るための何かが必要となるということです。

以下略

■_

書いた人の名前が気になったのと、CPLというのがみえたので

Prescient but Not Perfect: A Look Back at a 1966 Scientific American Article on Systems Analysis | @ScientificAmerican, Scientific American Blog Network

(さくっと略)
How much better would the world be today if everyone had adopted Strachey's approach 45 years ago?

    * Good: At a time when most programmers were using Assembler, when the first computer
      languages (LISP, FORTRAN and COBOL) were only about eight years old, Strachey chose
      to use a very high-level programming language,  CPL . CPL is surprisingly and
      refreshingly modern, reminiscent of popular languages today such as Python or Ruby.

    * Bad: CPL was so new that it had no compiler, nor a complete formal description. 
      Journal articles from 1963 and 1968 and a posthumously published set of notes from 
      2000 partially describe versions of the language that are slightly different than the 
      one presented in the article. I did my best to approximate what the CPL language is, 
      and wrote a translator for it (see below) that we can use to test and debug Strachey's 
      program.

(略)

A Translator for CPL

Strachey didn't have a CPL compiler when he wrote the article in 1966. The first CPL 
compiler emerged around 1970, and by the 1980s they were gone. So I had to create my 
own before I could run and debug the checkers program. I had three choices to make: (1) 
What CPL syntax is legal and what does it mean? (2) What parser-generator system 
should I use to create the CPL translator? (3) What language should I translate into? 
A full compiler—a translator into machine language—is a rather complex project, but 
translating into a high-level language that is very similar to CPL is much easier.

(略)
© 2011 Scientific American, a Division of Nature America, Inc. All Rights Reserved.

■_ strikes back

なんか「俺が訳す」という人を複数人見かけたので適当に流しつつ

Hail the return of native code and the resurgence of C++

Published on InfoWorld (http://www.infoworld.com)

Hail the return of native code and the resurgence of C++
By Neil McAllister
Created 2011-08-18 03:00AM

Programming language trends come and go. First, Java is the hot new language, then it's
Python [1], then Ruby steals the limelight, then it's back to JavaScript [2]. But the latest
language darling is probably the last one anyone expected. Believe it or not, 2011 could be
the year of C++.

プログラミング言語の流行というものは移り変わります。
初めは Java がホットな新言語でした。続いて Python、それから Ruby が注目の的となりました。
その後は JavaScript がそうなりましたが、latest language darling はみなが期待していたもの
ではないでしょう。信じようと信じまいと、2011年は C++ の年となりうるのです。


Last week, the latest version of the ISO C++ Standard was approved by unanimous vote [3].
It's the first major revision of the language in 13 years. Now officially known as C++11,
the new standard introduces features designed to make it easier to develop software for
modern parallel processing architectures, including lambda expressions and new data types
for concurrent computing.

先週、ISO C++ standard の最新バージョンが満場一致の投票を持って認可されました。
これはこの言語の最近13年間における最初の major revision です。
現在これは C++11として公式に認識されるようになり、
新標準では lambda expression や concurrent computing 向けの新しいデータ型を含む
modern parallel processing architectures のためのソフトウェアの開発を容易にするように
設計された機能を導入しています。

[ Get software development news and insights from InfoWorld's Developer World newsletter [4].
| And sharpen your Java skills with the JavaWorld Enterprise Java newsletter [5]. ]

Not that C++ really ever went away. With its older cousin C, it remains one of the most
popular languages for systems programming and for applications that call for
performance-intensive native code, such as 3D game engines.

C++ は

Outside its specialized niches, however, traditional systems programming itself has fallen
out of favor in recent years. Modern programmers have increasingly turned away from native
compilation in favor of managed-code environments such as Java and .Net, which shield them
from some of the drudgery of memory management and input validation. Others are willing to
sacrifice some performance for the syntactic comforts of dynamic languages such as Python,
Ruby, and JavaScript.

But C++11 arrives at an interesting time. There's a growing sentiment that the pendulum may
have swung too far away from native code, and it might be time for it to swing back in the
other direction. Thus, C++ may have found itself some unlikely allies.

(略)

■_

■_

2011年08月24日

■_

大東京トイボックス 7
大東京トイボックス (7) (バーズコミックス) 買った。読んだ。

・日経ソフトウエア
久しぶりに重箱の隅をつついてみた 日経ソフトウエア 2011年 10月号 [雑誌]

■_ PHP 5.3.7

5.3.7 は幻のバージョンになってしまったとか。

それはそれとして 徳丸浩の日記: PHP5.3.7のcrypt関数のバグはこうして生まれた に事情が良くまとめられていると思います。

で、スラッシュドット。 strncat の罠ってのは妥当な表現なんだろうか。

PHP 5.3.7に重大なバグ、strncatの罠にはまる - スラッシュドット・ジャパン

      make testですぐ引っかかる代物をリリースしたことが大問題ですよ。
      恐るべき事に、PHPというソフトは単体テストすら回さずにリリースが行われているということですよね?
      信じられないし、まともな神経を持った開発者ならあり得ない暴挙です。責任者が誰か知りませんが、ソフトをリリースする資格ないですよ。
      PHPは好きでも嫌いでもなかったんですが、こんな連中が作ってる代物だと知れた以上は、今後は出来る限り使用を避けようと思います。
      周りを説得する強力な材料にもなりましたし。
      ここまで誰も話題にしないMicrosoftのCRT 関数のセキュリティが強化されたバージョン [microsoft.com]の
      strcat_s。strlcatと違って黙って切り捨てることはない(そういう場合、デフォルトでは即座にプロセスご
      と死ぬ)ので、こっちだったら良かったのかなと思う。まだMSのコンパイラくらいでしか使えないけど。

      これベースにISO/IEC TR 24731(参考:STR07-C. TR 24731 を使用し、文字列操作を行う既存のコードの脅威
      を緩和する [jpcert.or.jp])なんてのも出ているので、C1X(C99の次)あたりに搭載されないか?

      直前で strlcpy を使ってるんだから、strlcat すればいいのに。
      ちょっと前を見れば static char passwd[MD5_HASH_MAX_LEN] ってあるように
      サイズもわかってるんだから。
            違うよ。strncatに書き換えた時点では問題なかった。その後で [php.net]さらにstrlcatに書き換えたのに、第3引数をそのままにしてたからバグったの。
            参考: PHP5.3.7のcrypt関数のバグはこうして生まれた [tokumaru.org]


      まあ仰ることも間違いではないのですが、C言語界の背景というか
      strncatのsize指定が「意外性最小原則にそぐわない」仕様だということで
      数々のバグの発生源となっており、散々非難されてきた、という今までの経緯があるのです。

      で、srtncat使用者はそこを注意して使用してたけど、後からそれをstrlcatに置き換えた人は
      そんな罠があったと知らず、何も考えずそのまま関数だけ置き換えてしまったと。

      ある意味、strncatというのは関数自体がバッドノウハウ的な存在なのですね。
      まさにバッドノウハウ的対応が、たとえその場は良くても将来に問題を引き起こすという好例となってしまったということでしょう。

strncat(strncpy) と strlcpy(strlcat) の引数の並びは一見同じものが並んでいるようで 実は意味が違う(から混乱を招いてよくない)という指摘は twitter でも見かけました。 strncpy/strncat はその存在を忘れてしまっていいんじゃないかと思うのですが、 引数の並び方を変えるといってもそれほどバリエーション作れないですしねえ>strl* 長さを第一引数にするのがわかりやすかった?

ところで reddit に寄せられたコメントからひとつ。

Serious Crypto Bug Found in PHP 5.3.7 : programming

I don't think it was a problem. Real PHP programmers don't use crypt() anyway.

さてこれはどのように解釈するべきものなのかw

で、まあ strl* でなんか書こうと思ったけど時間がなっしんぐ。 ネタ元のリンクを貼ってお茶を濁す。

■_ 今日の重箱の隅

日経ソフトウエア 2011年 10月号 [雑誌] に掲載の連載記事から。

わかってうれC~コンピュータの仕組み
第4回
C言語のfor文をアセンブラで記述するとどうなるか?

今回のテーマは、C言語のソースコードの中にアセンブラの命令を記述する
インラインアセンブラです。アセンブラは、マシン語と1対1に対応する
プログラミング言語です。従って、アセンブラでプログラムを記述すれば、
CPUが解釈しているレベルでの生々しいプログラムの姿を見ることができます。
それでは、インラインアセンブラを使って、アセンブラを体験してみましょう。

アセンブラの文法は give me money と同様である

アセンブラを初体験する人のために、アセンブラの文法を説明しておきましょう。
アセンブラの文法は、とても簡単です。プログラミングで使われる構文は、
基本的に一つだけしかありません。「動詞 目的語」という構文で、
「~せよ …を」という命令を表します。これは英語の命令文の構文と同様です。
アセンブラでは、動詞の部分を「オペコード」、目的語の部分を「オペランド」
と呼びます。

英語の命令文では、目的語がない場合、1個の場合、2個の場合があります。
例えば、stop なら目的語なし、help me なら目的語が1個、
give me money なら目的語が2個です。
目的語が2個ある場合は、後ろから前に作用します。give me money では、
後ろにあるmoney が前にあるme に give されます。これらの英語の文法は、
アセンブラでも同様です。

(略)

xor eax,eaxという処理でレジスタの値をゼロクリアするのは、アセンブラの
定番テクニックです。あらかじめeaxにどんな値が格納されていても、
同じ値でXOR演算を行えば、演算結果はゼロになります。
xor eax,eaxは、mov eax, 0 より処理が速いので、
アセンブラを知っているプログラマは、当たり前のように使います。

  

覚えているところでは、第一回で使っているコンパイラを明確にしていた (たしか VC6だったような)し、それに沿っているということでは間違いでは ないのでしょうけれど、AT&T形式のアセンブラは無視なんですかね。 op src, dst なアセンブリ言語も結構あると思うんですけど。

もうひとつの xor eax, eax の方。 これはレジスターの内容を使って演算してその結果を書き戻すということをするので、 ある時期から最速ではなくなったと聞いた覚えがあるんですよね。 無用に古びたテクニックを(誤解を招く形で)書いてるだけじゃないんでしょうか。 この種のことは、今までも時折見かけたと思います。

Michael Abrash - Wikipedia, the free encyclopedia

Another lesson Abrash offered was how hard-earned performance rewards by such micro 
optimizations could disappear or even make the program execute slower. Abrash was able 
to gain performance by carefully counting clock cycles of each instruction and 
ordering instructions in such a way that they used a minimal number of clock cycles. 
However, the number of clock cycles per instruction changed with new implementations 
of the x86 architecture and, as a result, his performance gains were lost from one 
generation to the next. For example, the bit-oriented "XOR EAX, EAX" 
(example in Intel assembler syntax) instruction was the fastest way to set a register 
to zero in the early generations of the x86, but most code is generated by compilers 
and compilers rarely generated XOR instructions, so the IA designers decided to move 
the frequently occurring compiler generated instructions up to the front of the 
combinational decode logic, making the literal "MOV EAX, 0" instruction 
execute faster than the XOR instruction. Still, carefully hand optimized assembler 
code will in general perform well on later x86 processors, even without retuning for 
the new architecture. The reason is that the optimization policies change only 
gradually between the architectures, so that many optimization assumptions valid for 
the original architecture still hold on the new architectures, for example 
"integer arithmetic is significant faster than floating point arithmetic" or 
"minimize memory accesses for maximum register usage".

たとえば上の文にも、"XOR EAX, EAX" は最速「だった」 (instruction was the fastest way) と過去形にしていますし、 making the literal "MOV EAX, 0" instruction execute faster than the XOR instruction. とあります。

この辺の話はもっと詳しい方がいると思いますし (herumiさんとか?)、 深入りはせずに逃げますw

来月は(Cコンパイラーの)最適化についての解説だそうですが、 またなんかありそうな予感。

■_ 今日の言語

なんとなく目に付いたので。

DM's Esoteric Programming Languages - Whenever

Whenever is a programming language which has no sense of urgency. It does things 
whenever it feels like it, not in any sequence specified by the programmer.

Design Principles

   Program code lines will always be executed, eventually (unless we decide we don't want
   them to be), but the order in which they are executed need not bear any resemblance to
   the order in which they are specified.

   Variables? We don't even have flow control, we don't need no steenking variables!

   Data structures? You have got to be kidding.

■_

■_

本来の勤務開始時間より早くに仕事をするってのは、 残業と一緒で「時間外労働」のはずだよねえ。 それに何の手当てもなしってのなら、サービス残業ならぬサービス早出?

2011年08月23日

■_

この1年の優れたIT系書籍はどれか?「Jolt Awards 2011」が6冊を発表。 - Publickey これ、翻訳ものでない日本で発売されたものから選ぶとしたらどんな感じになるでしょうね。 などと思ったり。

PHP 5.3.7 の例のバグ、該当部分のコードを見てなんというか絶句してしまった。

■_

■_ 改行位置

これに対処するためのコードを読んでみると、その大変さが伺える…かもしれない。

Ruby 初心者スレッド Part 45 [chaika]

282 デフォルトの名無しさん [sage] 2011/08/23(火) 18:30:39.59 ID: Be:
    マニュアルには『改行は行が明らかに次の行に継続する時だけ、空白文字として、
    それ以外では文の区切りとして解釈されます。』と書いてあるけど、
    foo + bar は+の前で改行するとNGで foo.each{…} は.の前後どちらでもOKなのはなんで?

283 デフォルトの名無しさん [sage] 2011/08/23(火) 19:00:38.89 ID: Be:
    >>282
    +の前で改行した場合は、単項演算子(+bar)として解釈されるってことじゃないの 

284 デフォルトの名無しさん [sage] 2011/08/23(火) 19:14:07.84 ID: Be:
    >>282
    「記号の前の改行は文区切り、記号の後の改行は空白文字」
    を原則にしてくだされ

    つまり、改行するなら記号のあと 

285 デフォルトの名無しさん [sage] 2011/08/23(火) 19:19:56.51 ID: Be:
    >>282
    行頭の.eachは1.8では通らなかったが、通るようになった
    行頭の + bar は >>283 の通り単項と見分けがつかない

    foo
    + bar

    は「fooを呼び出し、barの正負をそのままに戻り値とする」と読めてしまうよ 

286 デフォルトの名無しさん [sage] 2011/08/23(火) 20:43:54.39 ID: Be:
    それって.だけ特別扱いなのか?
    行頭が2項演算子としか解釈できないものならいけるかと思ったけど
    2
    ** 3
    はダメだった 

287 デフォルトの名無しさん [sage] 2011/08/23(火) 20:50:30.01 ID: Be:
    「記号の前の改行は文区切り、記号の後の改行は空白文字」
    を原則にしてくだされ

    つまり、改行するなら記号のあと 

288 デフォルトの名無しさん [sage] 2011/08/23(火) 20:52:09.69 ID: Be:
    だから>>284だって 

289 デフォルトの名無しさん [sage] 2011/08/23(火) 20:55:45.35 ID: Be:
    それはいいんだけど、.はなんで前でもOKなのか、
    前でいけるのが他にもあるのかが知りたいんです 

290 デフォルトの名無しさん [sage] 2011/08/23(火) 21:00:06.65 ID: Be:
    .も記号なのに前で改行できるって面白いな
    .は演算子じゃないから+とかとは別なのかな 

291 デフォルトの名無しさん [sage] 2011/08/23(火) 21:02:16.51 ID: Be:
    >>289
    ドットは後で変更されたワケだから、どっかに理由載ってるかもね 

292 デフォルトの名無しさん [sage] 2011/08/23(火) 21:04:49.78 ID: Be:
    おまいら - のことを忘れてないか 

293 デフォルトの名無しさん [sage] 2011/08/23(火) 21:12:45.88 ID: Be:
    >>289
    ドットと条件演算子は1.9で挙動が変更された

    あと、記号の前で改行「してはいけない」 

294 デフォルトの名無しさん [sage] 2011/08/23(火) 22:34:03.31 ID: Be:
    .は特別なのね
    皆の衆サンクス 

295 デフォルトの名無しさん [sage] 2011/08/23(火) 23:36:56.13 ID: Be:
    長いメソッドチェーンを複数行で書きたいからとか?
    . の前で改行できると メソッドチェーンが続いてることがわかりやすいだろうし 

■_ 良いコードを書くためには

To write good code, you sometimes have to write bad code | Lea Verou

To write good code, you sometimes have to write bad code

Posted on August 20, 2011 by Lea Verou	

And I'm not referring to learning.

For example, yesterday I was trying to write code for something and it ended up beng 
harder than I expected. It's one of those rare cases where you can fully imagine how 
the solution should work, enough to tell it to another person, but you can't put your 
thoughts to code and you feel you're not smart enough.

たとえば昨日わたしはちょっとしたコードを書こうとしたのですが、結局のところそれは
予想してたよりも難しいものでした。それはうまくいくであろうと考えた解決案が
うまくいかなかったレアケースのひとつであり、考えをほかの人に説明はできるのだけど
それをコードに落とすことができずに自分の能力が足りないと感じるようなものです。


I find that in those cases, it helps a lot to open a new editor window and try to 
write code that just works. Without being elegant, fast or maintainable. Just 
something that works properly. And after you manage to put your thoughts into (bad) 
code, it's easy to refine it from there and end up with good code.

そういったケースにであったとき、エディターで新しいウィンドウを開いて
エレガントではなく、高速でも保守性に優れてもいない
とにかく動くコードを書こうとすることが大いに助けになります。
とにかく適切に仕事を行うものです。
そして、自分の考えをそのような(悪い)コードに落とし込んだあとであれば
そこからリファインして最終的に良いコードにしていくことは容易なことです。

Just don't stop at the bad code, like many beginners do. It's like when designers 
sketch a rough draft for a logo, before drawing the digital version. Could you imagine 
how horrible it would be if they wanted to stop there and give the rough sketches to 
the client instead? :)

多くの初心者がそうなのですが、できの悪いコードで止まってはいけません。
そのコードは、デザイナーが本番の前に描くラフなスケッチのようなものなのです。
デザイナーがそういったラフ画で止めてしまってそれをクライアントに提出したいと
言い出した状況がどれほど恐ろしいものなのか想像できますか?
#ちょーやくモード


■_ Perl 5の正規表現

ruby-dev でやりとりで知ったのですが、Perl 5の正規表現もさらに手が入っているのですね。 a 修飾子とか u修飾子とか知らなかった。

perlre - Perl 正規表現 【perldoc.jp】 にあるのは 5.10 のかあ。

delta にちょっと記載があったのでそっちから。

perldelta - perl v5.14.0 での変更点 【perldoc.jp】
正規表現¶

(?^...) construct signifies default modifiers¶

((?^...) 構造はデフォルト修飾子を示します)

An ASCII caret "^" immediately following a "(?" in a regular 
expression now means that the subexpression does not inherit surrounding modifiers 
such as /i, but reverts to the Perl defaults. Any modifiers following the caret 
override the defaults.

正規表現中、ASCII キャレット "^" の直後に "(?" があると、 (/i のよ
うな)それを囲む修飾子を継承せず、 Perl のデフォルトに戻ることを意味するようになりまし
た。 キャレットに引き続く任意の修飾子はデフォルトを上書きします。

Stringification of regular expressions now uses this notation. For example, qr/hlagh/i 
would previously be stringified as (?i-xsm:hlagh), but now it's stringified as (?^i:hlagh).

正規表現の文字列化はこの記法を使うようになりました。 例えば、以前は qr/hlagh/i は 
(?i-xsm:hlagh) に 文字列化されていましたが、(?^i:hlagh) に文字列化されるようになります。

The main purpose of this change is to allow tests that rely on the stringification not 
to have to change whenever new modifiers are added. See "Extended Patterns" 
in perlre.

この変更の主な目的は、新しい修飾子が追加されたときに変更する必要の ない 文字列化に依存
したテストが行えるようにすることです。 "Extended Patterns" in perlre を参照
してください。

This change is likely to break code that compares stringified regular expressions with 
fixed strings containing ?-xism.

この変更は、文字列化された正規表現を ?-xism を含む固定文字列と 比較しているコードを壊
しそうです。

/d, /l, /u, and /a modifiers¶

(/d, /l, /u, /a 修飾子)

Four new regular expression modifiers have been added. These are mutually exclusive: 
one only can be turned on at a time.

四つの新しい正規表現修飾子が追加されました。 これらは互いに排他です: 同時には一つだけ
をオンにできます。

    *  The /l modifier says to compile the regular expression as if it were in the scope
       of use locale, even if it is not.

      /l 修飾子は、use locale スコープ内でない場合でも use locale スコープ内であるかのよう
      に正規表現をコンパイルします。

    *  The /u modifier says to compile the regular expression as if it were in the scope
       of a use feature 'unicode_strings' pragma.

      /u 修飾子は、use feature 'unicode_strings' プラグマのスコープ内に あるかのように
      正規表現をコンパイルします。

    * The /d (default) modifier is used to override any use locale and use feature 
      'unicode_strings' pragmas in effect at the time of compiling the regular expression.

      (デフォルトの) /d 修飾子は、正規表現のコンパイル時に効果のある 全ての use locale 
      プラグマと use feature 'unicode_strings' プラグマを 上書きするために使われます。

    * The /a regular expression modifier restricts \s, \d and \w and the POSIX ([[:posix:]])
      character classes to the ASCII range. Their complements and \b and \B are
      correspondingly affected. Otherwise, /a behaves like the /u modifier, in that
      case-insensitive matching uses Unicode semantics.

      /a 正規表現修飾子は \s, \d, \w および POSIX ([[:posix:]]) 文字クラスを ASCII の範囲に
      制限します。 それぞれの逆の効果を持つものと、\b および \B も同様に影響します。 その他
      では、/a は /u 修飾子と同様に振る舞うので、大文字小文字を 無視するマッチングは 
      Unicode の意味論を使います。

      If the /a modifier is repeated, then additionally in case-insensitive matching, no
      ASCII character can match a non-ASCII character. For example,

      /a 修飾子が繰り返されると、さらに、大文字小文字を無視するマッチングでは ASCII 文字で
      ないものはマッチングしません。 例えば、

          "k"     =~ /\N{KELVIN SIGN}/ai
          "\xDF" =~ /ss/ai

      match but

      はマッチングしますが

          "k"    =~ /\N{KELVIN SIGN}/aai
          "\xDF" =~ /ss/aai

      do not match.

      はマッチングしません。

See "Modifiers" in perlre for more detail.

さらなる詳細については "Modifiers" in perlre を参照してください。

非破壊的置換¶

The substitution (s///) and transliteration (y///) operators now support an /r option 
that copies the input variable, carries out the substitution on the copy, and returns 
the result. The original remains unmodified.

置換 (s///) と変換 (y///) 演算子は、入力変数をコピーしてから 置換を行い、結果を返す /r 
オプションに対応しました。 元データは変更されないままです。

  my $old = "cat";
  my $new = $old =~ s/cat/dog/r;
  # $old is "cat" and $new is "dog"

This is particularly useful with map. See perlop for more examples.

これは特に map で有用です。 さらなる例については perlop を参照してください。

(略)

あー /r はどこかで解説を読んだ覚えがあるなあ。

■_

Goodbye, shitty Car extends Vehicle object-orientation tutorial http://lists.canonical.org/pipermail/kragen-tol/2011-August/000937.html

2011年08月22日

■_

今朝は微妙に行きの電車での人口密度がいつもより高めだった (楽に座れるレベルではあったけど)。 なんでだろ。

■_ 読んでみた

Javaの前置インクリメントと後置インクリメントの内部実装を読みたい - 虎塚

Java

id:E_Mattsanさんからコメントで教えていただいたページが面白いです。

    * More Effective C++ 第6回 http://blog.livedoor.jp/exiashio/archives/2514235.html

C++の前置インクリメントと後置インクリメントの内部実装について書かれています。元ネタは、
『新訂版 More Effective C++』という本のようです。

前置と後置の振る舞いを同じにするために、内部的には後置の実装に前置を使っている、という
話が、興味深いと思いました。

で、Javaだとどうなのかが気になり、確認しようとしたところ、行き詰まってしまいました。

分からないこと

どのコードを読めばよいかが分かりません。標準APIの実装なのか? JVMのコードなのか?

そもそも「++」とか「+=」とかグレッパビリティ(grepの有効性。造語)が低すぎてキツイ。

一応、JVMにIINC.javaがありましたが、読むべきはこれではない気がします。

だって、インクリメント演算の機構が、こんな外出しのツールっぽい場所に書いてあるわけない…ヨネ?

    * jdk-6u23-jrl/j2se/src/share/classes/com/sun/org/apache/bcel/internal/generic/IINC.java

コンパイラの字句解析で「++」を判別してる場所を見つければよいのかもしれませんが、それどこコード? どこコードよーー

(略)


Egtra 2011/08/22 00:40 C++のあれは、クラスで演算子の多重定義をした場合の話です。それ以外
(intなど組込型)の場合、インクリメントにあたる命令を出力する位置を変える程度で済みます。
Javaの場合もそれと同じで、前置でも後置でもiincという同じ命令を使っているだけで、どっちで
どっちを実装しているとも言わないと理解するべきではないでしょうか。

torazuka 2011/08/22 04:19 ありがとうございます。元記事の前提を誤解していました。おっしゃる
とおり、iincの出現箇所が違うだけのようですね。

まあ、コメントの通りなんですが折角なので :)

実際に pre-increment/post-increment のコード(の元)を作ってるのはここですね。 わたしが見たのはディレクトリ名を見ればわかるように openjdk ですが 大体こんな感じになるはず。

openjdk6/langtools/src/share/classess/com/sun/tools/javac/jvm/Gen.java

   public void visitUnary(JCUnary tree) {
       OperatorSymbol operator = (OperatorSymbol)tree.operator;
       if (tree.getTag() == JCTree.NOT) {
           CondItem od = genCond(tree.arg, false);
           result = od.negate();
       } else {
           Item od = genExpr(tree.arg, operator.type.getParameterTypes().head);
           switch (tree.getTag()) {
(略)
           case JCTree.PREINC: case JCTree.PREDEC:
               od.duplicate();
               if (od instanceof LocalItem &&
                   (operator.opcode == iadd || operator.opcode == isub)) {
                   ((LocalItem)od).incr(tree.getTag() == JCTree.PREINC ? 1 : -1);
                   result = od;
               } else {
                   od.load();
                   code.emitop0(one(od.typecode));
                   code.emitop0(operator.opcode);
                   // Perform narrowing primitive conversion if byte,
                   // char, or short.  Fix for 4304655.
                   if (od.typecode != INTcode &&
                       Code.truncate(od.typecode) == INTcode)
                     code.emitop0(int2byte + od.typecode - BYTEcode);
                   result = items.makeAssignItem(od);
               }
               break;
           case JCTree.POSTINC: case JCTree.POSTDEC:
               od.duplicate();
               if (od instanceof LocalItem &&
                   (operator.opcode == iadd || operator.opcode == isub)) {
                   Item res = od.load();
                   ((LocalItem)od).incr(tree.getTag() == JCTree.POSTINC ? 1 : -1);
                   result = res;
               } else {
                   Item res = od.load();
                   od.stash(od.typecode);
                   code.emitop0(one(od.typecode));
                   code.emitop0(operator.opcode);
                   // Perform narrowing primitive conversion if byte,
                   // char, or short.  Fix for 4304655.
                   if (od.typecode != INTcode &&
                       Code.truncate(od.typecode) == INTcode)
                     code.emitop0(int2byte + od.typecode - BYTEcode);
                   od.store();
                   result = res;
               }
               break;
(略)
           }
       }
   }

Lexer.java とか Scanner.java というファイルがあると思うので そこを足がかりにすれば、++ に PLUSPLUS のような名前がつけられているのが わかると思います。 あとはそれで g(ry

visitor パターンが使われてて感心したっす。

■_ ハードル?

松江市が中学生にRuby教室開催、まつもと氏も来場 - ニュース:ITpro

 参加した中学生はプログラムの基礎について学んだ後、Rubyと、ゲーム用拡張ライブラリであ
るDXRubyで記述されたデジタル時計、スロットなどのプログラムを打ち込み、自分好みに改造す
る半日のカリキュラムに取り組んだ。

まつもとさんが twitter で発言されてたのですが、 プログラムに間違いがあったときに出てくるメッセージが英語なのがちょっと大変だったとか。

そういうのってどう解決するのがいいのでしょうね。 小学校から英語をやれば?(笑) というのはおいといて、メッセージカタログを作って多言語化というのも 仕掛けとしてはありとしても手間が増えますし。

… Scratch とかどうなってんでしょ?

■_ LL

街で見かけた感想から。

LL Planets - sodiumイオンにっき(2011-08-20)

毎年恒例のLLイベント。今回はJavascript分多めでお送りされました。

毎年、ここで各セッションのハイライトを書いてたんだけど、なんかしんどいので今年は多分書
かない。twitterとかでいろいろ出てたしもういいかな、ということで。

malaさんの基調講演はよかったなあ。

そうなんですよねえ。twitter でリアルタイムに流れてたりすると、 あとでまとめてという気がかなり失せるんですよね (これは RubyKaigi なんかでも同じ)。 自分がその場で twitter で何か言う言わないに関係なく、 もういいやという心境になるというか。

■_

■_

2011年08月21日

■_

実はLL Planets の会場でオライリーの本は(ノベルティの誘惑にも負けず) 買わなかったのだけど(本当のところは2冊買おうかというのがあったけど 欲しいノベルティに必要な金額に届かなかったw)、 別の本を二冊買っていた。 結構面白かったので明日にでも紹介してみよう。

最近、 煬帝(下) 煬帝(上)
を読んだのだけど、俄かにこの辺りの時代が気になっていろいろ調べてみたら
隋唐演義〈1〉群雄雌伏ノ巻 (中公文庫)
というのがあった。 面白そう。ではあるのだけど、この本文庫になる前に買って読んでいたような気もするんだよなあw

お、これも文庫になってたのか(って結構前じゃん…)
中国武将列伝〈上〉 (中公文庫) 中国武将列伝〈下〉 (中公文庫)

おっとこれは
天竺熱風録 (祥伝社文庫)
これもハードカバーで出ていたのが文庫でということのようだけど、 こっちはハードカバーで読んだ覚えがないなあ。多分未読だろう。買っとこうw

■_ Letter to a Young Developer

Letter to a Young Developer | Virtuous Code
Letter to a Young Developer

2011 August 19

by avdi

I've been getting some emails from young developers wanting to “level up” as programmers.
I'm definitely not the first to write about this topic, so I'm not sure how much I have to
add. Still, for what it's worth here are a few points off the top of my head:

    * Work with other developers. We are at a wonderful time in the history of technology
      when for the first time, it doesn't really matter where you are or who you are working
      for. So long as you have a decent internet connection, you can pair up with another
      developer anywhere in the world and work on some code together. More and more
      experienced developers I know are offering their time for this kind of knowledge 
      sharing. My friend Evan Light holds open office hours, and is developing a site to 
      help Rubyists  pair up. I've been doing this for a while as well. Want to work on some 
      FLOSS code? Email me and we'll set something up.

      ほかの開発者と一緒に働こう。

    * Read the classics. Code Complete, The Pragmatic Programmer, The Practice of Programming,
      Design Patterns. Etc.

      classics (古典)を読もう。


    * Read WikiWiki (sometimes known as WardsWiki). I can't stress this enough. Sometimes I
      think I learned everything I really needed to know about programming  from surfing
      WikiWiki on slow days.

    * Read other people's code. Hooray for GitHub! If you want to start with a more curated
      collection and you know some Ruby, try Best of Ruby Quiz.

      ほかの人たちのコードを読もう。


    * Get involved in your local user's groups. If they don't exist, start one. And submit
      talks. I don't care how much of a n00b you think you are. There is nothing better than
      committing to a talk to force you to to learn all about a topic.

      自分のいる地域のユーザーグループに参加しよう。もしないのなら、立ち上げてみよう。
      そして

    * Write a blog. Don't worry about being original. Some of the most useful blogs out
      there are a largely a chronicle of a programmer's experiments and mistakes, and how
      they overcame problems. Reflection is one of the most important parts of learning, 
      and writing helps you reflect. And sooner than you think you'll be getting feedback 
      from other programmers.

      blog を書こう。original であることに思い煩わないように
      #Don't worry ~のニュアンスが今ひとつわからん
      とても有用な blog の一部は、一プログラマーの経験したことやミスしたこと、そして
      問題をどのように乗り越えたかということのクロニクルだったりするのです。


以下略
    * And of course: practice, practice, practice. Write code at work. Write code at home.
      Practice code katas. Programming is no different from any other skill: in the end, it
      all comes down to practice.

Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons 
Attribution-Noncommercial-Share Alike 3.0 United States License.

classics として書名の出たのが


Code Complete,
The Pragmatic Programmer,
The Practice of Programming,
Design Patterns.

ですか。どれも邦訳があるけどアサマシを貼っておくべきかw

■_ 矢印がいっぱい

Arrow mania

■_ もしもPHPが

××だったら。

ぐはっ。訳をつけている余裕がががが

If PHP Were British - Added Bytes by Dave Child

If PHP Were British
もし PHP がイギリス製だったら

When Rasmus Lerdorf first put PHP together, he - quite sensibly, despite his heritage 
- chose not to write it in Greenlandic or Danish. Good job too - that would have been 
rather unpleasant to work with. He opted instead, being in Canada at the time, for the 
local tongue. No, not French - that bastard dialect of the Queen's English commonly 
referred to as "US English".

PHP developers in Britain have been grumpy about this ever since. What was he thinking? 
And more importantly, how do we undo this travesty? How do we developers ensure the 
traditions of the British Empire continue to be upheld, even in the digital age?

A Slap in the Face

    $variable_name

The first, but maybe the most important, of many changes that will allow PHP to achieve a
more elegant feel is to remove that symbol so beloved by the US and replace it with
something altogether more refined. More solid. More ... sterling.

最初で最も重要なのは、アメリカから借りてきたシンボルを置き換えること。

    £variable_name

Abbreviations
略称

Few things are more abhorrent to the British than unnecessary abbreviations. "Text speak"
is unheard of on the streets of London, as the natural ingrained British grammarian simply
refuses to stoop to sending messages of the "c u soon traffic kthxbye" variety, instead
proferring something altogether more elegant: "Dear Sir/Madam. I will arrive as soon as
time allows, which I expect to be within the hour. I assure you the horses shall not be
spared. Yours respectfully." (slower to type, yes, but we do not like to be rushed).

PHP, on the other hand, is full to bursting with abbreviations and acronyms which are 
entirely unnecessary:

     str_replace()
     is_int()
     var_dump()
     preg_match()
     json_encode()
     mysql_connect()

The following changes should improve things:
以下のように変更することは重要である:

     string_replace()
     is_integer()
     variable_dump()
     perform_a_regular_expression_match() 
     javascript_object_notation_encode()
     my_structured_query_language_connect()

Eloquence

    if ($condition) {
        // Code here
    } else {
        // Code here
    }

Shakespeare would be ashamed to see his native tongue twisted into this monstrosity. 
Brevity is to be applauded in the right context - in some dark corner, where it shall 
be seldom seen - but not here. The if ... else block is the most used conditional code 
in all of PHP, so it must be made as inoffensive as possible. There are many options 
for its replacement, but this may be the strongest:

    perchance (£condition) {
        // Code here
    } otherwise {
        // Code here
    }

Spelling
綴り

    imagecolorallocate()
    serialize()
    newt_centered_window()
    connection_status()

Words fail me at this point. How is any self-respecting gentleman expected to make 
head or tail of these "words". It beggars belief that anyone could allow 
such distortions of words to be entered into a programming language. They, along with 
the myriad of similar errors, should be reverted to their proper forms immediately:

    imagecolourallocate()
    serialise()
    newt_centred_window()
    connexion_status()

略
The Sun Never Sets ...

It is hoped that these few simple changes will improve the reputation and status of 
PHP among other languages. No longer will it be the poor American cousin - instead it 
can take its rightful place as the - British - King of the scripting languages.

Thanks

Many thanks to Mark and Pat, colleagues at GSBA, who started this resurrection of the 
British Empire in the pub on Friday.

© 2003 – 2011 Added Bytes   |   Creative Commons License

■_

■_

また転職のニュースが。


一つ前へ 2011年8月(中旬)
一つ後へ 2011年9月(上旬)

ホームへ


リンクはご自由にどうぞ

メールの宛先はこちらkbk AT kt DOT rim DOT or DOT jp