pdf
|<<
<
>
>>|
/
Recap for The Art of Naming ---- {{#ci|Recap}} for The Art of {{#x|Naming}} “{{#x|命名}}”课回顾 ☺{{#author|agentzh (章亦春)}}☺ {{#date|2006.10}} ---- To {{#ci|simplify}} a class interface, use of {{#x|inheritance}} is {{#ci|deprecated}}. 若想简化类的接口, 则不应使用继承。 ---- A {{#ci|bad}} example in {{#c|perl 5}} ⇒ ---- {{img src="#" width="0" height="0"}} {{img src="images/gd.png" width="357" height="623"}} ---- {{#cm|# This works:}} {{#kw|use}} GD::Simple; {{#kw|my}} {{#v|$img}} = {{#kw|new}} GD::Simple(40, 50); {{#v|$img}}->bgcolor({{#x|'white'}}); {{#v|$img}}->fgcolor({{#x|'red'}}); {{#v|$img}}->rectangle(10, 10, 50, 50); ---- {{#cm|# But this doesn't work, since}} {{#cm|# setPixel is a method derived}} {{#cm|# directly from GD::Image}} {{#kw|use}} GD::Simple; {{#kw|my}} {{#v|$img}} = {{#kw|new}} GD::Simple(40, 50); {{#v|$img}}->bgcolor({{#x|'white'}}); {{#v|$img}}->fgcolor({{#x|'red'}}); {{#v|$img}}->setPixel(10, 10, {{#x|'red'}}); ---- {{#cm|# We have to degrade to the harder way:}} {{#kw|use}} GD::Simple; {{#kw|my}} {{#v|$img}} = {{#kw|new}} GD::Simple(40, 50); {{#kw|my}} {{#v|$red}} = {{#v|$img}}->{{#x|colorAllocate}}(255, 0, 0); {{#v|$img}}->setPixel(10, 10, {{#x|$red}}); ---- {{#cm|# The Perl 5 way:}} {{#x|print}} \"hello, world!\\n\"; +{{#ci|5}} characters ---- {{#cm|# The Perl 6 way:}} {{#x|say}} \"hello, world!\"; +{{#ci|3}} characters ---- {{#ci|☺}} That's the {{#x|Huffman}} coding {{#ci|principle}} 这正是哈夫曼编码原理。 ---- ✓ {{#x|Rant}} on the software vendors and show them where the {{#x|technology}} {{#ci|really}} wants to go! 向那些软件商怒吼, 并向他们指出技术真正想去的地方! ---- {{img src="images/rant.jpg" width="198" height="190"}} ---- {{#x|Broad}} background knowledge is {{#ci|very}} important to {{#ci|good}} programmers. 宽广的背景知识对于好的程序员来说 是非常重要的。 ---- {{img src="images/eiffel.jpg" width="176" height="350"}} {{img src="images/pyramid.jpg" width="446" height="351"}} ---- {{#cm|<agentzh>}} yeah {{#cm|<agentzh>}} audreyt++ # you seem to know {{#ci|everything}}. {{#cm|<audreyt>}} nah, not really :) {{#cm|<agentzh>}} hehe {{#cm|<audreyt>}} that's what you get from spending far too much time on {{#x|wikipedia}}... {{#cm|<agentzh>}} ah, {{#x|wikipedia}}++ <章亦春> 是 <章亦春> 唐凤++ # 你似乎知道所有的事情 <唐凤> 才不是呢 :) <章亦春> 呵呵 <唐凤> 这是在 wikipedia 网站上花费了很多时间的结果…… <章亦春> 啊,wikipedia++ ---- {{#tag|☺}} Understanding the {{#ci|culture}} behind the technology is very {{#x|important}}. 理解技术背后的文化是很重要的。 ---- The {{#ci|culture}} of {{#x|Windows}} feels like... {{#tag|♨}} Windows 的文化就感觉像…… ---- {{img src="images/fashion.jpg" width="288" height="423"}} ---- While the {{#ci|culture}} of {{#x|UNIX}} feels like... {{#tag|♨}} 而 UNIX 的文化就感觉像…… ---- {{img src="images/wizard.jpg" width="351" height="419"}} ---- {{#x|Java}} gives me the {{#ci|feeling}} like... {{#tag|♨}} Java 给我的感觉就像是…… ---- {{img src="images/java.jpg" width="294" height="339"}} ---- {{#x|Perl}} gives me the {{#ci|feeling}} like... {{#tag|♨}} Perl 给我的感觉就像是…… ---- {{img src="images/perl.jpg" width="243" height="312"}} ---- The {{#ci|top}} 3 {{#x|jumps}} in my programming learning {{#ci|curve}} {{#cm|⇒}} 我的编程学习曲线中的三次飞跃 {{#cm|⇒}} ---- {{#tag|☆}} {{#ci|OOP}} (Object-Oriented Programming) {{#bdate|2001.2}} {{#t|C++, Java, C#, encapsulation}} + {{#tag|☆}} {{#ci|Dynamic}} Programming {{#bdate|2002.9}} {{#t|Perl, Awk, regexes, the UNIX culture}} + {{#tag|☆}} {{#ci|TDD}} (Test-Driven Development) {{#bdate|2004.4}} {{#t|C# NUnit, Perl's Test::More, Pugs}} ---- The {{#t|potential}} {{#x|4th}} jump at present: + {{#tag|☆}} {{#ci|Functional}} Programming {{#bdate|2006.?}} {{#t|Haskell, CPS, Perl 6}} ---- {{#tag|☺}} A small {{#ci|perlish}} {{#x|TDD}} example in C/C++ {{#cm|⇒}} C/C++ 中的一个 perl 风味的 测试驱动的示例 {{#cm|⇒}} ---- {{#cm|/* adder.h */}} {{#kw|#ifndef}} _ADDER_H_ {{#kw|#define}} _ADDER_H_ {{#kw|int}} add({{#kw|int}} a, {{#kw|int}} b); {{#kw|#endif}} ---- {{#cm|/* adder.cpp */}} {{#kw|#include}} \"adder.h\" {{#kw|int}} add({{#kw|int}} a, {{#kw|int}} b) { {{#cm|// doesn't do anything useful right now:}} {{#x|return 0;}} } ---- {{#cm|/* test_adder.cpp #/}} {{#kw|#include}} \"{{#x|adder.h}}\" {{#kw|#include}} \"{{#x|cpptest.h}}\" {{#kw|int}} main() { {{#x|plan}}(3); {{#x|is_}}(add(1, 2), 3, \"1 + 2 == 3\"); {{#x|is_}}(add(-2,1), -1, \"-2 + 1 == -1\"); {{#x|is_}}(add(3,-3), 0, \"3 + (-3) == 0\"); {{#x|summary}}(); {{#kw|return}} 0; } ---- {{img src="images/test_adder.png" width="469" height="443"}} ---- {{img src="images/tdd1.png" width="668" height="351"}} ---- {{#tag|D:\\projects>}}test_adder {{#x|1..3}} {{#x|not ok 1}} - 1 + 2 == 3 # Failed test (test_adder.cpp at {{#ci|line 6}}) # '{{#ci|0}}' # ne # '3' {{#x|not ok 2}} - -2 + 1 == -1 # Failed test (test_adder.cpp at {{#ci|line 7}}) # '{{#ci|0}}' # ne # '-1' {{#x|ok 3}} - 3 + (-3) == {{#ci|0}} # Looks like you failed 2 tests of 3. ---- {{#tag|☺}} The first 2 tests failed {{#ci|as expected}}~~~ 前 2 个测试如期失败~~~ ---- {{#tag|☺}} Now it's time to {{#ci|actually}} implement the {{#x|add}} function. 现在是真正给出 add 函数的实现的时候了。 ---- {{#cm|/* adder.cpp */}} {{#kw|#include}} \"adder.h\" {{#kw|int}} add({{#kw|int}} a, {{#kw|int}} b) { {{#cm|// now we add the functionality:}} {{#x|return a + b;}} } ---- {{#tag|☺}} Now let's {{#x|rebuild}} the project and {{#ci|rerun}} the tests... 现在让我们来重新生成项目 并再次运行测试…… ---- {{img src="images/tdd2.png" width="668" height="351"}} ---- {{#tag|D:\\projects>}}test_adder {{#x|1..3}} {{#x|ok 1}} - 1 + 2 == 3 {{#x|ok 2}} - -2 + 1 == -1 {{#x|ok 3}} - 3 + (-3) == 0 ---- Write {{#x|test}}... ...watch test {{#x|fail}}. Write {{#cm|code}}... ...watch test {{#cm|pass}}. {{#cm|Refactor}}... ...watch test {{#cm|pass}}. Write {{#x|test}}... ...watch test {{#x|fail}}. Write {{#cm|code}}... ...watch test {{#cm|pass}}. {{#cm|Refactor}}... ...watch test {{#cm|pass}}. ... ---- 编写{{#x|测试}}…… ……观察测试{{#x|失败}}。 编写{{#cm|代码}}…… ……观察测试{{#cm|通过}}。 {{#cm|重构}}…… ……观察测试{{#cm|通过}}。 编写{{#x|测试}}…… ……观察测试{{#x|失败}}。 编写{{#cm|代码}}…… ……观察测试{{#cm|通过}}. {{#cm|重构}}…… ……观察测试{{#cm|通过}}。 …… ---- {{#ci|Get}} my {{#x|slides}}! {{http://agentzh.org/misc/slides/naming_recap.pdf}} ---- {{#x|Contact}} me on the {{#ci|web}}! {{#c|♨}} {{agentzh@gmail.com}} ---- These slides are {{#ci|powered}} by {{#x|Sporx}} and {{img src="images/grin.png" width="41" height="41"}}{{#ci|Takahashi}}{{#x|++}} ---- {{#c|Thank you!}} ☺