diff --git a/published/20191223 Prioritizing simplicity in your Python code.md b/published/20191223 Prioritizing simplicity in your Python code.md new file mode 100644 index 0000000000..e0760548c7 --- /dev/null +++ b/published/20191223 Prioritizing simplicity in your Python code.md @@ -0,0 +1,63 @@ +[#]: collector: (lujun9972) +[#]: translator: (caiichenr) +[#]: reviewer: (wxy) +[#]: publisher: (wxy) +[#]: url: (https://linux.cn/article-11999-1.html) +[#]: subject: (Prioritizing simplicity in your Python code) +[#]: via: (https://opensource.com/article/19/12/zen-python-simplicity-complexity) +[#]: author: (Moshe Zadka https://opensource.com/users/moshez) + +简单是 Python 编程的第一要则 +====== + +> 本文是 Python 之禅特别系列的第二篇,我们将要关注其中第三与第四条原则:简单与复杂。 + +![](https://img.linux.net.cn/data/attachment/album/202003/15/124150t4wf3wwgdrijx6xx.jpg) + +> "Il semble que la perfection soit atteinte non quand il n'y a plus rien à ajouter, mais quand il n'y plus rien à retrancher." +> +> "It seems that perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away." +> +> “完美并非无可增,而是不可减。” +> +> —Antoine de Saint-Exupéry, [Terre des Hommes][2], 1939 + +编程时最常有的考量是与复杂性的斗争,只想写出让旁人无从下手的繁杂代码,对每个程序员来讲都算不上难事。倘若未能触及代码的简繁取舍,那么 《[Python 之禅][3]》 就有了一角残缺。 + +### 简单胜过复杂Simple is better than complex + +尚有选择余地时,应该选简单的方案。Python 少有*不可为*之事,这意味着设计出巴洛克风格(LCTT 译注:即夸张和不理性)的程序只为解决浅显的问题不仅有可能,甚至很简单。 + +正因如此,编程时应当谨记,代码的简单性是最易丢失,却最难复得的。 + +这意味着,在可以选用函数来表达时不要去引入额外的类;避免使用强力的第三方库往往有助于你针对迫切的问题场景设计更妥当的简短函数。不过其根本的意图,旨在让你减少对将来的盘算,而去着重解决手头的问题。 + +以简单和优美作为指导原则的代码相比那些想要囊括将来一切变数的,在日后要容易修改得多。 + +### 复杂胜过错综复杂Complex is better than complicated + +把握用词的精确含义对于理解这条令人费解的原则是至关重要的。形容某事复杂complex,是说它由许多部分组成,着重组成成分之多;而形容某事错综复杂complicated,则是指其包含着差异巨大、难以预料的行为,强调的是各组成部分之间的杂乱联系。 + +解决困难问题时,往往没有可行的简单方案。此时,最 Python 化的策略是“自底向上bottom-up”地构建出简单的工具,之后将其组合用以解决该问题。 + +这正是对象组合object composition这类技术的闪耀之处,它避免了错综复杂的继承体系,转而由独立的对象把一些方法调用传递给别的独立对象。这些对象都能独立地测试与部署,最终却可以组成一体。 + +“自底建造” 的另一例即是[单分派泛函数][4]singledispatch的使用,抛弃了错综复杂的对象之后,我们得到是简单、几乎无行为的对象以及独立的行为。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/19/12/zen-python-simplicity-complexity + +作者:[Moshe Zadka][a] +选题:[lujun9972][b] +译者:[caiichenr](https://github.com/caiichenr) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/moshez +[b]: https://github.com/lujun9972 +[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/read_book_guide_tutorial_teacher_student_apaper.png?itok=_GOufk6N (Person reading a book and digital copy) +[2]: https://en.wikipedia.org/wiki/Wind,_Sand_and_Stars +[3]: https://www.python.org/dev/peps/pep-0020/ +[4]: https://opensource.com/article/19/5/python-singledispatch diff --git a/translated/tech/20200113 How to setup a DNS server with bind.md b/published/20200113 How to setup a DNS server with bind.md similarity index 72% rename from translated/tech/20200113 How to setup a DNS server with bind.md rename to published/20200113 How to setup a DNS server with bind.md index c659d90dbb..356ea4bf8c 100644 --- a/translated/tech/20200113 How to setup a DNS server with bind.md +++ b/published/20200113 How to setup a DNS server with bind.md @@ -1,18 +1,18 @@ [#]: collector: (lujun9972) [#]: translator: (geekpi) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) +[#]: reviewer: (wxy) +[#]: publisher: (wxy) +[#]: url: (https://linux.cn/article-11997-1.html) [#]: subject: (How to setup a DNS server with bind) [#]: via: (https://fedoramagazine.org/how-to-setup-a-dns-server-with-bind/) [#]: author: (Curt Warfield https://fedoramagazine.org/author/rcurtiswarfield/) -如何使用 bind 设置 DNS 服务器 +简明指南:使用 bind 设置 DNS 服务器 ====== ![][1] -域名系统或 DNS(通常称为 DNS)将域名翻译或转换为与该域关联的 IP 地址。DNS 是能够让你通过名称找到自己喜欢的网站而不是在浏览器中输入 IP 地址的原因。本指南将向你展示如何配置一个主 DNS 系统以及客户端。 +域名系统Domain Name System,我们更通常称为 DNS 的系统,可以将域名翻译或转换为与该域关联的 IP 地址。DNS 是能够让你通过名称找到自己喜欢的网站而不是在浏览器中输入 IP 地址的原因。本指南将向你展示如何配置一个主 DNS 系统以及客户端。 以下是本文示例中使用的系统细节: @@ -23,15 +23,15 @@ client.fedora.local (192.168.1.136)- 客户端 ### DNS 服务器配置 -使用 sudo 安装 bind 包: +使用 `sudo` 安装 bind 包: ``` $ sudo dnf install bind bind-utils -y ``` -_bind_ 包提供了_/etc/named.conf_ 配置文件,来供你配置 DNS 服务器。 +bind 包提供了 `/etc/named.conf` 配置文件,来供你配置 DNS 服务器。 -编辑 _/etc/named.conf_ 文件: +编辑 `/etc/named.conf` 文件: ``` sudo vi /etc/named.conf @@ -61,37 +61,37 @@ allow-query { localhost; }; allow-query { localhost; 192.168.1.0/24; }; ``` -指定转发和反向区域。区域文件只是具有系统上 DNS 信息(例如 IP 地址和主机名)的文本文件。转发区域文件使得将主机名转换为 IP 地址成为可能。反向区域文件则相反。它允许远程系统将 IP 地址转换为主机名。 +指定转发和反向区域。区域文件Zone file就是具有系统上 DNS 信息(例如 IP 地址和主机名)的文本文件。转发区域文件forward zone file使得将主机名转换为 IP 地址成为可能。反向区域文件reverse zone file则相反。它允许远程系统将 IP 地址转换为主机名。 -在 /etc/named.conf 文件的底部查找以下行: +在 `/etc/named.conf` 文件的底部查找以下行: ``` include "/etc/named.rfc1912.zones"; ``` -在此处,你将在_**该行的正上方**_指定区域文件信息,如下所示: +在此处,你将在**该行的正上方**指定区域文件信息,如下所示: ``` zone "dns01.fedora.local" IN { -type master; -file "forward.fedora.local"; -allow-update { none; }; + type master; + file "forward.fedora.local"; + allow-update { none; }; }; zone "1.168.192.in-addr.arpa" IN { -type master; -file "reverse.fedora.local"; -allow-update { none; }; + type master; + file "reverse.fedora.local"; + allow-update { none; }; }; ``` -_forward.fedora.local_ 和 _reverse.fedora.local_ 文件是要创建的区域文件的名称。它们可以是任意名字。 +`forward.fedora.local` 和 `reverse.fedora.local` 文件是要创建的区域文件的名称。它们可以是任意名字。 保存并退出。 #### 创建区域文件 -创建你在 /etc/named.conf 文件中指定的转发和反向区域文件: +创建你在 `/etc/named.conf` 文件中指定的转发和反向区域文件: ``` $ sudo vi /var/named/forward.fedora.local @@ -114,7 +114,7 @@ dns01 IN A 192.168.1.160 client IN A 192.168.1.136 ``` -所有_**粗体**_内容都特定于你的环境。保存文件并退出。接下来,编辑 _reverse.fedora.local_ 文件: +所有**粗体**(LCTT 译注:本译文中无法呈现粗体)内容都特定于你的环境。保存文件并退出。接下来,编辑 `reverse.fedora.local` 文件: ``` $ sudo vi /var/named/reverse.fedora.local @@ -139,11 +139,10 @@ client IN A 192.168.1.136 136 IN PTR client.fedora.local. ``` -所有_**粗体**_内容都特定于你的环境。保存文件并退出。 +所有**粗体**(LCTT 译注:本译文中无法呈现粗体)内容都特定于你的环境。保存文件并退出。 你还需要配置 SELinux 并为配置文件添加正确的所有权。 - ``` sudo chgrp named -R /var/named sudo chown -v root:named /etc/named.conf @@ -174,7 +173,7 @@ $ sudo named-checkzone forward.fedora.local /var/named/forward.fedora.local $ sudo named-checkzone reverse.fedora.local /var/named/reverse.fedora.local ``` -你应该看到 OK 的响应: +你应该看到 “OK” 的响应: ``` zone forward.fedora.local/IN: loaded serial 2011071001 @@ -193,13 +192,13 @@ $ sudo systemctl start named #### 配置 resolv.conf 文件 -编辑 _/etc/resolv.conf_ 文件: +编辑 `/etc/resolv.conf` 文件: ``` $ sudo vi /etc/resolv.conf ``` -查找你当前的 nameserver 行。在示例系统上,调制解调器/路由器充当名称服务器,因此当前看起来像这样: +查找你当前的 `nameserver` 行。在示例系统上,使用调制解调器/路由器充当名称服务器,因此当前看起来像这样: ``` nameserver 192.168.1.1 @@ -213,15 +212,15 @@ nameserver 192.168.1.160 保存更改并退出。 -不幸的是需要注意一点。如果系统重启或网络重启,那么 NetworkManager 会覆盖 _/etc/resolv.conf_ 文件。这意味着你将丢失所做的所有更改。 +不幸的是需要注意一点。如果系统重启或网络重启,那么 NetworkManager 会覆盖 `/etc/resolv.conf` 文件。这意味着你将丢失所做的所有更改。 -为了防止这种情况发生,请将 _/etc/resolv.conf_ 设为不可变: +为了防止这种情况发生,请将 `/etc/resolv.conf` 设为不可变: ``` $ sudo chattr +i /etc/resolv.conf ``` -如果要重新设置并允许其再次被覆盖: +如果要重新设置,就需要允许其再次被覆盖: ``` $ sudo chattr -i /etc/resolv.conf @@ -267,21 +266,21 @@ $ dig fedoramagazine.org ;; MSG SIZE rcvd: 266 ``` -有几件事需要检查以验证 DNS 服务器是否正常运行。显然,取得结果很重要,但这本身并不意味着 DNS 服务器实际上正常工作。 +需要检查几件事以验证 DNS 服务器是否正常运行。显然,取得结果很重要,但这本身并不意味着 DNS 服务器实际上正常工作。 -顶部的 QUERY、ANSWER 和 AUTHORITY 字段应显示为非零,如我们的示例所示: +顶部的 `QUERY`、`ANSWER` 和 `AUTHORITY` 字段应显示为非零,如我们的示例所示: ``` ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 6 ``` -并且 SERVER 字段应有你的 DNS 服务器的 IP 地址: +并且 `SERVER` 字段应有你的 DNS 服务器的 IP 地址: ``` ;; SERVER: 192.168.1.160#53(192.168.1.160) ``` -如果这是你第一次运行 _dig_ 命令,请注意完成查询要花费 830 毫秒的时间: +如果这是你第一次运行 `dig` 命令,请注意完成查询要花费 830 毫秒的时间: ``` ;; Query time: 830 msec @@ -308,7 +307,7 @@ $ dig fedoramagazine.org $ sudo dnf install bind-utils -y ``` -编辑 /etc/resolv.conf 文件,并将主 DNS 配置为唯一的名称服务器: +编辑 `/etc/resolv.conf` 文件,并将主 DNS 配置为唯一的名称服务器: ``` $ sudo vi /etc/resolv.conf @@ -320,7 +319,7 @@ $ sudo vi /etc/resolv.conf nameserver 192.168.1.160 ``` -保存更改并退出。然后,使 _/etc/resolv.conf_ 文件不可变,防止其被覆盖并变回默认设置: +保存更改并退出。然后,使 `/etc/resolv.conf` 文件不可变,防止其被覆盖并变回默认设置: ``` $ sudo chattr +i /etc/resolv.conf @@ -368,7 +367,7 @@ $ dig fedoramagazine.org ;; MSG SIZE rcvd: 266 ``` -确保 SERVER 输出的是你 DNS 服务器的 IP 地址。 +确保 `SERVER` 输出的是你 DNS 服务器的 IP 地址。 你的 DNS 服务器设置完成了,现在所有来自客户端的请求都会经过你的 DNS 服务器了! @@ -379,7 +378,7 @@ via: https://fedoramagazine.org/how-to-setup-a-dns-server-with-bind/ 作者:[Curt Warfield][a] 选题:[lujun9972][b] 译者:[geekpi](https://github.com/geekpi) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/sources/tech/20200312 Make SSL certs easy with k3s.md b/sources/tech/20200312 Make SSL certs easy with k3s.md index 29040a92cd..36f0ca7849 100644 --- a/sources/tech/20200312 Make SSL certs easy with k3s.md +++ b/sources/tech/20200312 Make SSL certs easy with k3s.md @@ -1,5 +1,5 @@ [#]: collector: (lujun9972) -[#]: translator: ( ) +[#]: translator: (wxy) [#]: reviewer: ( ) [#]: publisher: ( ) [#]: url: ( ) diff --git a/translated/tech/20191223 Prioritizing simplicity in your Python code.md b/translated/tech/20191223 Prioritizing simplicity in your Python code.md deleted file mode 100644 index 04b303e702..0000000000 --- a/translated/tech/20191223 Prioritizing simplicity in your Python code.md +++ /dev/null @@ -1,60 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: (caiichenr) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (Prioritizing simplicity in your Python code) -[#]: via: (https://opensource.com/article/19/12/zen-python-simplicity-complexity) -[#]: author: (Moshe Zadka https://opensource.com/users/moshez) - -简单是Python编程的第一要则 -====== -本文是 Python 之禅特别系列的第二篇,我们将要关注其中第三与第四条原则:简单与复杂。 - -![Person reading a book and digital copy][1] - -> "It seems that perfection is finally attained not when there is no longer anything to add, but when there is no longer anything to take away." -> -> “完美并非无可增,而是不可减。” -> -> —Antoine de Saint-Exupéry, _[Terre des Hommes][2]_, 1939 - -编程时最常有的考量是与复杂性的斗争,只想写出让旁人无从下手的繁杂代码,对每个程序员来讲都算不上难事。倘若未能触及代码的简繁取舍,那么 [Python 之禅][3] 就有了一角残缺。 - -### 简单胜过复杂 Simple is better than complex - -尚有选择余地时,应该选简单的方案。Python 少有不可为之事,这意味着设计出巴洛克风格(即夸张和不理性)的程序只为解决浅显的问题不仅有可能,甚至会频繁发生。 - -正因如此,编程时应当谨记,代码的简单性是最易丢失,却最难复得的。 - -这意味着,在可以选用函数来表达时不要去引入额外的类;避免使用第三方库往往有助于你针对问题场景设计更妥当的简短函数。不过其根本的意图,旨在让你减少对将来的盘算,而去着重解决手头的问题。 - -以简单和优美作为指导原则的代码相比那些想要囊括将来一切变数的,在日后要容易修改得多。 - -### 复杂胜过错综复杂 Complex is better than complicated - -把握用词的精确含义对于理解这条令人费解的原则是至关重要的。形容某事复杂 (_complex_),是说它由许多部分组成,着重组成成分之多;而形容某事错综复杂 (_complicated_),则是指其包含着差异巨大、难以预料的行为,强调的是各组成部分之间的杂乱联系。 - -解决困难问题时,往往没有可行的简单方案。此时,最 Python 化的策略是“自底向上”地构建出简单的工具,之后将其组合用以解决该问题。 - -这正是对象组合 (_object composition_) 这类技术的闪耀之处,它避免了错综复杂的继承体系,转而由独立的对象把一些方法调用传递给别的独立对象。这些对象都能独立地测试与部署,最终却可以组成一体。 - -“自底建造” 的另一例即是 [单分派泛函数 (singledispatch)][4] 的使用,抛弃了错综复杂的对象之后,我们得到是简单、几乎无行为的对象以及独立的行为。 - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/19/12/zen-python-simplicity-complexity - -作者:[Moshe Zadka][a] -选题:[lujun9972][b] -译者:[caiichenr](https://github.com/caiichenr) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://opensource.com/users/moshez -[b]: https://github.com/lujun9972 -[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/read_book_guide_tutorial_teacher_student_apaper.png?itok=_GOufk6N (Person reading a book and digital copy) -[2]: https://en.wikipedia.org/wiki/Wind,_Sand_and_Stars -[3]: https://www.python.org/dev/peps/pep-0020/ -[4]: https://opensource.com/article/19/5/python-singledispatch