Rspec 1.1.4版的新特性
Rspec新版本发布了。来看看它又带来了什么。
hash_including方法,它能让开发者在Mock接受参数时不用指定全部参数,只需要指定应包含某个键值对。示例代码如下:
# before
account.should_receive(:deposit).with({:amount => 37.42, :date => anything()})
# in 1.1.4
account.should_receive(:deposit).with(hash_including(:amount => 37.42))
修正了heckle支持的bug。
stub_model方法出现了,再也不用在View Spec里用mock_model之后,一个一个属性写上去了。这个方法
参考:
http://blog.davidchelimsky.net/articles/2008/05/27/rspec-1-1-4
谷歌开放Google App Engine
http://code.google.com/appengine/
谷歌开放了免费的App Engine,500M的储存空间&5百万的每月PV。看了一下之后是基于Py的,最简单的HelloWorld只要写个输出的Py脚本再用个yaml指定请求的路由处理。如果是需要更加复杂的处理就是要使用谷歌提供的Web框架,其中包装了Django等框架。看来是个不错的机会学习Py和Py的WebApp开发。感觉好像是谷歌开始要推广Py。
在YouTube的视频介绍:
http://www.youtube.com/watch?v=3Ztr-HhWX1c
http://www.youtube.com/watch?v=tcbpTQXNwac
http://www.youtube.com/watch?v=oG6Ac7d-Nx8
http://www.youtube.com/watch?v=oTFL7FPLnXY
http://www.youtube.com/watch?v=JcM2Ejk1tis
http://www.youtube.com/watch?v=K7usoKm5zwE
不知道是不是RP问题,创建时一直提示域名不可用……或许毕业后会去作个Pyer或者Cpper,而不是Rubyist。
试用c.vim
c.vim(C-support)是一个vim插件,C/Cpp开发的助推器,这个系列还有一个lua和Bash的版本。
不废话了,先看看它的主要功能先。
首先是代码模板:
— Statements ———————————————————
\sd do { } while (n,v,i)
\sf for (n,i)
\sfo for { } (n,v,i)
\si if (n,i)
\sif if { } (n,v,i)
\sie if else (n,v,i)
\sife if { } else { } (n,v,i)
\sw while (n,i)
\swh while { } (n,v,i)
\ss switch (n,v,i)
\sc case (n,i)
\s{ { } (n,v,i)
— Preprocessor ——————————————————-
\p< #include <> (n,i)
\p” #include “” (n,i)
\pd #define (n,i)
\pu #undef (n,i)
\pie #if #else #endif (n,v,i)
\pid #ifdef #else #endif (n,v,i)
\pin #ifndef #else #endif (n,v,i)
\pind #ifndef #def #endif (n,v,i)
\pi0 #if 0 #endif (n,v,i)
\pr0 remove #if 0 #endif (n)
— Idioms ————————————————————-
\if function (n,v,i)
\isf static function (n,v,i)
\im main() (n,v,i)
\i0 for( x=0; x<n; x+=1 ) (n,v,i)
\in for( x=n-1; x>=0; x-=1 ) (n,v,i)
\ie enum + typedef (n,i)
\is struct + typedef (n,i)
\iu union + typedef (n,i)
\ip printf() (n,i)
\isc scanf() (n,i)
\ica p=calloc() (n,i)
\ima p=malloc() (n,i)
\isi sizeof() (n,v,i)
\ias assert() (n,v)
\ii open input file (n,i)
\io open output file (n,i)
— Snippets ———————————————————–
\nr read code snippet (n)
\nw write code snippet (n,v)
\ne edit code snippet (n)
\np pick up prototype (n,v)
\ni insert prototype(s) (n)
\nc clear prototype(s) (n)
\ns show prototype(s) (n)
— C++ —————————————————————-
\+c class (n,i)
\+cn class (using new) (n,i)
\+ci class implementation (n,i)
\+cni class (using new) implementation (n,i)
\+mi method implementation (n,i)
\+ai accessor implementation (n,i)
\+tc template class (n,i)
\+tcn template class (using new) (n,i)
\+tci template class implementation (n,i)
\+tcni template class (using new) impl. (n,i)
\+tmi template method implementation (n,i)
\+tai template accessor implementation (n,i)
\+tf template function (n,i)
\+ec error class (n,i)
\+tr try … catch (n,v,i)
\+ca catch (n,v,i)
\+c. catch(…) (n,v,i)
这个表最左边的就是按键,中间就是对应的模板,最后面是对应的模式。n是normal,i就是插入模式,v是虚拟模式。展开的模板放在 ~/.vim/c-support/templates 这里,自己可以hack,比如第一件事就是把Templates中的个人资料改一下。我还把函数声明改了一下,默认是把返回值类型放到上一行,看起来不爽。
然后就是编译链接和运行代码啦,我只用快捷键。
F9 compile and link
Alt-F9 write buffer and compile
Ctrl-F9 run executable
Shift-F9 set command line arguments
Shift-F2 switch between source files and header files
有了这些快捷键之后加上Vim7本身就有的一点点补全功能,其实这个工具也有些IDEful了。
最后看看一些实用功能,比如代码和注释的转化,还有行尾插入注释,插入注释行等等。
— Comments ———————————————————–
\cl end-of-line comment (n,v,i)
\cj adjust end-of-line comment(s) (n,v,i)
\cs set end-of-line comment column (n)
\c* code -> comment /* */ (n,v)
\c/ code -> comment // (n,v)
\cc code -> comment // (n,v)
\co comment -> code (n,v)
\cfr frame comment (n,i)
\cfu function comment (n,i)
\cme method description (n,i)
\ccl class description (n,i)
\cd date (n,i)
\ct date \& time (n,i)
有空试用一下lua-support和bash-support。其实一直想写篇rails.vim的配置和使用和一点点Src分析。
TCppPL中的一段话
这是在B.Stroustrup的TCppPL中Chapter2最后结尾的一段话:
没有一种程序设计语言是完美无缺的。幸运的是,一种程序设计语言不必是完美无缺的,也可以成为构造伟大系统的良好工具。事实上,一种通用的程序设计语言根本不可能对它被用于的所有工作都是最完美的,对一项工作来说最完美的东西对于另外的工作就常常会表现出严重的缺陷,因为在一个领域中的最完美事物实际上也就是意味着专门化。Cpp的设计是想成为构造范围广泛多样的系统的良好工具,而且能够直接表达范围广泛多样的思想。
并不是所有的东西都能直接通过语言的某些内部特征表述。事实上,这也不应该成为一种理想。语言特征的存在是为了支持各种各样的程序设计风格和技术,因此,学习一种语言的工作就应该集中于去把握对该语言而言固有的和自然的风格--而不是去理解该语言所有语言特征的细枝末节。
在实践性的程序设计中,理解语言中最晦涩难懂的语言特征,或者使用最大量的不同特征并不能获得什么利益。把一种特征孤立起来看并没有什么意思,只是在由技术和其他特征所形成的环境里,这一特征才获得了意义和趣味。因此,在阅读后面的章节时请牢记,考察Cpp的各种细节的真实目的在于能够应用它们,在有效的环境里,去支持良好的程序设计风格。
Bjarne真的是一个超人级的人物,很早就看清了程序设计语言的真谛。这段话的意思人人都懂吧。(还有赞叹一下裘掌门的翻译功力)
上次Topcoder的比赛很失败,让我觉着自己。这让我又回过头来再看Cpp的书,看Cpp圣经--TCppPL,看侯Sir的STL剖析。看着Cpp的代码有种亲切的感觉,书中Bjarne写出来的Sample,很优美干练,可读性也非常高。
其实程序设计语言规格到底还是给人来描述现实问题的,描述后让计算机来处理问题,所以能更好地解决问题的语言就是一门不错的语言。RoR最能体现专门化解决问题的思想,Ruby的DSL能力不是盖的。而创造Ruby的这些DSL或者框架的超人们,他们都是掌握了良好程序设计风格的家伙。(说到最后知不到自己在说什么)
无痛体验Rails2.1RC1
无须升级整个系统的Rails,只需要在项目中的Rakefile中加入下面的代码,然后运行rake rails:freeze:edge:
namespace :rails do
namespace :freeze do
desc 'Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0'
task :edge do
require 'open-uri'
version = ENV["RELEASE"] || “edge”
target = “rails_#{version}.zip”
url = “http://dev.rubyonrails.org/archives/#{target}”
chdir ‘vendor’ do
puts “Downloading Rails from #{url}”
File.open(’rails.zip’, ‘wb’) do |dst|
open url do |src|
while chunk = src.read(4096)
dst << chunk
end
end
end
puts ‘Unpacking Rails’
rm_rf ‘rails’
`unzip rails.zip`
%w(rails.zip rails/Rakefile rails/cleanlogs.sh rails/pushgems.rb rails/release.rb).each do |goner|
rm_f goner
end
end
puts ‘Updating current scripts, javascripts, and configuration settings’
Rake::Task['rails:update'].invoke
end
end
end
这段代码其实是Rails2.1里的rails:freeze:edeg的Rake任务代码,因为Rails的代码库已经迁移至github,好像svn不提供新的版本,现在获取Rails最新版本的方法一是到github那里clone下来,要么就到http://dev.rubyonrails.org/archives/下载一个打包好的zip文件。
其实最傻瓜的方法就是直接下载http://dev.rubyonrails.org/archives/rails_edge.zip然后解压到vendor/那里,其实上面贴的rake脚本也是做了这个事情:-)











