html tool

2015年3月18日星期三

Dive into Python 的我的翻译------Chapter 15. Refactoring VII [15.3.Refactoring I]

The best thing about comprehensive unit testing is not the feeling you get when all your test cases finally pass, or even the feeling you get when someone else blames you for breaking their code and you can actually prove that you didn't. The best thing about unit testing is that it gives you the freedom to refactor mercilessly.
[pope译]

       完整的单元测试的最大好处,不是当你测试用例全部通过测试的感觉;甚至也不是有人指责{blames}你引起他的代码问题{breaking their code}时 ,你可以证明你没有;单元测试带给你最好的事情是你可以自由的狠狠的{mercilessly}重构你的代码。    

Refactoring is the process of taking working code and making it work better. Usually, "better" means "faster", although it can also mean "using less memory", or "using less disk space", or simply "more elegantly". Whatever it means to you, to your project, in your environment, refactoring is important to the long-term health of any program.
[pope译]

       重构在使用中代码的过程是使其工作得更好,一般来说,"更好"意味着"更快",尽管{although}它可能也意味这着"使用更少的内存",或者“使用更少的磁盘空间”,或者更简单“更加优雅{elegantly}”.无论在你的环境中它对你和你的项目意味着什么,重构对任何程序的长期健康{long-term health}都很重要。

 Here, "better" means "faster". Specifically, the fromRoman function is slower than it needs to be, because of that big nasty regular expression that you use to validate Roman numerals. It's probably not worth trying to do away with the regular expression altogether (it would be difficult, and it might not end up any faster), but you can speed up the function by precompiling the regular expression.
[pope译]
这里,"更好"意味着"更快"。特别是{specifically},这个fromRoman函数比需要的慢,由于这个大而不好的是用来确定{validate}罗马字符的正则表达式.它可能并不值得尝试去除在一起的正则表达(这个可能有点儿难,并且它可能还没更快点儿),但你可以通过预编译{precompiling}这个正则表达式来达到提速这个函数。     

没有评论:

发表评论