ときどきの雑記帖'

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

一つ前へ 2013年1月(下旬)
一つ後へ 2013年2月(中旬)

ホームへ

2013年02月10日

■_

少林サッカー。サントラCDを買ってたはずなんだけど (CDウォークマン的な何かで聴きまくってた)、さてどこにいった。 まだリッピングしてなかったんだよなあ。

ぐはっ、今日「震える山」(の前編)やったのか。 あと半日早く気がついていれば…○| ̄|_ アニメ ガンダム・Gセレクション RETURNS | BS11 ちょっとこの値段では買う気になれないかなあ… 機動戦士ガンダム 第08MS小隊 Vol.04 [DVD] 機動戦士ガンダム 第08MS小隊 Vol.04 [DVD]
機動戦士ガンダム 第08MS小隊 5.1ch DVD-BOX (初回限定生産)
機動戦士ガンダム 第08MS小隊 5.1ch DVD-BOX  (初回限定生産)

Land of Lisp

■_ TaPL

昨日の続き。というか補足というか。

22.2 Two Views of Type Variables

Suppose that t is a term containing type variables and Γ is an associated context (possibly also
containing type variables). There are two quite different questions that we can ask about t:

  1. “Are all substitution instances of t well typed?” That is, for every σ, do we have
      σΓ  ⊢ σt : T for some T?

  2. “Is some substitution instance of t well typed?” That is, can we find a σ such that
     σΓ ⊢ σt : T for some T?

According to the first view, type variables should be held abstract during typechecking, thus
ensuring that a well-typed term will behave properly no matter what concrete types are later
substituted for its type variables. For example, the term

  λf:X→X. λa:X. f (f a);

has type (X→X)→X→X, and, whenever we replace X by a concrete type T, the instance

  λf:T→T. λa:T. f (f a);

is well typed.

の、 λf:X→X. λa:X. f (f a); の型が (X→X)→X→X だってのがちょっとわからなくなった ○| ̄|_ f の 型が X→X、aの型が X ってのはよい。で、 f (f a)

11章には


Is an uninterpreted type useless? Not at all. Although we have no way of naming its elements directly,
we can still bind variables that range over the elements of a base type. For example, the function1

  λx:A. x;
  n <fun> : A → A

is the identity function on the elements of A, whatever these may be. Likewise,

  λx:B. x;
  n <fun> : B → B

is the identity function on B, while

  λf:A→A. λx:A. f(f(x));
  n %lt;fun> : (A→A) → A → A

is a function that repeats two times the behavior of some given function f on an argument x.

こういうのがあって、一回やってるはずなんだけどなあ

■_ BP

特製「BP」ってなんだろう?

■_ Goodnight, Parrot

Goodnight, Parrot : perl Goodnight, Parrot - Modern Perl Books for modern Perl programming ううむ、ざっと読んだり訳すにはちょっと文章長め(わたしには)

Goodnight, Parrot - Modern Perl Books for modern Perl programming

Goodnight, Parrot

By chromatic on February 9, 2013 6:00 AM | No Comments

I stopped working on Parrot in January 2011. I'd started sometime in late 2001, probably around
September, around the same time I submitted my first patches to p5p. Nine years is a long time.

I didn't have the fortune to attend the infamous mug-throwing meeting which launched Perl 6 in 2000,
but by 2002 I found myself attending Perl 6 design meetings and taking copious notes and even
contributing ideas here and there. (It's not easy to speak up when Larry and Damian get going. Throw
in people like Allison Randal and Dan Sugalski, and it can be downright intimidating.)

(ざっくり略)

Because I thought I wouldn't get that in the foreseeable future, in 2011 I stopped contributing to
Perl 6 and Parrot altogether. I have better things to do with my time, including making things that
will actually get used. More power to the dreamers and experimenters who want to invest in the long
game. Good luck to them. That's not me anymore, and I'm quite a bit happier for it.

Parrot 5.0 came out last month, and there'll probably be a Parrot 5.1, but there's an irony to
realizing that Parrot will peter out as of Parrot 5 and that there will probably never be a Parrot 6.
Goodnight, Parrot : perl

Is it correct to say that the project was just too ambitious? I can't quite piece together the why
of it all.

What I seem to see is that the people were chasing a moving target. And bootstrapping a whole new
compiler + language + vm is a big task.

The mystery to me, though, is why it didn't fly, with talent of that magnitude. Those people have
built lots and lots of other things, so why this one in particular didn't fly remains a mystery to me.


Many people will disagree with me, but I believe the biggest problem remains that the pressure to
produce and support a working product is less important to the current developers than their desire
to do other things. It's really not fair for me to speculate about what they feel, but perhaps they'd
rather produce something which they believe is "complete" than something that is generally
"useful and usable by regular people". (Alternately, I'm being petty and bitter and should
give them the benefit of the doubt and wait just a little bit longer.)

When Parrot started to get serious about producing a mature product in 2009, it didn't lead to more
users and only seemed to frustrate Rakudo all the more. I can't entirely blame the Rakudo developers
for that frustration.

Maybe that's not fair to suppose. The intent of Rakudo Star was to produce a useful and usable and
supportable product, but it certainly hasn't met my needs, even two and a half years later--and I
thought I would be an ideal early adopter.

ちょっと腰を据えて読んだ方がよさげ。

■_

■_

11日は都立中央図書館辺りに籠もってようかなあ。 自分の本を持ち込んで読むのは無理そうだけどw 都立中央図書館 利用案内

2013年02月09日

■_

フレッシャーズ
通勤路の途中にある某洋服チェーン店に「フレッシャーズ向け云々」みたいな 文句の書かれたポスターがあって、まーた新手の英語もどきかと思い調べてみると… フレッシャーズ - Google 検索 フレッシャーってどういう意味ですか - Yahoo!知恵袋 フレッシャーズって何ですか? - Yahoo!知恵袋 和製英語っぽい響きですが、一応ちゃんとした英語ですね。 なんだってーっ!?

Fresher | Define Fresher at Dictionary.com noun British Slang. freshman. おおう。
1/350 艦船 No.12 1/350 アメリカ海軍 駆逐艦 DD445 フレッチャー 78012

デバッグの理論と実践デバッグの理論と実践 ―なぜプログラムはうまく動かないのか を読んでいましたら、253ページのリスト10-2 安全を保つためCycloneが設ける制限 に挙げられている項目の中に 領域解析とfree()への制限によって、循環ポインタ (dangling pointer)を防ぐ なんてのが。 dangling pointer って循環ポインターでしたっけ?

コピーキャット: 模倣者こそがイノベーションを起こす
書店で面陳されててちょっと気になった。 ううむどうしよう。

■_ TaPL読書会

22章。 22.3 までなんとかかんとか。 9章とか11章の内容を踏まえた記述があったりして、 最初の方の記憶がだいぶ怪しくなっているのを再確認。 確かに巻頭付近にある各章の関連グラフを見ると、22章は11章につながっているのよねえ。

22.3.2 定義
Γ |- t:T |x C
"term t has type T under assumptions Γ Constraints C"

turnstyle とか誤魔化してますがそれはおいといて、 x (χかも)の左側に | がくっついている記号が使われているんですが、 これって何者なんでしょうか? 22.3.2 の本文を読めばなんとなーくわかるのですが(制約 C に属する型変数?)、 なにかこうもやもやしたものがまだ。

あとこれ。ぱっと見で mapsto と → が一緒に見えて混乱したw

22.2.2 Example

  Let = f:X, a:Y and t = f a. Then

  ([X ↦ Y→Nat], Nat)     ([X↦ Y→Z], Z)
  ([X ↦ Y→Z, Z↦Nat], Z)    ([X↦Y→Nat→Nat], Nat→Nat)
  ([X ↦Nat→Nat, Y↦Nat], Nat→Nat)

are all solutions for (Γ, t).

今日の範囲に Exercise がいくつかあったのだけど、すっ飛ばして読んでいったので きちんとやっとかないとねえ。 これとか

22.3.9 Exercise [Recommended, ⋆⋆⋆ ]

In a production compiler, the nondeterministic choice of a fresh type variable name in the rule
CT-APP would typically be replaced by a call to a function that generates a new type variable -
different from all others that it ever generates, and from all type variables mentioned explicitly
in the context or term being checked - each time it is called. Because such global " gensym "
operations work by side effects on a hidden global variable, they are difficult to reason about
formally. However, we can mimic their behavior in a fairly accurate and mathematically more
tractable way by "threading" a sequence of unused variable names through the constraint generation 
rules.

