2012年7月9日星期一

Dive into python 的 我的翻译 XII


       [原文]P117
Why bother? After all, there are only 3 Dialectizer classes; why not just use a case statement? (Well, there's no case statement in Python, but why not just use a series of if statements?) One reason: extensibility. The translate function has absolutely no idea how many Dialectizer classes you've defined. Imagine if you defined a new FooDialectizer tomorrow; translate would work by passing 'foo' as the dialectName.
[pope译]有什么困扰{bother}?毕竟{after all},这里只有3个Dialectizer classes;为什么不使用case 声明呢?(很好,python 中没有case 声明,那为什么不使用一系列的if 声明呢?)第一个原因:可扩展性{extensibility},此翻译函数完全不了解你定义了多少的Dialectizer类。想象一下,如果明天你定义了一个新的FooDialectize,翻译函数要通过foo作为dialectName 进行工作。

[net 译 来源: http://woodpecker.org.cn/diveintopython/html_processing/all_together.html   ]
何必这么麻烦?毕竟只有三个 Dialectizer 类;为什么不只使用一个 case 语句? (噢,在 Python 中不存在 case 语句,但为什么不只使用一组 if 语句呢?) 理由之一是:可扩展性。这个translate 函数完全不用关心我们定义了多少个方言变换器类。设想一下,如果我们明天定义了一个新的 FooDialectizer 类,把 'foo' 作为 dialectName 传给 translate ,translate 也能工作。

【popexizhi:
先总体表扬一个,直接看自己的这段翻译,倒是没什么直接的郁闷之处,(是看了久了,自己也闻不出异味吗?:)),接着说说细节问题。
1.what  bother ?
整体查了一下,很直接的翻译“何必呢?”:)很自然的句子,我喜欢
自己承认第一问题,第一次看到bother第一反应可是 brother 。:) 我的猜想,一下这两个是有同源的内容吗?go一下
2."if you defined a new FooDialectizer tomorrow;translate would work by passing 'foo' as the dialectName."
这次不是来说翻译内容的,而是说 python的 extensibility的,oo构架的直接问题就是要解决可扩展性的,这里的例子最终目的是对html的tag格式化,理解并处理,这个的到不是python特有的,只是看到想起设计模式的问题插一句,不过倒是引起我的一个兴趣,可以试试GoF的Design pattern, python实现一下,加深自己对他们两个的理解:)
[next] python 版23种design pattern


Even better, imagine putting FooDialectizer in a separate module, and importing it with from module import. You've already seen that this includes it in globals(), so translate would still work without modification, even though FooDialectizer was in a separate file.
[popexizhi译] 更妙的{even better},想象一下放FooDialectizer在一个别的{separate}模块, 使用form module import 导入它。你可以在globals()中看到包含它,所以 翻译函数没有修饰{modification}([?]应该翻译成什么?)依然可以工作,尽管{even though} FooDialectizer 在一个分离文件中。
[net译 来源: http://woodpecker.org.cn/diveintopython/html_processing/all_together.html   ]
甚至会更好。设想将 FooDialectizer 放进一个独立的模块中,使用 from module import 将其导入。我们已经知道了,这样会将它包含在 globals() 中 ,所以不用修改 translate ,它仍然可以正确运行,尽管 FooDialectizer 位于一个独立的文件中。
【popexizhi:
1."modification"
修改,修正的意思,嘻嘻,笑自己一下,上下文联系一下应该猜想出来的:)
2."even better" "even though"
更妙的,即使
这次说的是even 副词 ,这个倒是很表达感情:),很给力的用法。
】    

没有评论:

发表评论