Sat 29 March, 2008


- 说明
- Waves 是一款很有前途的Ruby语言网络软件框架。它是一种全新的思维,而不是简单的模仿;集成当前最好的软件包,而不是轻易的纳入;不仅注意软件开发的细节,更重要的是以软件全局为出发点。
- 相关报道
add to del.icio.us. look up in del.icio.us.
add to furlFri 28 March, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
不知道算是幸运,还是不幸,我参与的多数项目,如果不是从头开始,我也是最开始加入的几个人之一,所以,我通常对项目的来龙去脉都比较清楚。这次,我有机会尝试一下在一头雾水的情况下开始一个项目。
这个项目已经进行了超过一个月,因为客户需要在赶在最近的一次发布之前,增加一些功能。老板按照目前的进度估算了一下,如果不加人,这个任务很难完成,于是客户很合作的同意增加两个人。就这样,我成了临时工。事实上,在这个阶段进入,项目早就过了最初的阶段,远远望去,没有几百也有几十的程序文件屹立在那里。虽然有最熟悉项目的人为我们介绍了项目的背景和架构,但这些宏观层面上的东西,对于编写代码这样“微观”的操作而言,几乎是没有任何直接的帮助。作为一个新人加入到项目,除了发呆,我还能做什么呢?
回想在以前公司的情形,大多数新进项目的人多半是得到一大堆文档,然后,有人语重心长的说,先把文档看了吧!且不说这些文档这种东西几乎写出来就过时,单单读完这些文档就需要花费很多时间。运气好的话,还有代码可以对应,但千万不要指望你能够一下子读懂这些代码。也许,你会想找别人来问,如果不出意外,大多数人都会不明就里的非常忙,忙到有时间上网聊天却没有时间给你讲这些东西。事实上,很多人即便自己做了很多东西,也不一定能够清晰的描述出来,所以,即便找到一个“闲”人,成功从他那弄明白这些东西的概率也很低。其结果是,我们经常会看到一些人在那对着电脑上的文档发呆。
在ThoughtWorks,我也恨不得找到一堆这样的无聊文档来打发时间,以此来享受偷懒的时光。遗憾的是,完全没有这种机会。因为那些“文档”会被视为浪费,这在以消除浪费为己任的敏捷来看,是无论如何不能接受的。于是,我在找不到任何借口的情况下,进入项目的第一天,就开始写程序了。不了解项目,怎么写程序?这是个问题。
敏捷实践中,有一个叫做Pair Programming的,从字面上来看,就是两个人一起开发。对于ThoughtWorker们来说,Pair是一种常态。所以,我在开发时也会有一个Pair,虽然我对项目一头雾水,但我的Pair已经在这个项目上工作了很长一段时间,所以,他很清楚这个项目的一切,差不多一切,因为代码是集体所有,所以,他在开发过程中会接触到各个部分。
拿到我们要做的Story,我的Pair会结合这个Story给我介绍上下文,并结合代码大致描述一下我们要做的事情。虽然在这个项目上我是新手,但我并不是对编程一无所知。有了这些基本的信息,我至少对我们要做什么,以及如何来做,在心里已经形成了一个大致的印象。刚开始时,基本上是我的Pair在主导开发,一边做一边告诉我,我们已经走到了哪里。渐渐的,我已经对我们在做的代码有了一些认识,开发也开始由一个人主导转向两个人讨论。随着开发的深入,我也发现了现有做法的一些不足,于是,我提出对代码进行重构,并给出了自己的分析和建议。我的Pair在听了之后,认为这是一个可行的建议,于是,我们毫不留情的将那段大家看着不舒服的代码改掉,这段代码从此清净了。
这就是在加入项目前几天所做的事情,虽然我目前还不能对整个项目有个很好的把握,但是,我相信,我已经开始在这个项目中起作用了。我想,Pair Programming是主要原因。正如前面所说,虽然我对项目很无知,但我的Pair很好的弥补了我的不足。正是两个人的协调工作,让我可以在对项目没有完整认识的情况下,可以很快入门,以最快的速度融入到开发之中。
曾几何时,我对Pair Programming的认识还停留在大家一起写程序和知识分享上,原来它对半路出家的人帮助也很大。虽然《人月神话》教导我们说,加人起不了很大的作用,但Pair的方式至少可以在相当大的程度上发挥新人的价值,削弱加人带来的负面影响。
add to del.icio.us. look up in del.icio.us.
add to furl
- 视频说明
- 在这个视频中,Apple公司展示了iPhone SDK及其所开发iPhone软件,同时也说明了iPhone软件营销模式,这种模式将会给软件业的未来带来什么。
- iPhone手机的SDK视频
add to del.icio.us. look up in del.icio.us.
add to furlThu 27 March, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
Hongli and crew from Phusion have been hard at work for some time to fix the ease-of-deployment issue on Apache with their Passenger project. They now have a video that demos how simple it’ll be to install and get running with mod_rails. Check it out.
add to del.icio.us. look up in del.icio.us.
add to furl
We’re shaking up the Rails core group a bit. First, please welcome Pratik Naik as the newest member of the group.
He’s been doing great work all around the framework and has been spearheading both the documentation branch in git and a thorough cleanup of Action View internals. We’re really happy to hand him the commit keys to the repository.
Second, we’ve created the Rails core alumni for all the proud members of the core group who are no longer in the day-to-day improvement of the framework itself. All of the alumni are still busy working in the Ruby on Rails ecosystem, but either have their hands full with their business or has dedicated their open source time to other initiatives.
We’re incredibly grateful for all the works you guys have done for Ruby on Rails over the years. And you’re all welcome back in the active core group any time you decide. Thanks guys!
Finally, this means that the current active core group is about half its former size. We’d like to add a few more to that, so hopefully we can pick a few more people who’ve been doing varied work on the framework for a sustained period of time soon.
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furlWed 26 March, 2008