Let F denote a sequence of distinct type variable names. Then, instead of writing ⊢ t : T |x C for
the constraint generation relation, we write Γ⊢ Ft : T |F C, where Γ, F', and t are inputs to the
algorithm and T, F, and C are outputs. Whenever it needs a fresh type variable, the algorithm
takes the front element of F and returns the rest of F as F'.

Write out the rules for this algorithm. Prove that they are equivalent, in an appropriate sense,
to the original constraint generation rules.

gensym とか different from all others that it ever generates とか、 「Lispのマクロ?」とか思ったのはここだけの話。

次回の開催時期は未定です。 3月の第2土曜にやらないのは確定しているんですが、 そのあとのほかの予定が読めないので。

■_ チャック・ノリス

Why does HTML think “chucknorris” is a color? : programming Why does HTML think “chucknorris” is a color? - Stack Overflow チャック・ノリス(の名前)はある色として解釈されるというお話。

<body bgcolor="chucknorris"> test </body>

Why does HTML think “chucknorris” is a color? - Stack Overflow

How come certain random strings produce various colors when entered as background colors in HTML?
For example:

<body bgcolor="chucknorris"> test </body>

...produces a document with a red background across all browsers and platforms.

Interestingly, while chucknorri produces a red background as well, chucknorr produces a yellow background.

What's going on here?

そのからくり。

Why does HTML think “chucknorris” is a color? - Stack Overflow

It's a holdover from the Netscape days:

    Missing digits are treated as 0[...]. An incorrect digit is simply interpreted as 0. For example
    the values #F0F0F0, F0F0F0, F0F0F, #FxFxFx and FxFxFx are all the same.

From this blog post, which covers it in great detail, including varying lengths of color values, etc.

If we apply the rules in turn from the blog post, we get the following:

    Replace all non valid hexadecimal characters with 0's

chucknorris becomes c00c0000000

    Pad out to the next total number of characters divisible by 3 (11 -> 12)

c00c 0000 0000

    Split into three equal groups, with each component representing the corresponding colour
    component of an RGB colour:

RGB (c00c, 0000, 0000)

    Truncate each of the arguments from the right down to 2 characters

Which gives the result

RGB (c0, 00, 00) = #C00000 or RGB(192, 0, 0)

Here's a JSFiddle demonstrating the bgcolor attribute in action, to produce this "amazing" colour swatch:

BGColor Swatch
http://i.stack.imgur.com/jc3FZ.png


This also answers the other part of the question; why does bcolor="chucknorr" produce a yellow
colour? Well, if we apply the rules, the string is:

