html tool

2015年3月17日星期二

Dive into Python 的我的翻译------Chapter 15. Refactoring VI [15.2. Handling changing requirements IV]

Example 15.8. Coding the new requirements

  •        1.toRoman only needs one small change, in the range check. Where you used to check 0 < n < 4000, you now check 0 < n < 5000. And you change the error message that you raise to reflect the new acceptable range (1..4999 instead of 1..3999). You don't need to make any changes to the rest of the function; it handles the new cases already. (It merrily adds 'M' for each thousand that it finds; given 4000, it will spit out 'MMMM'. The only reason it didn't do this before is that you explicitly stopped it with the range check.)
    [pope译]toRoman 仅需要在范围检查中做一个小的改变。在你使用0 2.You don't need to make any changes to fromRoman at all. The only change is to romanNumeralPattern; if you look closely, you'll notice that you added another optional M in the first section of the regular expression. This will allow up to 4 M characters instead of 3, meaning you will allow the Roman numeral equivalents of 4999 instead of 3999. The actual fromRoman function is completely general; it just looks for repeated Roman numeral characters and adds them up, without caring how many times they repeat. The only reason it didn't handle 'MMMM' before is that you explicitly stopped it with the regular expression pattern match
    [pope译]
    你不需要为fromRoman做任何改变。唯一要变的是romanNumeralPattern;如果你仔细看{look closely}你会主要到在正则表达式的第一块{section}加入一个M.这样允许4个M代替3个M,这意味着你将允许罗马字符4999来替代3999.这个实际上{actual}fromRoman函数是完全可以的{completely general};它仅寻找替代的罗马字符并将其拼装起来,不关心{caring}替换了多少次.之前唯一没有打出'MMMM'的原因是你在正则表达执行匹配式停止了它.
    You may be skeptical that these two small changes are all that you need. Hey, don't take my word for it; see for yourself:
    [pope译]
    你可能怀疑{skeptical} 你只要做两个小的改变。嗨,别看这个,注意你自己的
    [popexizhi]这个 don't take your word for it,see for yourself.可以这样翻译吗?
  •  Example 15.9. Output of romantest72.py against roman72.py
    • All the test cases pass. Stop coding.
      Comprehensive unit testing means never having to rely on a programmer who says "Trust me."
      [pope译]
      所有的测试用例通过了,停止编码。
      完整的单元测试意味着从没有依赖{rely on}编程者说"相信{trust}我"    
        

没有评论:

发表评论