add to del.icio.us. look up in del.icio.us.
add to furlTue 25 March, 2008

One Lair and Twenty Ruby DSLs
Implementing an Internal DSL
上面几个文章都是关于DSL的,不过,在这里,我并不是太关心DSL的话题,我更感兴趣的是代码的写法。按照这几篇的分类方法,直接用程序设计语言编写的DSL算是内部DSL,也就是说,所谓内部DSL,也就是一种标准的程序代码。
Kent Beck在他的《Implementation Patterns》的第三章《A Theory Of Programming》中,谈到了编程的价值观(Value):Communication(沟通)、Simplicity(简单)和Flexibility(灵活)。如果说简单和灵活很容易理解的话,那么把沟通放在价值观中,尤其排在所有价值观的第一位,则显现出Kent Beck对于编程的深刻。在这个软件开发越来越需要协作的年代,写代码的时候,多站在让别人理解的角度考虑一下,会极大提升代码的可读性。在ThoughtWorks的招聘流程中,有一个Code Review的环节,拜这个环节所赐,我看过很多人的代码,不在少数的应聘者其代码唯一的优点就是完成了需求。以沟通为标准进行衡量,这显然是不够的。
同样,以沟通为标准,那么内部DSL显然在这方面做得更好,因为DSL本身就是为了让人更容易理解而存在的。这几篇文章中提供了很多内部DSL的手法,比如Method Chaining、Expression Builder等等。抛开DSL这样的BuzzWord,这些方法应该属于增强程序本身表达能力的方法。
JDK有一个很好的Method Chaining的例子:StringBuffer的append方法。
StringBuffer sb = new StringBuffer();
sb.append("log1").append("log2").append("log3");
这样的写法显然比下面的写法更为简洁,尤其是需要往StringBuffer中添加很多内容的时候。
StringBuffer sb = new StringBuffer();
sb.append("log1");
sb.append("log2");
sb.append("log3");
在我看来,这些内部DSL技术为我们打开了一扇窗,它让我们在编写代码,尤其作为API提供的代码时,有了一个新的思考方向。当然,并不是一味的应用这些内部DSL技术就会写出好代码,作为一个有经验的软件开发人员,我们需要一定的鉴别能力,分辨出究竟怎样做才会真正的提高代码的“沟通”能力。
之前写过两篇关于程序设计语言表达的blog(1、2),虽然这篇不像那两篇一样讨论语言的差异,但也算是在语言表达能力上的探讨吧!
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
A small plea to people writing code generator tools.
If you have a tool that creates, say, an application skeleton, like this:
$ wooblegen appname
please do not blindly process an argument of “help”.
A few times I’ve forgotten the options to one or another tool, invoked it with an argument of ‘help’, and ended up with a boatload of directories and files, none of which were very helpful.
The correct behavior would be to scold the user (such as myself) , explaining that the standard invocation would be possibly -h or --h or -help or -H, but not, you know, help. Then give a choice to generate stuff or get help.
add to del.icio.us. look up in del.icio.us.
add to furl
I received some feedback on the ‘Presenting Code’ post from yesterday.
Presenting Code … An Update
I got lots of feedback on the “Presenting Code” post. In addition to Cédric Beust’s initial comments, the following people had something to say on the topic:
John Wilger asked on Twitter why I didn’t use “file:” (rather than “http:” and a local web server). Unfortunately, Keynote will not do a web view from a “file:” style URL.
Luke Kanies reports that he does something similar. He uses Vim (rather than Ruby + the Syntax gem) to generate the highlighted HTML. He also adds:
In general, this method works out great, but the one thing I would say is that you should always uncheck “automatic update”. Otherwise, you’ll find that it tries to update 10 seconds before your presentation starts and your web server isn’t available.
Ok, that’s good advice. BTW, I would be very interested in a script (AppleScript or Ruby+OSA) that would iterate over the pages in a Keynote presentation and refresh all the WebViews. Any takers?
James Edward Gray II and Mike Clark mentioned the HTML output bundle. James gives the following details:
- Select Bundles → TextMate → Create HTML From Document (or Create HTML From Document With Line Numbers, if you prefer)
- Preview the document in TextMate with Window ⇢ Show Web Preview
- Highlight and Edit → Copy the content you want from the HTML window
- Switch to Keynote and Edit → Paste
Mike (who credits Bruce Williams as his source for this tip) also provided a video.
Couple of items on the above:
- When creating the HTML from the document, convert the whole document. Once in Web Preview mode you can cut and paste only what you want.
- Choose a TextMate theme with a background that matches the background in your presenetation to get the best effect for your colors.
Dr. Nic also mentions a “Copy as RTF” TextMate bundle. (I’m not sure if this is the same as James and Mike’s hint above or something different).
Finally, Chris Nelson confirms (via Twitter): “AFAIK there is no equivalent of web views in OpenOffice :(“
add to del.icio.us. look up in del.icio.us.
add to furlMon 24 March, 2008

Tomorrow I’m going to leave early for Seelbach deep in the Black Forest where I’ll spend the rest of the week educating myself on civil service (which I finished for two thirds already, but hey, who cares).
Anarchaia and chris blogs will resume publishing Saturday, March 29.
Please notice that this means I will not be able to attend Euruko 2008 in Prague this year. That’s sad, but I can’t help it (not that I’d have anything to talk about). Enjoy the program.
Regarding conferences, I am planning to go to the Workshop on Self-sustaining Systems in May and RailsConf Europe in September (I hope there will be a CabooseConf Europe, really).
I expect to have occasional Internet access in Seelbach, else mail will have to wait. It’s my first travel with the EEE.
NP: Grateful Dead—Promised Land
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
软件命令行解说:解决GnuWin32在Windows Vista上的问题
- 问题说明
在Windows Vista上使用 GnuWin32 ,会出现缺少一些动态软件包,如 libintl3.dll 、 libiconv.dll、 pcre3.dll 等。 - 解决方法
- 下载以下相关的动态软件包文件(这是为GnuWin32)
http://surfnet.dl.sourceforge.net/sourceforge/gnuwin32/libiconv-1.9.2-1-bin.zip
https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/test/libintl3.dll?rev=7872&format=raw - 下载以下相关的动态软件包文件(这是为命令grep)
http://garr.dl.sourceforge.net/sourceforge/gnuwin32/pcre-7.0-bin.zip - 把这些软件包dll文件存放到 GnuWin32 或者 grep 根目录下的目录bin中,如果需要解压的话先解压。
- 下载以下相关的动态软件包文件(这是为GnuWin32)
add to del.icio.us. look up in del.icio.us.
add to furlSun 23 March, 2008

add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furl
This exchange on twitter got me thinking…
Twittering …
I noticed the following twitter conversation this evening between objo and superchris:
superchris: any good recommendations on showing code samples in OpenOffice Impress?
objo: @superchris yeah, get a mac and use Keynote
objo: otherwise, I would screenshot emacs
superchris: @objo.. ya know, i almost added “And I’ll smack anyone who says get a Mac” but ran out of space
superchris: @objo… but actually your idea of using NetBeans screenshots is pretty good
objo: @superchris you never listen …. EMACS not netbeans. Come on man.
superchris: @objo just being helpful by translating for you.. :)
superchris: planning to code with NetBeans on linux forever for no other reason but to annoy @objo
ScreenShots … Yuck!
The problem Chris is trying to solve is putting code snippets into a presentation. There just isn’t a good way to do this in modern presentation programs.
In the old days, I would generate my presentation completely in HTML from a simple text markup file. The generation process was controlled by rake. This allowed me to changed the code, run the unit tests and rebuild the presentation all with a simple rake command. Eventually, I got up to speed with CSS and could make some really nice looking presentations, all from HTML.
Although I could get nice looking slides with CSS, it was a lot of work getting it to work just so. Eventually, I abandoned that approach and swithed to a modern slide presentation program (Keynote in my case).
Although generating the slides is a bit easier in Keynote (or PowerPoint, or Open Office Impress), reproducing code for technical talks is much harder. You generally have two choices:
- Cut and paste the code text into Keynote losing any syntax highlighting you might have had, or
- Take a screen shot of the code in your fancy editor, preserving the syntax highlighting but losing the “text” nature of the code.
Neither option is pleasant. The former punishes the audience by making the code harder to read, the latter punishes you making the presentation hard to change. (I once saw Dave Thomas giving a Ruby talk and he noticed that he had a minor typo in the code. He switched to edit mode in Keynote with the intent of fixing it on the spot, then he realized that the code was in a graphic image and was uneditable).
Of the two options, I’ve been using the text cut’n’paste technique for most things. In the twitter conversation above, Chris is considering the edit snapshot technique.
Other Options?
I’ve heard rumors of someone working on a script that will insert code snippets into the Keynote data file directly. Unfortunately, as far as I know, they are still rumors at this time.
But here’s another idea. I’ve prototyped this, and think it will work. But be warned I haven’t tried this on a really presentation yet.
Presenting Code … A Proof of Concept
While perusing the options in Keynote, I noticed an insert option called “Web View”

