Python as a Foreign Language
Prologue
puellae.map(lang)
puellae.map(lang)
puellae.map(lang)
Perlの補足
Then
use strict;
use warnings;
Now
use v5.12; # or better
The Three Virtues of a Programmer
laziness(怠惰)
Impatience(短気)
Hubris(傲慢)
1. Lazyness(怠惰)
The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don't have to answer so many questions about it.
全体の労力を減らすために手間を惜しまない気質。この気質の持ち主は、役立つプログラムを書いてみんなの苦労を減らしたり、同じ質問に何度も答えなくてもいいように文書を書いたりする。
1. Lazyness(怠惰)→Perl?
"Open Source" before the word is born
CPAN
Lightning Talks
Code Golf
…
2. Impatience(短気)
The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least that pretend to.
コンピューターが怠慢な時に感じる怒り。この怒りの持ち主は、今ある問題に対応するプログラムにとどまらず、今後起こりうる問題を想定したプログラムを書く。少なくともそうしようとする。
2. Impatience(短気)→Ruby?
Extendable Built-in Objects (Monkey Patch)
Ruby Out of on Rails
GEM 2.0 vs 1.x
…
3. Hubris(傲慢)
Excessive pride, the sort of thing Zeus zaps you for. Also the quality that makes you write (and maintain) programs that other people won't want to say bad things about.
神罰が下るほどの過剰な自尊心。または人様に対して恥ずかしくないプログラムを書き、また保守しようとする気質。
Zen of Python
import this
Beautiful is better than ugly.
きたないのよりきれいな方がいい
Perl
join "☆" => qw/まどか マギカ/;
Ruby
%w[まどか マギカ].join('☆')
JavaScript
['まどか', 'マギカ'].join('☆');
Python
u"☆".join(['まどか', 'マギカ'])
Explicit is better than implicit.
ごちゃごちゃ難しいのより、白黒はっきりしてるのがいい
Explicit is better than implicit.
🐍
Python 3.3
u"🐍"
"🐍"
from __past__ import unicode
# わけがわからないよ
Python (and C++11)
u"\U0001F40D"
Simple is better than complex.
めんどうなのよりかんたんな方がいい
A Little Wish
Perl
$universe =~ s/魔女//g;
Ruby
universe.gsub(/魔女/, '');
JavaScript
universe.replace(/魔女/g, '');
Python
import re;
re.compile('魔女').sub('', universe);
Complex is better than complicated.
けど、訳分かんなくなるくらいならめんどうな方がまし
Perl
sub make_counter {
my $count = shift;
sub { return ++$count }
}
my $c0 = make_counter(0);
my $c1 = make_counter(0);
print $c0->(), "\n";
print $c1->(), "\n";
print $c1->(), "\n";
print $c0->(), "\n";
print $c1->(), "\n";
print $c1->(), "\n";
Python - Buggy
def make_counter(count):
def fun():
count += 1
return count
return fun
c0 = make_counter(0)
c1 = make_counter(100)
print(c0())
print(c1())
print(c1())
print(c0())
print(c1())
print(c1())
Python - Corrected
def make_counter(count):
def fun():
nonlocal count
count += 1
return count
return fun
c0 = make_counter(0)
c1 = make_counter(100)
print(c0())
print(c1())
print(c1())
print(c0())
print(c1())
print(c1())
Flat is better than nested.
ネストさせなくていいならしない方がいい
Flat is better than nested.
Sparse is better than dense.
たくさん詰め込んだのよりスカスカな方がいい
Sparse is better than dense.
Then why do you include batteries?
Sparse is better than dense.
Then why do you include batteries?
PIP? Easy Install?
Readability counts.
読みやすさがたいせつなのよ
Readability counts.
→ We'll talk about it later
Special cases aren't special enough to break the rules.
特別なこともあるけど掟破りってほどじゃない
Special cases aren't special enough to break the rules.
Although practicality beats purity.
実用性を求めてくと、ちょっとはずれちゃうこともあるけどね
Although practicality beats purity.
→ We'll talk about it later
Errors should never pass silently.
エラーをだまって通すようなことがあっちゃいけません
Unless explicitly silenced.
わざとそうしてるんじゃない限り
In the face of ambiguity, refuse the temptation to guess.
あいまいなことをてきとーに処理しちゃいけません
There should be one-- and preferably only one --obvious way to do it.
間違えようのないやり方がひとつだけあるのがいいね
There should be one-- and preferably only one --obvious way to do it.
len(u"\U0001F40D")
There should be one-- and preferably only one --obvious way to do it.
% /usr/bin/python
Python 2.7.2 (default, Jun 20 2012…
[GCC 4.2.1 Compatible Apple Clang 4.0…
Type "help", "copyright", "credits"…
>>> len(u"\U0001F40D")
2
There should be one-- and preferably only one --obvious way to do it.
% port installed |grep python
python27 @2.7.3_0+ucs4 (active)
python32 @3.2.3_0+ucs4 (active)
…
% /opt/local/bin/python2.7
Python 2.7.3 (default, Aug 9 2012…
[GCC 4.2.1 Compatible Apple Clang 4.0…
Type "help", "copyright", "credits"…
>>> len(u"\U0001F40D")
1
Although that way may not be obvious at first unless you're Dutch.
オランダ人以外には、ちょっと分かりにくかったりしてもね
Although that way is not be obvious for years unless you're stuck with the Basic Multilingual Plane.
BMPで満足しちゃっている限りは
Now is better than never.
やらないよりは今やるべき
Although never is often better than *right* now.
けど今「すぐ」やるならやんない方がいいこともある
u"🐍" or just "🐍"
If the implementation is hard to explain, it's a bad idea.
作るものをうまく説明できないようならそれはボツ
If the implementation is hard to explain, it's a bad idea.
% ./configure --enable-unicode=ucs4
If the implementation is hard to explain, it's a bad idea.
% ./configure --enable-unicode=ucs4
Python 3.3 で直るのですよね?
If the implementation is easy to explain, it may be a good idea.
うまく説明できたらたぶんそれがグッド
If the implementation is easy to explain, it may be a good idea.
Would somebody explain this mess to the Dutch in Mountain View?
どなたかマウンテンビューのオランダ人に説明してあげてくだちい
Namespaces are one honking great idea -- let's do more of those!
ぶらぼーなアイディア名前空間、やっぱこれですね
Namespaces are one honking great idea -- let's do more of those!
% easy_install
何をeasy_installするって?
Perlも人のこと言えた義理か?
% prove
何をproveするって?
(まあTAPは言語非依存ではありますが)
Why Python is not as popular here as it should be?
なぜPythonがいまいち萌えてないかって?
Because you are not import
ing enough!
import足りなさすぎ!
Python deserves more.
We deserve more from Python.
Python to Foreigners = Readablity
We love codes.
We hate psudocodes.
they never run.
bugs don't show up
We have Python today. Why need psudocodes?
Who in the world trusts your code sample if len(u"🐍")
varies?
So fix the unicode mess
Perl has done that 10 years ago (5.8)
the only one way to do it ever since
Ruby has done that 5 years ago (1.9)
very rubyishly, with each string knowing its own encoding
Python claims to have done that
Another Little Wish
「すべての疑似コードを、生まれる前に消し去りたい」
Errors should never pass silently.
→ The most especially if the error is in the language itself.
"No language is an island"
「島言語なんて、あるわけない」
Zen is not about reading mantra.
Zen is all about practice.
禅は唱えるべきものではありません
禅は為すべきものです
御礼なう
for question in questions:
question.answer