@@ -966,7 +966,7 @@ msgstr ""
966
966
967
967
#: ../../faq/design.rst:556
968
968
msgid "How do you specify and enforce an interface spec in Python?"
969
- msgstr ""
969
+ msgstr "如何在 Python 中指定和強制使用一個介面規範 (interface spec)? "
970
970
971
971
#: ../../faq/design.rst:558
972
972
msgid ""
@@ -975,6 +975,8 @@ msgid ""
975
975
"module. Many feel that compile-time enforcement of interface specifications "
976
976
"helps in the construction of large programs."
977
977
msgstr ""
978
+ "像是 C++ 和 Java 等語言提供了模組的介面規範,他描述了該模組的方法和函式的原"
979
+ "型。很多人認為這種在編譯時強制執行的介面規範在建構大型程式時十分有幫助。"
978
980
979
981
#: ../../faq/design.rst:563
980
982
msgid ""
@@ -985,12 +987,18 @@ msgid ""
985
987
"`~collections.abc.Iterable`, :class:`~collections.abc.Container`, and :class:"
986
988
"`~collections.abc.MutableMapping`."
987
989
msgstr ""
990
+ "Python 2.6 加入了 :mod:`abc` 模組,讓你可以定義抽象基底類別 (Abstract Base "
991
+ "Classes, ABCs)。你可以使用 :func:`isinstance` 和 :func:`issubclass` 來確認一"
992
+ "個實體 (instance) 或是類別是否實作了某個抽象基底類別。而 :mod:`collections."
993
+ "abc` 模組定義了一系列好用的抽象基底類別,像是 :class:`~collections.abc."
994
+ "Iterable`、:class:`~collections.abc.Container` 和 :class:`~collections.abc."
995
+ "MutableMapping`。"
988
996
989
997
#: ../../faq/design.rst:570
990
998
msgid ""
991
999
"For Python, many of the advantages of interface specifications can be "
992
1000
"obtained by an appropriate test discipline for components."
993
- msgstr ""
1001
+ msgstr "對 Python 來說,很多介面規範的優點可以用對元件適當的測試規則來達到。 "
994
1002
995
1003
#: ../../faq/design.rst:573
996
1004
msgid ""
@@ -1003,6 +1011,11 @@ msgid ""
1003
1011
"be used to construct exhaustive test suites that exercise every line of code "
1004
1012
"in a module."
1005
1013
msgstr ""
1014
+ "一個針對模組的好測試套件提供了回歸測試 (regression testing),並作為模組介面規"
1015
+ "範和一組範例。許多 Python 模組可以直接當成腳本執行,並提供簡單的「自我測"
1016
+ "試」。即便模組使用了複雜的外部介面,他依然可以用外部介面的簡單的「樁」(stub) "
1017
+ "模擬來獨立測試。:mod:`doctest` 和 :mod:`unittest` 模組或第三方的測試框架可以"
1018
+ "用來建構詳盡徹底的測試套件來測試模組裡的每一行程式碼。"
1006
1019
1007
1020
#: ../../faq/design.rst:581
1008
1021
msgid ""
@@ -1014,6 +1027,11 @@ msgid ""
1014
1027
"test that your :meth:`append` implementation will actually do this "
1015
1028
"correctly, but it's trivial to check this property in a test suite."
1016
1029
msgstr ""
1030
+ "就像介面規範一樣,一個適當的測試規則在建造大型又複雜的 Python 應用程式時可以"
1031
+ "幫上忙。事實上,他可能可以有更好的表現,因為介面規範無法測試程式的特定屬性。"
1032
+ "舉例來說,:meth:`append` 方法應該要在某個內部的串列最後面加上新的元素,而介面"
1033
+ "規範沒辦法測試你的 :meth:`append` 是不是真的有正確的實作,但這在測試套件裡事"
1034
+ "件很簡單的事。"
1017
1035
1018
1036
#: ../../faq/design.rst:589
1019
1037
msgid ""
@@ -1023,6 +1041,9 @@ msgid ""
1023
1041
"write any of the actual code. Of course Python allows you to be sloppy and "
1024
1042
"not write test cases at all."
1025
1043
msgstr ""
1044
+ "撰寫測試套件相當有幫助,而你會像要把程式碼設計成好測試的樣子。測試驅動開發 "
1045
+ "(test-driven development) 是一個越來越受歡迎的設計方法,他要求先完成部分的測"
1046
+ "試套件,再去撰寫真的要用的程式碼。當然 Python 也允許你草率地不寫任何測試。"
1026
1047
1027
1048
#: ../../faq/design.rst:597
1028
1049
msgid "Why is there no goto?"
0 commit comments