It turns out that this option allows you to include a web page in your presentation. For example, here is my blog inserted directly into the presentation. Clicking on the “web view” object will show an “update” button that will refresh that page from the web.

So, all I have to do is get the code onto a web page, formatted nicely with syntax highlighting, and Keynote will suck it into the presentation, more or less automatically for me. Cool.
Getting it formatted is easy. That’s just a small little Rake task
with a good syntax highlighting library. I used Syntax (its a gem,
docs on Rubyforge), but there are other options out there.
Here’s the rakefile:
#!/usr/bin/env ruby
require "rake/clean"
CLOBBER.include('*.html')
task :default => :extract
task :extract => "hello.html"
file "hello.html" => "hello.rb" do
extract "hello.html", "hello.rb"
end
and here is the rakelib/extract.rake library:
#!/usr/bin/env ruby
require 'syntax/convertors/html'
def extract(outfile, infile)
open(outfile, "w") do |out|
out.puts "<html>"
out.puts " <head>"
out.puts " <style type=\"text/css\">"
out.puts %(
.ruby { font-size: 24pt; font-weight: bold; }
.ruby .normal {}
.ruby .comment { color: #888; font-style: italic; }
.ruby .keyword { color: #A00; font-weight: bold; }
.ruby .method { color: #077; }
.ruby .class { color: #074; }
.ruby .module { color: #050; }
.ruby .punct { color: #447; font-weight: bold; }
.ruby .symbol { color: #099; }
.ruby .string { color: #944; }
.ruby .char { color: #F07; }
.ruby .ident { color: #004; }
.ruby .constant { color: #07F; }
.ruby .regex { color: #B66; }
.ruby .number { color: #D55; }
.ruby .attribute { color: #377; }
.ruby .global { color: #3B7; }
.ruby .expr { color: #227; })
out.puts " </style>"
out.puts " </head>"
out.puts " <body>"
out.puts " <pre class=\"ruby\">"
code = open(infile) { |f| f.read }
convertor = Syntax::Convertors::HTML.for_syntax("ruby")
html = convertor.convert(code)
out.puts html
out.puts " </pre>"
out.puts " </body>"
out.puts "</html>"
end
end
Edit the CSS styles above to tweek the output to exactly the colors you want. I’ve added a large font-size line to make the code big enough for teh presentation (I hate small code fonts in presentations, you can ask objo about my rants on that topic.)
Now we need to get the code on a web page. No need to get fancy here.
I have a script called servefiles that will start a webrick process
that serves files from the current directory. Just start it up with
“servefiles 3333” (the 3333 is the port to use). Servefiles will
display its URL in its startup message, like so:
$ servefiles 3333 URL: http://tardis.local:3333 [2008-03-23 00:47:37] INFO WEBrick 1.3.1 [2008-03-23 00:47:37] INFO ruby 1.8.6 (2008-03-03) [i686-darwin9.2.0] [2008-03-23 00:47:37] INFO WEBrick::HTTPServer#start: pid=874 port=3333
Here’s the code for servefiles:
#!/usr/bin/env ruby
require 'webrick'
include WEBrick
dir = Dir::pwd
port = (ARGV.first || (12000 + (dir.hash % 1000))).to_i
puts "URL: http://#{Socket.gethostname}:#{port}"
s = HTTPServer.new(
:Port => port,
:DocumentRoot => dir
)
trap("INT"){ s.shutdown }
s.start
Now all we have to do is cut and paste the URL given by servefiles
into keynote and append the HTML file name we wish to add to our
presentation:

Now, to update the code in the presentation, I need to:
- Edit the original code base (and run unit tests against it).
- Run rake
- Press the “Update Now” button in Keynote.
Not bad.
It’s Just a Proof of Concept
Just be warned, I haven’t tried this in a real presentation yet. I’ve just spent an hour or so seeing if all the pieces would work together. There are some obvious things to explore.
- The extraction code could be enhanced to pull snippets from files based on tags. Or even better, being able to say “Extract Method m from Class C”.
- I’m using a fixed font size, but extract could easily take the font size as an argument or even calculate the proper font size given the amount of text found in the snippet.
- I’ve not played with the “Update automatically” checkbox in the Keynote dialog. I’m not sure when it automatically updates, but it is possible that using it might mean you don’t even need step three above.
I will probably experiment some more with then in my next code heavy presentation. Let me know if you try this and how it work for you.
UPDATE
Cédric Beust points out that cutting and pasting from Eclipse to PowerPoint does preserve syntax highlighting. I verified the same is true for Eclipse and Keynote. However all the other IDEs and editors I tried (NetBeans, Coda, TextMate, Emacs) will paste as plain, uncolored text in Keynote. So, if you are going the cut and paste route, you might want to consider using Eclipse for the cut source.
Just for kicks I tried the presentation software in OpenOffice with the same result. Eclipse copies will preserve highlighting, none of the others will.
So, there you have it.
add to del.icio.us. look up in del.icio.us.
add to furl
add to del.icio.us. look up in del.icio.us.
add to furlSat 22 March, 2008

As I reported two days ago, after I installed Safari 3.1, my MiddleClickClose extension stopped working. Well, I've gotten it working again, but it doesn't load under Safari < 3.1. So, only install this version if you are using Safari 3.1. If you are using an older Safari, use this one.
- Binary — MiddleClickClose-Safari3.1.zip
- Source — MiddleClickClose-Safari3.1-Src.zip
As before, I'm releasing this under the GPL.
add to del.icio.us. look up in del.icio.us.
add to furl

