• python哲学


     1 import this
     2 
     3 The Zen of Python, by Tim Peters
     4 # python的设计哲学, 作者:Tim Peters
     5 
     6 Beautiful is better than ugly.
     7 # 优雅胜于丑陋(Python 以编写优美的代码为目标)
     8 
     9 Explicit is better than implicit.
    10 # 明确胜于含糊晦涩(优美的代码应当是明了的,命名规范,风格相似)
    11 
    12 Simple is better than complex.
    13 # 简单胜于复杂(优美的代码应当是简洁的,不要有复杂的内部实现)
    14 
    15 Complex is better than complicated.
    16 # 复杂胜于凌乱(如果复杂不可避免,那代码间也不能有难懂的关系,要保持接口简洁)
    17 
    18 Flat is better than nested.
    19 # 扁平胜于嵌套(优美的代码应当是扁平的,不能有太多的嵌套)
    20 
    21 Sparse is better than dense.
    22 # 间隔胜于紧凑(优美的代码有适当的间隔,不要奢望一行代码解决问题)
    23 
    24 Readability counts.
    25 # 可读性很重要(优美的代码是可读的)
    26 
    27 Special cases aren't special enough to break the rules.
    28 # 即便假借特例的实用之名,也不应打破这些原则(这些规则至高无上)
    29 
    30 Although practicality beats purity.
    31 # 尽管实践大于理论
    32 
    33 Errors should never pass silently.
    34 # 错误不可置之不理,除非你确定需要这样做(精准地捕获异常,不写 except:pass 风格的代码)
    35 
    36 Unless explicitly silenced.
    37 # 除非另有明确要求
    38 
    39 In the face of ambiguity, refuse the temptation to guess.
    40 # 面对模棱两可(有歧义),拒绝猜测
    41 
    42 There should be one-- and preferably only one --obvious way to do it.
    43 # 而是尽量找一种,最好是唯一一种容易的解决方案(如果不确定,就用穷举法)
    44 
    45 Although that way may not be obvious at first unless you're Dutch.
    46 # 虽然这种方式开始时并不容易,除非你是 Python之父(这里的 Dutch 是指 Guido )
    47 
    48 Now is better than never.
    49 # 但从现在就开始这么做,总比永远都不做好
    50 
    51 Although never is often better than *right* now.
    52 # 尽管经常有时 “没有做” 反倒比 “现在立马做“ 结果要好
    53 
    54 If the implementation is hard to explain, it's a bad idea.
    55 # 如果一个实现不容易解释,那么它肯定是个坏主意
    56 
    57 If the implementation is easy to explain, it may be a good idea.
    58 # 如果一个实现很容易解释,那么它也许是个好主意
    59 
    60 Namespaces are one honking great idea -- let's do more of those!
    61 # 就像命名空间就是一个绝妙的想法,应当多加利用
  • 相关阅读:
    腾讯开源 APIJSON 连创五个第一
    最火的分布式 HTAP 数据库 TiDB
    完爆Facebook/GraphQL,APIJSON全方位对比解析(三)-表关联查询
    后端自动化版本管理,再也不用改URL了!
    后端开挂:3行代码写出8个接口!
    3步创建服务端新表及配置
    Activity猫的一生-故事解说Activity生命周期
    APIJSON-以坚持和偏执,回敬傲慢和偏见
    APIJSON,让接口和文档见鬼去吧!
    Android 100多个Styles快速开发布局XML,一行搞定View属性,一键统一配置UI...
  • 原文地址:https://www.cnblogs.com/linkenpark/p/10968830.html
Copyright © 2020-2023  润新知