c00c00000 => c00 c00 000 => c0 c0 00 [RGB(192, 192, 0)

Which gives a light yellow gold colour. As the string starts off as 9 characters, we keep the second
C this time around hence it ends up in the final colour value.

I originally encountered this when someone pointed out you could do color="crap" and it,
well, comes out brown.

"123abc" を数値コンテキストで評価したときにげふんげふんみたいな話ですね。と。

■_ 応じてみた

締め切り間近なので。 “Producing Open Source Software”第2版に向けたKickstarter Campaign - m-takagiの日記 Updating "Producing Open Source Software" for 2nd Edition by Karl Fogel — Kickstarter

んでまあ、すでに目標額はオーバーしてたんでいいかなとも思ったんですが

Updating "Producing Open Source Software" for 2nd Edition by Karl Fogel — Kickstarter

Yes, overfunding is fine:

The amount I've set as the threshold is enough to make all the important updates I'm aware of right
now, but things don't need to stop there.  If this project gets overfunded, that's even better:
that would allow me to spend even more time improving the book, including doing more research (e.g.,
talking to people in more open source projects, companies, etc), having more colleagues review the
work-in-progress & incorporating their feedback, improving site infrastructure to better automate
the ebook builds, improving the translation infrastructure, etc.  More money == better book and better
access, basically.  I'll be doing my work in a publicly visible repository, so anyone can stop by and
see what's going on at any time.  Patches welcome, of course.

ということなので考え直しました。 で、いくら出すかという話なんですが、$50だせば一冊もらえるとはいうものの 送料はこっちもちだったり、$100でサインつきになるけど やはり送料があるしそこまで出してる余裕はなあ(円ドルレートがちょっと円安に傾いてるしね) ということで$50には届かないくらいの金額で。

Redline Smalltalk V1.0 | Indiegogo

■_ MIT白熱教室

音のはなし。 今回は前回ほど「熱い語り」はなかったけれども、それはそれ。

■_

2013年02月08日

■_

出たようです きつねさんでもわかるLLVM - 達人出版会

コメントの伸びも良いし、取りあげるのには面白い題材かなあと思ったのだけど 元記事のコード部分を取り出すのが面倒そうだったので断念。 まあこういうこともあると。 John Carmack's comment on Doom 3's code style | Hacker News The Exceptional Beauty of Doom 3's Source Code

http://www.oreilly.co.jp/books/images/picture_large978-4-87311-587-0.jpeg Land of Lispのミュージックビデオ和訳・改 : だらっと学習帳

YAPC::Asia TOKYO 2013

■_ 6502

海の向こうは6502好きな人多そうですよね。やっぱりApple II の影響なんだろか。 Easy 6502 by skilldrick Easy 6502 | Hacker News Easy 6502 : programming

Easy 6502 | Hacker News

cpeterso

Is anyone still producing 6502 processors today? Is there any price advantage to using such an
venerable and well-known design today?

MagerValp

Yes, Western Design Center is selling the 65C02 in the classic 40-pin DIP package for about $5 a pop.

The last time I checked, which admittedly was almost 10 years ago, microcontrollers with embedded
6502 cores were quite popular with chinese toy manufacturers.

cpeterso

You reminded me of the Playpower Foundation that is designing a $10 6502-based "TV-computer"
for distributing educational games to developing countries. This is cool, but I can't help but think
that Moore's Law will deliver a cheap Android device.

Is there an Android device cheaper than the Raspberry Pi?

http://playpower.org/

まだ売ってるのか!

Easy 6502 : programming

6502 pretty much is a dead language. Any assembly ya see now adays will be x86, ARM, AVR (probably
closest to 6502), or maybe whatever ya call that stuff on the Propeller. Which are a bit "deeper"
than 6502 was. 6502 is pretty much a Turing Machine compared to modern CPUs.

But for me, it all started on the Commodore 64's 6510. I wrote my first text editor for it circa
1981 in under 2K of assembly at good ole $C000. I use the same text editor today to write code.
It's limited to 80 columns, but, eh, that's ok. http://shazware.com/shaz/ned.html
(Hint - you probably won't like it - i wrote it for me:)

My first PC was at school - a Commodore PET and TRS 80 Model II. My first home pc was the Timex
Sinclair ZX81, but I only learned Z80 asm on it to flash the screen (in FAST mode) and gave up on
it to buy a...

Wonderful C64. Man. The last couple years of high school for me were Led Zeppelin, Journey, Boston,
pot and 6502 assembly language coded via NEd. I was and continue to be a nerd to this day. Just let
me write code, build robots, and play piano and I'll be happy. Now adays I stick with c++, though.
Maybe C on an AVR or somethin. And my life's work has become http://pianocheetah.com Ok, enough self
agrandizement for today - sorry:/

実を言うと、わたし自身は6502にはあまり思い入れはなかったり。 6502搭載機に縁がなかったからなあ。

んで、好きな石は68000だったり。16ビットだけど。

Easy 6502 by skilldrick

Introduction

In this tiny ebook I'm going to show you how to get started writing 6502 assembly language. The 6502
processor was massive in the seventies and eighties, powering famous computers like the BBC Micro,
Atari 2600, Commodore 64, Apple II, and the Nintendo Entertainment System. Bender in Futurama has a
6502 processor for a brain. Even the Terminator was programmed in 6502.

So, why would you want to learn 6502? It's a dead language isn't it? Well, so's Latin. And they still
teach that. Q.E.D.

(Actually, I've been reliably informed that 6502 processors are still being produced by Western
Design Center, so clearly 6502 isn't a dead language! Who knew?)

Seriously though, I think it's valuable to have an understanding of assembly language. Assembly
language is the lowest level of abstraction in computers – the point at which the code is still
readable. Assembly language translates directly to the bytes that are executed by your computer's
processor. If you understand how it works, you've basically become a computer magician.

Then why 6502? Why not a useful assembly language, like x86? Well, I don't think learning x86 is
useful. I don't think you'll ever have to write assembly language in your day job – this is purely
an academic exercise, something to expand your mind and your thinking. 6502 was originally written
in a different age, a time when the majority of developers were writing assembly directly, rather
than in these new-fangled high-level programming languages. So, it was designed to be written by 
humans. More modern assembly languages are meant to written by compilers, so let's leave it to them.
Plus, 6502 is fun. Nobody ever called x86 fun.

ではなぜ6502なのか? なぜ x86のような有用なアセンブリ言語を使わないのか?
わたしはx86を学ぶことが有用だとは考えません。
わたしはあなたが日々の仕事でアセンブリ言語を使わなければならないことにはならないと考えています。
アセンブリ言語を学ぶことは純粋に academic な exercise であり、あなたの mind や思考を
拡大するものです。6502は遙か昔、developer たちの大半が
今日のような new-fangled high-level なプログラミング言語ではなく
直接アセンブリ言語でプログラムを書いていた時代に作られたものです。
つまり、人が書くために設計されたものです。
もっと最近のアセンブリ言語はコンパイラーが使うものとなってしまっているので避けたのです。
さらに言えば 6502は楽しい。
x86が楽しいという人は皆無でしょう。


以下略

■_ バグの話

流石に仕事関連で、最近あったことは書くのが色々以下略だったりした。

■_

■_

明日はアレ。

2013年02月07日

■_

ちょっとピンチ。

■_ 一兆クレジット艦隊

何度となく(中途半端に)話題にしてますが。

きちんと書くにはまだ資料が足りないのでねー。 実際のゲームが手元にないとかではなく、関係したエピソードについて。 なんですが。 なんにしろ断片的にしか覚えてなくて、検索キーワードもいいのがなくて空振りばかりと。

とはいえ、ちょっと前に書いたように大きく前進できるかもしれない手がかりを見つけられたんですが あれやこれやでそこからの進み具合が…

で、なんかこういうのが今日になって見つかりました

なんだってー>リメイク版

Traveller には見あたらないけど、これか? Adventure 3: Trillion Credit Squadron - Mongoose | Traveller | RPGNow.com

■_ Topaz

Rails Hub情報局: 本家の5倍速? Pythonで実装したRuby処理系の「Topaz」が登場

Announcing Topaz: A New Ruby — Topaz 0.1 documentation

Announcing Topaz: A New Ruby

I'm extraordinarily pleased to today announce Topaz, a project I started 10 months ago, to create
a brand new implementation of the Ruby programming language (version 1.9.3).

Topaz is written in Python on top of the RPython translation toolchain (the same one that powers
PyPy). Its primary goals are simplicity and performance.

Because Topaz builds on RPython, and thus much of the fantastic work of the PyPy developers, it
comes out of the box with a high performance garbage collector, and a state of the art JIT
(just-in-time) compiler. What does this mean? Out of the box Topaz is extremely fast.

Topaz is far from complete and is missing many builtin methods and classes. However, it does have
nearly every element of Ruby, including classes, blocks, many builtin types, all sorts of method
calls, and much much more. We don't yet consider it stable, but it's getting closer every day.

If you want to try it out right now, you can grab a nightly build, or build it yourself:

    OS X 64-bit
    Linux 32-bit
    Linux 64-bit
    Windows 32-bit

The major goal for the next several months is going to be completeness: adding more features of Ruby,
more builtin classes, more standard library modules, and generally getting to a point where real
people can run real applications under Topaz (the holy grail, of course, being running Rails). One
feature of particular note is FFI, once we have this people will begin to be able to run and develop
applications that interact with C libraries (such as database bindings).

If you're interested in a high performance Ruby, I'd encourage you to get involved: in testing it out,
in writing bug reports, and in helping to build the missing features.

(以下略)
© Copyright 2012-2013, Alex Gaynor. Created using Sphinx 1.1.2.

ということでソースコード眺めてみる。

■_

Use of Goto in Systems Code : programming

■_

2013年02月06日

■_

とりあえずKindle版のお試し版を読むことにしました>昨日のWirth先生の本

■_

今朝のJR組は大変だったみたいですね。通勤。 わたしは間引き運転の予定はなかった路線の、都心から離れる方向に乗っていくので特に何もなく。 さらに元々朝の始業時間よりかなり早めに出社してたりするので (ただし始業時刻になるまで仕事はしてない :)

結果的に雨で、間引き運転の必要がなくなったとしても 前夜早くから間引き運転のアナウンスはあったのだから、 いつもと同じ人数が数の減った電車に乗ることになればどうなるかってのは容易に想像できたんじゃ なかろうかなあという気はするんですけどね。

通常運転に戻さなかった(戻せなかった)点については怠慢と片付けるだけの判断材料がないので ここでは触れしません。

寺田寅彦 電車の混雑について

そいやこう言う話も

■_

Grandmaster とは。 そして例によって話題が横にそれつつ伸びる…

C++ Grandmaster Certification [CPPGM] : programming

C++ Grandmaster Certification [CPPGM] : programming

Does anyone know who is actually behind this, or if it is even real? The website is light on details
and there is no contact information or company names anywhere. They claim it is based on an internal
course somewhere without saying where.

Exactly - this is why I think it smells very fishy. No recognised names, associated companies, etc.
And it would take quite some talent and resources to put together and deliver such a project. So far,
there's no demonstrated credibility.


Lobsters have historically been opressed by mammals. For the last 10 years the problem has been
increasing, and we have developed a great sense of community. It's time we raise and make everyone
hear what we have to say.

Join us and learn more about our history at www.freelobsters.com


in the grand scheme of things, those languages are really very similar to each other.


Is Scheme similar to those languages in the grand scheme of Scheme?

According to Greenspun's Tenth Rule, yes.

■_

中途半端にやったのを中途半端に投下 Lessons learned from NUL byte bugs : programming Gauche Devlog - NUL in a string

More magic - Lessons learned from NUL byte bugs

Lessons learned from NUL byte bugs Posted on 2012-12-10
NUL バイトバグから得られた教訓


Last time I explained how sloppy representations can cause various vulnerabilities. While doing some
research for that post I stumbled across NUL byte injection bugs in two projects. Because both have
been fixed now, I feel like I can freely talk about them with a clear conscience.

前回(More magic - Structurally fixing injection bugs)
わたしは sloppy representations がどのようにしてさまざまな脆弱性を引き起こす可能性があるかについて
説明しました。ちょっとした調査をしている間、わたしは二つのプロジェクトにおける NUL バイトインジェク
ションに取り組んでいました。その二つのプロジェクトはどちらも現在では修正済みであるので、それらのバ
グについて自由に書けるだろうと判断しました。


These projects are Chicken Scheme and the C implementation of Ruby. The difference in the way these
systems deal with NUL bytes clearly shows the importance of handling security issues in a structural
way. We'll also see the importance of truly grokking the problem when implementing a fix.

その二つのプロジェクトとは、 Chicken Scheme と Ruby の C 実装です。これらのシステムにおける NUL バイ
トを扱う方法の違いは security issues を structual way で handling することの重要性をはっきりと示して
います。わたしたちはまた、修正を行うときの truly grokking the problem の重要性も見ることになるでしょ
う。


A quick recap

Remember that C uses NUL bytes to delimit strings. Many other languages store the length of the
string instead. In these languages, NUL bytes can occur inside strings. This can cause unintended
reinterpretation when strings cross the language border into C.

C は NUL バイトを文字列を終端するために使っていることを思い出してください。他の多くの言語では C とは
違って文字列の長さを保持しています。そのような言語では、NUL バイトを文字列の中に含めることもできます
が、これは言語の境界 (language border) を越えて C へ文字列を渡すときに意図していない reinterpretation
を引き起こす可能性があります。


In my previous post I already pointed out how Chicken automatically prevents this reinterpretation
in its foreign function interface (FFI). You just describe to Scheme that your C function accepts a
string, and it will take care of the rest:

前回の投稿では Chicken がその foreign function interface (FFI) によってどのようにして自動的にこの
reinterpretaion を防いでいるのかについて説明しました。行うことは文字列を受け付ける C 関数について
Scheme で記述するだけで、残りのことは Chicken がよろしくやってくれます。

  (define my-length (foreign-lambda int "strlen" c-string))

   ;; Prints 12:
  (print (my-length "hello, there"))

  ;; Raises an exception, showing the following message:
  ;; Error: (##sys#make-c-string) cannot represent string with NUL
  ;;   bytes as C string: "hello\x00there"
  (print (my-length "hello\x00there"))

The FFI's feature of automatically checking for NUL bytes in strings before passing them on to C was
only added in late 2010 (Chicken 4.6.0). However, because everything uses this interface, this
mismatch could easily be fixed, in a central location, securing all existing programs in one fell
swoop.

文字列を C へ渡す前にその文字列に含まれている NUL バイトに対する検査を自動的に行う FFI の機能は、
2010 年の終盤になってから Chicken 4.6.0 で追加されたものに過ぎません。
しかしすべてがこのインターフェースを使っているのでこの mismatch は簡単に修正することができました
in a central location, 
securing all existing programs in one fell swoop.



Now, you may be thinking "well, that's nothing special; it's good engineering practice that
there must be a single point of truth, and that you Don't Repeat Yourself". And you'd be right!
In fact, this is a key insight: solid engineering is a prerequisite to secure engineering. It can
prevent security bugs from happening, and help to fix them quickly once they are discovered. A core
tenet of "structural security" is that without structure, there can be no security.

さてここであなたはこう考えるかもしれません。 “特別なことはなにもない。これは
there must be a single point of truth な優れた engineering practice だ。
繰り返し同じことをすることはない。”
と。そう、あなたは正しい! 実際、これは key insight であり、
solid engineering とは secure enginnering のための prerequisite (必要条件、あらかじめ必要となるもの)
です。
これは偶発的なセキュリティバグを防ぎ、また、セキュリティバグが見つかったときの即座の修正を手助けします。
"structural security" の core tenet (主義、主張) は、structure 抜きでは no security になる可能性が
あるということです。


When smugness backfires

To drive home the point, let's take a look at what I discovered while writing my 
previous blog post. After describing Chicken's Right Way solution and feeling all smug 
about it, I noticed an embarrassing problem: for various reasons (some good, others 
less so), there are places in Chicken where C functions are called without going 
through the FFI. Some of these contained hand-rolled string conversions!

To drive home the point,
前回の blog 記事を書いている間にわたしが発見したものを取り上げることにしましょう。
Chiken の正しい解決方法を説明してすべてを解決したつもりになった後で、
FFI を通すことなく呼び出される C 関数がさまざまな理由で Chicken に存在していることにわたしは
気がついたのです。そういったものの一部には hand-rolled string conversions があったのです!


It turns out that we overlooked these places when first introducing the NUL byte 
checks, and as a consequence several critical procedures (standard R5RS ones like 
with-input-from-file) were left vulnerable to exactly this bug:

このことはわたしたちが最初に NUL byte check を導入したときにそういった場所を見逃していて、
(standard R5RS ones like with-input-from-file のような) いくつかの critical procedure がまさにこの
バグであるところの脆弱性を残していたことが明らかになったのです。


  ;; This program outputs "yes" twice in Chickens < 4.8.0
  (with-output-to-file "foo\x00bar" (lambda () (print "hai")))
  (print (if (file-exists? "foo") "yes" "no"))
  (print (if (file-exists? "foo\x00bar") "yes" "no"))


To me, this just validates the importance of approaching security measures in a 
structural rather than an ad-hoc way; the bug was only in those parts of the code that 
didn't use the FFI. Deviation from a rule is where bugs are often found!

わたしにとってはこれは単に、セキュリティにおいては ad-hoc な方法よりも
structual な方法をとることが格段に重要であることの確認です。
このバグは FFI を使っていなかった部分のコードにしかありません。
バグはルールを守っていないところからしばしば発見されたのです!


You can also see that we fixed it as thoroughly as possible, especially given the at times awkward
structure of the Chicken code. We commented every special situation extensively, assigned a new error
type C_ASCIIZ_REPRESENTATION_ERROR for this particular error, and added regression tests for at least
each class of functionality (string to number conversion, file port creation, process creation,
environment access, and low-level messaging functionality). There's definitely room for improvement
here, and I hope to one day reduce the special cases to the bare minimum. By documenting special
cases it's easy to avoid introducing new problems. It also makes them easier to find when refactoring.
The tests help there too, of course.

わたしたちが可能な限りの修正をしたこと、特に Chiken のコードの awkward structure を修正したことは
Chicken のコードで確認できます。わたしたちは広範囲にわたってすべての special situation にコメントを
つけ、特定のエラーに対して新しいエラー型 C_ASCIIZ_REPRESENTATION_ERROR を割り当て、それぞれの機能の
クラスに対する最低限のテストを行う regression test を追加しました。この機能クラスには文字列から数値
への変換、ファイルポートの作成、プロセスの生成、環境へのアクセス、低水準メッセージング機能といったも
のがあります。ここには room for improvement (改良、改善すべき点?) が間違いなく存在していて、そして、
いつの日か bare minimum のための special cases を reduce することをわたしは希望しているのです。
特別なケースをドキュメント化することによって、新しい問題を持ち込むことを排除するのが簡単になります。
It also makes them easier to find when refactoring.
また、いつリファクタリングするかの判断をより容易なものにします。
The tests help there too, of course.


When you run the above program in a Chicken version with the fix, it behaves like expected:
上記のプログラムを Chiken の修正済みバージョンで実行すると次のような結果となります:


  Error: cannot represent string with NUL bytes as C string: "foo\x00bar"


Another approach
もうひとつのアプローチ


The Ruby situation is a little more complicated. It has no FFI but a C API, so it 
works the other way around: you write C to interface "up" into Ruby. It has 
a StringValueCStr() macro, which is documented as follows (sic):

Ruby の situation はちょっと複雑になっています。Ruby には FFI がなく C API があるので
so it works the other way around:
Ruby に対するインターフェースを C で書きます。
Ruby には StringValueCStr() というマクロがあるのですが、
このマクロのドキュメントは次のように書かれています。


  You can also use the macro named StringValueCStr(). This is just
  like StringValuePtr(), but always add nul character at the end of
  the result. If the result contains nul character, this macro causes
  the ArgumentError exception.

  StringValueCStr() というマクロを使うこともできます。
  このマクロは StringValuePtr() と似ていますが、常に nul 文字をその結果の末尾に追加します。
  nul 文字がすでに含まれている場合にはこのマクロは ArgumentError 例外を引き起こします。


However, this isn't consistently used in Ruby's own standard library:
しかしこのマクロは Ruby 自身の標準ライブラリでも一貫性を持って使われているわけではありません:


  File.open("foo\0bar", "w") { |f| f.puts "hai" }
  puts File.exists?("foo")
  puts File.exists?("foo\0bar")


In Ruby 1.9.3p194 and earlier, this shows the following output, indicating it's vulnerable:
1.9.3p とそれより前のバージョンのRubyでは、このコードは次のような脆弱性を示唆する出力を行います:

  true
  test.rb:4:in `exists?': string contains null byte (ArgumentError)
          from test.rb:4:in `<main>'


It turns out that internally, Ruby strings are stored with a length, but also get a NUL byte tacked
onto the end, to prevent copying when calling C functions. This performance hack undermines the safety
of Ruby to C string conversions, and is the direct cause of these inconsistencies. True, there is a
safe function that extracts the string while checking for NUL bytes, but there are also various ways
to bypass this, and if you accidentally use the wrong macro to extract the (raw) string, your code
won't break. Of course, this is only true for benign inputs...

ここで、Ruby の文字列は内部的には長さも一緒に格納されているけれども NUL バイトが終端に置かれていて、
それが C 関数を呼び出したときのコピーを邪魔していることが明らかになりました。この performance hack
は文字列の Ruby から Cへの変換の安全性を傷つけているし、これら incosistencies の直接の原因となって
います。確かに文字列を extract する際に NUL バイトをチェックする安全な関数は存在しますが、それをバ
イパスする方法もたくさんあって、もしあなたが文字列を extract するのに accidentally に間違ったマクロ
を使ってしまってもあなたのコードが壊れることはありません。
もちろんこれはいじわるでない (benign) 入力に対してしか意味はありません。


The complexity of Ruby's implementation makes it hard to ensure that it's safe everywhere. Indeed,
the various places where strings are passed to C all do it differently. For example, the ENV hash
for manipulating the POSIX environment has its own hand-rolled test for NUL, which you can easily
verify; it produces a different error message than the one exists? gave us earlier:

Ruby の実装のこの complexity は、プログラムのどの部分も安全であることを保証すること (ensure that
it's safe everywhere) を困難にしています。実のところ、C に対して文字列を渡している場所はたくさん
あって、それぞれ違ったやり方をしているのです。たとえば POSIX 環境変数を操作するための ENV ハッシュは
独自の hand-rolled な test for NUL を持っているのですが、exits? とは異なるエラーメッセージを生成す
るのでそのことは簡単に確かめられます。


  irb(main):001:0> ENV["foo\0bar"] = "test"
  ArgumentError: bad environment variable name


There is no reason this couldn't just use StringValueCStr(). So, even though Ruby has this safe
macro, which provides a mechanism to check for poisoned NUL bytes in strings, it's rarely used by
Ruby's own internals. This could be fixed just like Chicken; here too, the best way to do that
would be to generalize and eliminate all special cases. Simpler code is easier to secure.

ここで StringValueCStr() を使っていけない理由はありません。そして Ruby がこの、文字列中の poisoned
NUL bytes に対する検査機構を提供する安全なマクロを持っているのにもかかわらず、Ruby 自身の内部であ
っても使われていることがまれなのです。これは Chicken と同じように修正が可能でした。この修正のため
の最善の方法は generalize を行って すべての special case を eliminetate することです。より単純な
コードは安全にするのもより容易なのです。


A fundamental misunderstanding
根本的な誤解

When I reported the bug in the File class to the Ruby project, they quickly had a fix, but
unfortunately they seemed uninterested in going through Ruby's entire code to fix all string
conversions (quoting from private e-mail conversation):

わたしが File クラスのバグを Ruby プロジェクトに報告したとき、彼らは即座にそのバグを修正したのですが、
残念なことに Ruby のコード全体を通してすべての文字列変換を修正しようということには興味がなかったよう
です (privateなやり取りをしたメールから引用します)。


  > I agree that this looks like a good place to fix the File/IO
  > class, but there are many other places where strings are passed to C.
  > Are all of those secured?
  All path names should be converted with "to_path" method if possible.
  If any methods don't obey the rule, it is another bug.  Please let us
  know if you find such case.


In retrospect, there is the possibility that I didn't quite make myself clear enough. Perhaps this
person thought I was referring to other path strings in the code. However, to me it sounds a lot
like they made the same conceptual mistake that the PHP team made when they "fixed" NUL
injections.

振り返ってみると、わたしは自分の意図を十分明確にできていなかったのかもしれません。おそらく返答したこ
の人物は、わたしがコード中のほかの path 文字列を渡すことを言っていると考えたのでしょう。しかし、わた
しにとってその行動は、PHP team が NUL injections を「修正」したときに犯してしまったのと同じ
conceptual mistake を Ruby 開発者たちが犯してしまったように思えたのです。


The PHP solution was to add a special "p" flag for converting path strings. This happens
for all PHP functions declared in C (via zend_parse_parameters()). By the way, notice how this is a
new flag. There probably are tons of PHP extensions out there which aren't using this flag yet. Also,
who can verify that they managed to find all the strings in PHP which represent paths?

PHP で採用された解決策は特別な "p" フラグを path 文字列の変換のために追加するというものでした。これ
は (zend_parse_parameters()を通じて) C で宣言されている PHP 関数すべてに影響しました。ところでこの新
しいフラグはどのように認識するのでしょうか。おそらくこのフラグをまだ使っていない PHP extensions は山
ほどあるでしょう。また、PHP において path を表現している文字列をすべて見つけ出すのを彼らが manage し
たと誰が verify できるのでしょうか?


The PHP team was completely missing the point here. This fix means that path arguments aren't allowed
to have embedded NUL bytes. Other string type arguments are not checked. They are missing the fact
that this isn't just a path issue. Rather, as I described before, it's a fundamental mismatch at the
language boundary where strings are translated from the host language to C. However, there seems to
be a widespread belief that this can only be exploited in path strings.

ここでPHP team は完全にポイントを見失っていました。彼らの行った修正は、path 文字列が埋め込まれた NUL
バイト (embedded NUL bytes) を持つことは許されないというものです。他の文字列型の引数はチェックされま
せんでした。彼らはバグが単なる path についての問題 (path issue) でないという事実を見落としていました。
わたしが以前説明したようにこれは、文字列が host 言語から C へと変換される language boundary における
fundamental mismtach なのです。しかしながら path 文字列においてのみ exploit 可能であると広く信じられ
てしまっているようです。


I'm not entirely sure why this is, but I can guess. First off, "poisoned NUL byte" attacks
have been popularized by a 1999 Phrack article. This article shows a few attacks, but only the
path examples are really convincing. Of course, another reason is that injecting NUL bytes in path
strings really is the most obvious and practical way to exploit web scripts.

それがなぜなのかわたしは完全に確信してはいませんが、推測はできます。最初に 1989年の Phrack article に
よって "poisoned NUL byte" 攻撃はポピュラーになりました。
この article は少数の攻撃を例示しただけでしたが、path を使った例はとても説得力のあるものでした。
誤解が広まったもうひとつの理由はもちろん、 path strings への NUL bytes の injection が web script を
exploit するための 最も obvious で practical な方法であったということです。


Recently, however, different NUL byte attacks have been documented. For example, they can be used to
truncate LDAP and SQL queries and to bypass regular expression filters on SQL input, but you could
argue these are all examples of failure to escape correctly. I found a more convincing example in the
(excellent!) book The Tangled Web: it contains a one-sentence warning about using HTML sanitation C
libraries from other languages. Also, NUL bytes can sometimes be used to hide attacks from log files.

しかし最近になって異なる NUL バイト攻撃がドキュメント化されました。たとえば NUL バイト攻撃は LDAP や
SQL のクエリを truncate したり、SQL 入力に対する正規表現フィルターのバイパスするのに使用可能です。
しかしそういった例のすべては正しいエスケープに失敗しているだけだという主張は可能です。
わたしは The Tangled Web という (excellentな) 本で、もっと convincing な例を発見しました。
その本には C 以外の言語から HTML のsanitation をする Cのライブラリを使うことについての一節がありました。
また、NUL バイトはログファイルから攻撃を隠すことにも使えることがあります。


However, the most impressive recent exploit is without a doubt this common vulnerability in SSL
certificate verification systems. In an attack, an embedded NUL byte causes a certificate to be
accepted for "www.paypal.com", when the CN (Common Name) section (that is, the server's
hostname) actually contains the value "www.paypal.com\0.thoughtcrime.org". Certificate
authorities generally just accepted this as a valid subdomain of "thoughtcrime.org",
ignoring the NUL byte. Client programs (like web browsers) tended to use C string comparison
functions, which stop at the NUL byte. Luckily, this was widely reported, and has been fixed in 
most programs.

しかしながら最近最も強い印象を与えた exploit はまず間違いないなく SSL certificate verification systems
における common vulnerability です。ある攻撃において、埋め込まれた NUL バイトは実際には
"www.paypal.com\0.thoughtcrime.org" であるような
CN (Common Name) section (that is, the server's hostname) に対する
certificate  を "www.paypal.com" として accept させてしまいました。
certificate authorities は一般的にこれを "thoughtcrime.org" の vaild なサブドメインと
して acceptし、NUL バイトを無視します。(webブラウザのような) クライアントプログラムは
NUL バイトの場所で比較をストップする C の文字列比較関数を使う傾向にあります。
幸運にもこれは広く report されていますし、またほとんどのプログラムでは修正済みです。


I believe that NUL byte mishandling represents a big and mostly untapped source of vulnerabilities.
High-level languages are gaining popularity over C for client-side programs, but many crucial
libraries are still written in C. This combination means that the problem will grow unless this is
structurally fixed in language implementations.

NUL バイトの mishandling が巨大で最も untapped な vulnerabilities の原因の原因になっているとわたしは
確信しています。高水準言語はクライアントサイドの言語として C を越えた popularity を得ましたが、多く
の重要なライブラリ群は今でも C で書かれています。この組み合わせは、問題が言語の実装において
structurally に fix されるまでは大きくなり続けることを意味しています。


Except where otherwise noted, content on this site is licensed under a Creative Commons
Attribution 3.0 License. All code fragments on this site are hereby put in the public domain.

■_

■_

しまった出遅れた(謎)

2013年02月05日

■_

「大雪」の天気予報が何日か前から出てるわけですが、 たとえば十年前のコンピューター(スーパーコンピューター)だと計算できたんだろうか などということが気になったり (計算性能だけの問題ではないでしょうけれども)。 そこから話を広げ…るのは面倒なので書かない(お約束)

■_ D is for Digital

こいつ D is for Digital: What a Well-Informed Person Should Know About Computers and Communications
D is for Digital: What a Well-Informed Person Should Know About Computers and Communications の翻訳本の表紙イメージがAmazonさんにも出てきまして。 ディジタル作法 −カーニハン先生の「情報」教室−
ディジタル作法 −カーニハン先生の「情報」教室− それはさておき、翻訳本のこのタイトルがちょーーーーーっと気になる今日この頃。 「作法」というのは、過去の本のタイトルにあやかってということ何じゃあないかと思うのですが、 これらは「さくほう」であって「さほう」じゃあなかったような? (「プログラミング作法」は違ったかも) ソフトウェア作法 プログラミング作法 それに、「D is for Digital」について、大先生のページに本の簡単な説明と目次があるのですけど

D is for Digital

D is for Digital

This book explains how today's computing and communications world operates, from hardware through
software to the Internet and the web. It includes enough detail that you can understand how these
systems work, no matter what your technical background. The social, political and legal issues
that new technology creates are discussed as well, so you can understand the difficult issues we
face and appreciate the tradeoffs that have to be made to resolve them.

Contents
Preface
Introduction
Part I: Hardware
    What's in a Computer?
    Bits, Bytes, and Representation of Information
    Inside the CPU
    Wrapup on Hardware
Part II: Software
    Algorithms
    Programming and Programming Languages
    Software Systems
    Learning to Program
    Wrapup on Software
Part III: Communications
    Networking
    The Internet
    The World Wide Web
    Data, Information, and Privacy
Wrapping Up
Notes
Glossary
Index

んーー、「作法」?

■_ Young CS students do not know who was N. Wirth nor that Pascal is a prog language.

確か2000年辺りに「引退」されてた様に記憶しているし、 知らないといっても不思議はないかなあとは思いつつもちと複雑な気持ちに。 Young CS students do not know who was N. Wirth nor that Pascal is a prog language. It's time to teach some history of programming languages : programming

It's time to teach history of programming languages | Modeling Languages

It's time to teach history of programming languages

February 05, 2013   jordi

One of the first concepts I show when teaching Model-driven engineering is the MDE equation
(Models + Transformations = Software ) which obviously revisits the well-known Niklaus Wirth‘s
equation: Algorithms + Data Structures = Programs.

I thought that by linking the two, it would be easier for the students to grasp the main aspects of
MDE but I was wrong. Relating the two doesn't work because it turns out none of my students ever
heard about Wirth equation, nor about Wirth himself and most of them have no idea what Pascal is
(happened already three times with both undergrad and master students).

Frankly, I'm puzzled. I'm not saying they should learn Pascal (though which language should be used
to teach programming to first-year students is an interesting controversy) but I do believe that
some context about the languages they learn is needed. Students should know the basics of the main
programming paradigms (structured, object-oriented, functional,…) and get a basic feeling of the
strengths of each one, their representative languages, the reasons that motivated their creation, etc.
以下略

© 2013 Modeling Languages. All Rights Reserved.

ありゃ。旧版どころかこれも新刊では買えないのか。 アルゴリズムとデータ構造
アルゴリズムとデータ構造

というわけで原著。 Algorithms + Data Structures = Programs (Prentice-Hall Series in Automatic Computation)
Algorithms + Data Structures = Programs (Prentice-Hall Series in Automatic Computation)

amazon.com の方で、wirth, nikulaus で検索したらこんな本が引っかかったんですが これ、日本語訳でてないですよねえ? (Amazon情報では2000年の刊行らしい) The School of Niklaus Wirth: The Art of Simplicity
The School of Niklaus Wirth: The Art of Simplicity

The School of Niklaus Wirth: The Art of Simplicity: Laszlo Boszormenyi, Jurg Gutknecht, Gustav Pomberger: 9781558607231: Amazon.com: Books

Book Description
Publication Date: October 25, 2000 | ISBN-10: 1558607234 | ISBN-13: 978-1558607231 | Edition: 1

Niklaus Wirth is one of the great pioneers of computer technology and winner of the ACM's A.M.
Turing Award, the most prestigious award in computer science. he has made substantial contributions
to the development of programming languages, compiler construction, programming methodology, and
hardware design. While working at ERH Zurich, he developed the languages Pascal and Modula-2. He
also designed an early high performance workstation, the Personal Computer Lilith, and most recently
the language and operating system Oberon.

While Wirth has often been praised for his excellent work as a language designer and engineer, he is
also an outstanding educator-something for which he is not as well known. This book brings together
prominent computer scientists to describe Wirth's contributions to education. With the exception of
some of his colleagues such as Professors Dijkstra, Hoare, and Rechenberg, all of the contributors to
this book are students of Wirth. The essays provide a wide range of contemporary views on modern
programming practice and also illuminate the one persistent and pervasive quality found in all his
work: his unequivocal demand for simple solutions. The authors and editors hope to pass on their
enthusiasm for simple engineering solutions along with their feeling for a man to whom they are all so
indebted.

Kindle版で60ドルかあ。ううむ

■_

2013年02月04日

■_

やる気レベル低下中

■_ What to do about GNU?

Paolo さんがまた。 What to do about GNU? | GNU Smalltalk What to do about GNU? Three ideas for GNU and the FSF : programming

What to do about GNU? | GNU Smalltalk

About a month ago, I released GNU sed version 4.2.2 and included in the release a "rant" (more
of a criticism, perhaps—I'm not a native speaker) about the state of the GNU project.

I made it clear that I had no philosophical disagreement with FSF; in fact, that's likely the reason
why almost no one took my post as an occasion to attack the FSF and Richard Stallman. To the few that
did: guys, you clearly missed the point. I wrote that text because I want free software and the FSF
to be successful. My concern is that if GNU loses, the FSF loses—even if some other piece of free
software happens to win.

(略)

GNU has been producing free software for almost 30 years now, and there's no reason why it should
stop. Join us now and share the software; you'll be free, hackers, and we'll do our best to make it
fun!

全文でも長くはないし訳しといた方がよいのかしらん

■_ 雪

さてどうしたものか 2月6日、首都圏に大雪の予報 - ねとらぼ 首都圏では2月5日の深夜から雨や雪が降り始め、6日朝の通勤通学の時間帯にもっとも降る可能性が高く、それが夜にかけて続くとのこと。

■_

■_ 長いオプションを使おう

Use long flags when scripting - The Changelog

Use long flags when scripting - The Changelog

I peruse a fair amount of dotfile repos, and keep seeing people use short flags inside aliases and
little command line tools. Short flags are a command line shortcut, and they do belong there, but
if you're not writing the command in a prompt, do yourself (and anyone else that may someday be
reading your code) a favor and be more verbose, because this:

  curl --silent checkip.dyndns.org \
  | grep --extended-regexp --only-matching '[0-9\.]+'

is a lot easier for a human to understand than this:

  curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'

言ってることには賛成だけど、ブラケットの中の . をエスケープしているのが気に入らない :)

2013年02月03日

■_

白熱教室の先生の「熱い話」でふと思い出したのですが、 高校のときの世界史(選択)の先生(講師できていた)が最後の授業で そういう印象を残した話をしてくれたなあと。 どういった内容なのかはナイショw。 その年を最後に日本を離れてハワイに住むんだとか言ってたのですけど どうなったのかなあ。

んで、さらに連想で「カール・セーガン」と 「COSMOS」を思い出したり。 あの番組も今観ると「しょぼ」とかになっちゃうんですかねえ。

そしてその「COSMOS」で知ったのが「ヴァンゲリス」 「ブレードランナー」やら「炎のランナー」

最近「品質」という言葉がなんというかそのゲシュタルト崩壊(たぶん間違った使い方)というかなんというか

ミネストローネ。 モスバーガーの季節限定メニューに出てこない(クラムチャウダーはある)し、 渋谷駅にあるドリンクショップ(何と称するのか知らない。東口の改札付近にあるあれ)でも いつもなら出てる時期にでてこなかったし、 12月辺りに出てきたなあと思ったら 今日通りかかったときにはまたなくなってた。 なんかあったんだろか。

■_ 蒸気機関車の興亡

図書館で偶然見かけて、借りて読んでみたのだけど面白かった。 詳しい感想などは書くかもしれないし書かないかもしれない。 蒸気機関車の興亡

この人は他にも蒸気機関車で本を書いているのね。 蒸気機関車200年史 蒸気機関車の技術史 (交通ブックス)

■_

  • XNAのはなし - 猫とC#について書くmatarilloの雑記
  • 出版状況クロニクル57(2013年1月1日~1月31日) - 出版・読書メモランダム
  • 小学生からプログラミング教育を始めるエストニア: プログラマの思索
  • 今週の話題 : B-Tree を使用した STL 互換のコンテナライブラリなど - WebOS Goodies
  • C++ containers that save memory and time
  • Tcl言語で漢数字変換を含んだ計算処理 | その他(プログラミング)のQ&A【OKWave】
  • コーディングミスの見逃しを防ぐスクリプト - None is None is None
  • 圏論プログラミング言語 - Wikipedia
  • 「小さなイプシロン」
  • ちょっと危ない?と思ったら 自分でできるうつ予防  :日本経済新聞
  • 見も蓋もない「とりあえずの救済」が重要だよ - clonblmn's revenge
  • Boost.Locale security notice
    boost::locale::utf::utf_traits accepted some invalid UTF-8 sequences.
  • What to do about GNU? | GNU Smalltalk
  • ■_

    2月の新刊で面白そうなのを見つけたんだけど値段ががががが 数学の女王 ―歴史から見た数論入門― / Jay R.Goldman  著 鈴木 将史 訳 | 共立出版

    数学の女王 ―歴史から見た数論入門― / Jay R.Goldman  著 鈴木 将史 訳 | 共立出版
    
    数学の全体像が見渡せた頃の,フェルマー,オイラー,ガウスといったさまざまな主人公たちの人生模様を
    描きながら,とりわけ多くの人々を魅了してきた「数論」の分野を縦横無尽に案内する。読者は数学者たち
    の人間味あふれる姿に触れつつ数学発展の歴史をその源流からたどり,やがてヴェイユやワイルズに至るま
    での現代数学が,その延長線上に現れてくる様を見ることができる。またそこには古代ギリシャのディオフ
    ァントスという天才の姿も息づいていて,数学という学問を数千年のつながりとして描く壮大な試みとなっ
    ている。
    

    なんとなくアサマシ貼り付け。 数学の女王 ―歴史から見た数論入門―

    ■_

    日曜日の夜は何とも忙しない。 いやまあ大したことやってるわけでもないんですけど。

    ■_

    そして寝る前にアップロードするのを忘れてしまったという。

    2013年02月02日

    ■_

    むむこれが出るのか。現地でカタログ買うとかフリー入場になるのを待つという手もあるけど素直に委託待ちかなあ。 新刊は「サクラ姫ネリマ証券・2」です。(SIESTA) 前のが面白かったので待ってたのね(二つめのリンク先に飛ぶときは周囲に注意 :)。 COMIC ZIN 通信販売/商品詳細 サクラ姫ネリマ証券 金融商品入門者向け同人誌 サクラ姫ネリマ証券 「内容はかなりガチだ!」 - アキバBlog

    白熱教室 白虹とかアレクサンダーの暗帯とか知らなかったわー。 にしても最後の締めの言葉が熱いわあの先生 (本はまだ買ってないんだけど、ちょっと立ち読みした部分にはいろいろと背景情報があってなるほどなあとも)。 白虹++あおぞら☆めいと アレキサンダーの暗帯: 松沢友紀はこうして生きている

    ■_ きんどる

    面白そうなのみつけたので買ってみた。読むのはこれから。 Amazon.co.jp: プログラミング言語学をめざして eBook: 金田 泰: Kindleストア Amazon.co.jp: ベクトル記号処理法とその論理型言語プログラムへの適用 eBook: 金田 泰: Kindleストア

    ■_ sed & awk

    A nice tutorial on sed and awk commands.. : programming The UNIX School: awk & sed

    A nice tutorial on sed and awk commands.. : programming
    
    sed + grep + awk == all the power in the universe
    
    
    
    Don't forget to add 'find' to the mix.
    
    
    
    This link look like a good idea, but it is a really bad piece of advice: using a real programming
    language that replaces sed and awk and cut and sort is a much better investment in the mid- and
    long-term.
    
    While Perl for example can get criticized for being difficult to read, at least it will work in the
    same manner across many systems, large scripts will be much faster than shell processes, and will be
    more reliable (in case there are spaces in filenames for instance).
    
    And there are of course other languages that can be used for system administration: Python, Ruby and
    even Ocaml.
    
    
    
    I have to disagree with you; I have found awk, grep, cut, and sort absolutely indispensable over my
    entire career for quickly processing text based data. As much as I love Python, my language of
    choice, it's often far more efficient to whip up a short awk script and get the results now.
    
    

    ■_

    銭湯の入り方(暗黙のルールとかマナーとかそういうのね)を知らない人も多いんだろうなあ。

    ■_ 会員登録

    そりゃすばらしいと IT記者会Report にいって、岸田さんの記事を読もうとクリックすると 「会員専用」とかなんとか ○| ̄|_ なんか気勢削がれたなあ。

    ■_

    ■_ おーぎし

    特撮博物館のときの失敗をしないようせねばw>王義之展

    それはさておき L'eclat des jours(2013-02-02) 何気なくつけたNHK-Gで、これは誰の書でしょう? とか問いかけがあって何か書付が示された。 江戸時代の人の何かかなぁとか思って眺めていたら、西(最初は東っぽい)晋の王義之(350年ころの人)で、名前に見覚えがあってもさっぱりわからないのでついそのまま見てしまった。 最初は東っぽいというところの意味が良くわからんのですが、 西晋と東晋であれば東晋のほうが後の時代です。 東晋 - Wikipedia

    2013年02月01日

    ■_

    変わる変わるよ(ry
    東京都、小田急と進める下北沢駅など3駅の地下化切り替え工事を3月に実施 | エンタープライズ | マイナビニュース この辺りは裁判沙汰になったりいろいろあったんだよねえ。 で、むかーし高校生の時分に正月の郵便局アルバイトやったときに この辺の地域が割り当てられたのよね。細い道まで覚えている(いた)けど 今はもうだいぶ変わっているだろうねえ 東北沢~世田谷代田間(工事中区間)|複々線化事業|鉄道事業|事業案内|会社案内|企業・CSR情報|小田急電鉄 この開かずの踏み切りのひとつが通り道にあって(ry

    この区間とか登戸や向ヶ丘遊園あたりもわたしが学生の頃とは大違いだし。 世田谷代田~和泉多摩川間(複々線化完成区間)|複々線化事業|鉄道事業|事業案内|会社案内|企業・CSR情報|小田急電鉄

    鉄道がらみの変化といえばこういうのも。 あの辺りの東横線の地上部分どうするんだろうとは気になってた。 東急電鉄が渋谷川を再生 渋谷駅南側、憩いの場に  :日本経済新聞

    ■_

    JaSSTでのLTだかであったというこれ JaSST-LT 病理学 から。 ソフトウェア病理学というのはなんか聞き覚えがあるような。 ソフトウェア病理学 | shimashimaの日記 | スラッシュドット・ジャパン

    しかし高い本だ。 Amazon.co.jp: ソフトウェア病理学―システム開発・保守の手引: Capers Jones: 本 Amazon.co.jp: Assessment and Control of Software Risks (Yourdon Press Series): T. Capers Jones: 洋書 面白そうな本ではあるのだけど、 Assessment and Control of Software Risks: T. Capers Jones: 0076092032878: Amazon.com: Books の書評の一つに The book is a great resource for brainstorming potential risks to your projects and strategies to handle them. Almost all are timeless. However, the book is 10 years old and much has changed over the last 10 years. The Internet is a prime example. This new medium has most of the risks of legacy systems, but the Internet brings new possibilities and new expectations. とあるようにちょっと古い本なので、 古本で翻訳本に手をだすのはちょっと値段に見合ったものではないかもという気はする。 とりあえず都立中央図書館にはあるっぽいので近くの図書館で取り寄せを頼んでみよう (直接行ってもいいんだけどね。ちょっと見るだけなら)。

    でスライドにもあった読書会。行けない場所ではないな。 「ソフトウェア病理学」読書会第1回|zenbackキーワーズ 2月20日 「ソフトウェア病理学」読書会第4回(神奈川県)

    ■_ Scheme vs. Python

    Scheme vs. Python as a learning language, professor' point of view : programming

    Scheme vs. Python
    
    Scheme vs. Python
    
    People keep asking me about the choice of programming language in 61A. Here is a rather longer
    explanation than I could give face to face.
    
    61A におけるプログラミング言語の選択について繰り返し尋ねられています。
    ここで書いたのは、対面して話すよりも長い釈明です。
    
    
    1. The most important thing to understand: The choice of programming language is far from the most
    important thing in designing a course. The Berkeley party line is that you should be able to learn
    a programming language (after the first time) over a weekend. If we mean that, then we shouldn't be
    arguing about the programming language so much. And we shouldn't start designing a course by
    picking a programming language. Honestly, if the new Python-based course turns out to be a better
    course, I won't mind at all that it's in Python. It's SICP that I want to preserve, not Scheme.
    
    最も重要なことは、プログラミング言語の選択は designing a course において最重要なものからはほど遠い
    ということです。
    The Berkeley party line is that you should be able to learn
    a programming language (after the first time) over a weekend.
    If we mean that, then we shouldn't be arguing about the programming language so much.
    そして、わたしたちはプログラミング言語の選択 (picking) によって course を design すべきでないのです。
    正直申し上げて、この新しい Python-based course が a better course になったとしても、
    わたしはそれが Python を使ったものであるかどうかには頓着しないでしょう。
    わたしが preserve したいのは SICP であって Scheme ではないのです。
    
    
    2. Having said that, something that is important to understand in designing a course is that the best
    language for a course is not necessarily the best language for writing real-world code. For writing
    real-world code, what you want is aggressive optimization, and access to libraries for up-to-the-minute
    solutions to real-world problems. For a course, what you want is a crystal-clear language that
    highlights the computer science ideas without hiding them in a cloud of syntax or library details.
    
    ある course における best language が、real-world code を書くための best language である必要はないと
    いうことです。real-world code を書くために必要となることは aggressive optimization と、
    real-world problems に対する up-to-the-minute な solution のためのライブラリに対するアクセスです。
    For a course, what you want is a crystal-clear language that
    highlights the computer science ideas without hiding them in a cloud of syntax or library details.
    
    
    3. And having said that, I'm not really ready to cede the real world to Python or Java. How many
    people reading this are 50 years old? Lisp is 50 years old — and for the most part, the lifespan of
    a programming language is closer to the lifespan of a dog than to that of a person. Only one other
    language (Fortran) is that old and still in use. Why has Lisp survived? Not because it's useless.
    People still use it because you can write working code in Lisp way faster than you can in most
    so-called “practical” languages.
    
    And having said that, I'm not really ready to cede the real world to Python or Java.
    これを読んでいる人のどれほどが50才でしょうか? Lisp は50才です。
    - and for the most part, プログラミング言語のlifespanは人間のそれよりも犬のそれに近いものです。
    Lisp 以外の言語ではただ一つ Fortran だけが古く、今も使われているものです。
    なぜ Lisp が生き延びたのか? それは Lisp が useless であったからではありません。
    Lisp が使われているのは、“practical”な言語と呼ばれているもののほとんどよりも
    Lisp の方が早く working code を書けるからです。
    
    
    4. During those entire 50 years, people have been saying “Lisp is impractical”; “Lisp is too slow”;
    “procedure calling is too expensive”; “only professors care about Lisp.” They're still saying it.
    But meanwhile, users — real users — who would never dare give their bosses a program written in Lisp
    are demanding Lisp's ideas in the programming languages they do use. Today you take recursion for
    granted, but it was a radical idea when Lisp introduced it. (Fortran didn't have recursive procedures 
    until fairly late in its history; the early personal computer users made do with BASIC, which, in
    those early versions, had no procedure calling at all.) Users of strongly typed languages demanded,
    and got, Lisp's heterogeneous lists. Today, the radical Lisp idea that's invading the mainstream is
    first class procedures. Guido van Rossum, the inventor of Python, hates Lisp, but he was dragged
    kicking and screaming by users into providing [a half-assed version of] lambda in Python. Even C++,
    a notorious can of worms, has added lambda in its most recent version. Lambda in Java is coming in 2013. 
    In another decade they'll probably discover first class continuations.
    
    その50年間に繰り返し次のようなことが言われてきました。“Lisp is too slow”(Lisp は遅すぎる)、
    “procedure calling is too expensive”(手続き呼び出しが高くつきすぎる)、
    “only professors care about Lisp”(教授たちだけが Lisp に注目している)。
    今でもこのようなことを言っている人たちもいます。
    しかし一方で自分たちの上司に対して Lispで書いたプログラムを渡すことが決してできない
    (本当の)ユーザーたちは、自分たちの使うプログラミング言語に Lisp のアイデアを要求したのです。
    今あなたは再帰を自由に扱えますが、Lisp が導入したときはそれは radical なアイデアだったのです
    (Fortran はかなり遅くまで再帰的手続きを持っていませんでした。初期のパーソナルコンピューターの
    ユーザーは BASIC を使っていましたがそれは手続きもないようなものでした)。
    strongly typed languages のユーザーたちは Lisp の heterogeneous lists を要求し、手に入れました。
    今日 mainstream を invading している radical Lisp idea は first class procedures です。
    Python の inventor である Guido van Rossum は Lisp が好きではありませんでしたが、
    ユーザーたちの要望によって Python に [a half-assed version] の lamdaを追加することになりました。
    C++ でさえ、most resent version で lambda を追加しました。Java の lambda も 2013年に来ます。
    次の十年には first class continuations (第一級継続) が発見されることでしょう。
    
    
    5. You can learn to program in any language. But it's not just an accident that the authors of SICP
    chose Scheme as their teaching language. The big ideas in the book — the ones that alumni in the real
    world tell us they're using in their work — express themselves best in Scheme. Indeed, saying it that
    way puts the matter backward. Gerry Sussman (with Guy Steele) invented Scheme before he turned (with
    Hal Abelson) to expressing the ideas behind Scheme in a course. SICP is Scheme, in tutorial form. 
    
    どんな言語ででもプログラムを学ぶことはできます。しかし、SICP の著者たちがその teaching language とし
    て Scheme を選んだのは単なる偶然からではないのです。
    SICP の big ideas は Scheme で説明したということです
    - the ones that alumni in the real world tell us they're using in their work -
    Indeed, saying it that way puts the matter backward.
    Gerry Sussman (と Guy Steele) は彼らが (Hal Abelson と共に)
    course の背景にあるSchemeという考えに到る前に Scheme を開発しました。
    SICP とは Scheme なのです。tutorial form において。
    

    ■_ 再利用

    Reusable code - The original developer reused the hell out of that one line of code : programming

    Reusable Code - The Daily WTF
    
    Code reuse is one of the key steps to maintainability. There are many ways a developer might make
    their code reusable. For example, Steve's co-worker wrote this block, which generates 1000 log entries:
    
    コードの再利用は保守性の key stepの一つです。
    developerが自分たちのコードを再利用可能にするのには多くの手段があります。
    たとえば Steveの同僚は1000件のログエントリを生成するのに次のようなblockを書きました。
    
    int next = 0;  
    
    List<FeedSearchTransactionLogResult> allDataSimulated = new List<FeedSearchTransactionLogResult>();  
    
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
    //SNIP skip 995 lines…  
      
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));  
    allDataSimulated.Add(new FeedSearchTransactionLogResult(next++));
    
    At least, it might be 1000 log entries. It's hard to tell. The original developer reused the hell
    out of that one line of code. This block is easy to modify- if the number of iterations ever changes,
    a developer simply needs to add or remove the correct number of lines. 
    

    reddit での反応から

    Reusable code - The original developer reused the hell out of that one line of code : programming
    
    See: Unrolled loop optimisation.
    
    
    
    See: -O4
    
    
    
    You'd think that he'd consider somehow getting rid of object instantiation inside the loop first...
    
    
    Could be. This is the problem with snippet of codes. Without knowing the context behind the code you
    cant really tell what the programmer was trying to achieve.
    
    
    Loop unrolling makes sense for low numbers of iterations. By the time you hit 1,000 iterations, I
    think anything you gain in unrolling is lost due to lower cache locality.
    
    
    
    This example appears to be C#, in which case the CLR JIT already takes care of that optimization for
    you for "small loops with small bodies", so it's quite likely a case of cargo-cult
    optimization — the kind of tweak that is assumed or said to be useful, but may have no effect (or
    even a negative one).
    
    

    ■_

    ■_ 今日の新言語

    Gagallium : Introduction to Mezzo

    Gagallium : Introduction to Mezzo
    
    
    What is Mezzo?
    
    Mezzo draws most of its inspiration from ML. Therefore, a big chunk of the language reads and feels
    just like ML (keywords: strict evaluation, functional, impure). However, there's a reason we're
    designing a new language: we want to go further than ML.
    
        We want to reject some programs previously accepted by ML; in a sense, we want to forbid patterns
        we consider dangerous.
    
        Conversely, we want to accept some programs previously deemed unsafe by an ML type-checker: we
        want to make more programming patterns possible.
    
    Most of these improvements come at a cost, naturally. The design that I'm about to introduce is
    still very much in flux, and time will tell whether the cognitive cost of our new system is worth
    the benefits.
    
    However, we deliberately tried to cut down the complexity of the system: in a sense, we don't want
    to end up doing proofs within the type system. Therefore, the mechanisms that I'm about to introduce
    may seem low-tech compared to recent research works, but we believe that's what makes it possible to
    explain the language to a (seasoned) ML programmer, and also what makes writing a type-checker
    relatively doable, without requiring a huge burden of annotations from the programmer.
    
    

    Gagallium : Introduction to Mezzo, continued


    一つ前へ 2013年1月(下旬)
    一つ後へ 2013年2月(中旬)

    ホームへ


    リンクはご自由にどうぞ

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