Python之美



Python之美

Black是一个代码格式化工具,项目上个月刚迁移到Python组织下,意味着这是一个社区认可的项目。项目诞生不久我就点了Star,到现在已经1w+ star了,但是我一直没写文章推荐过它,因为我并不完全认可它。

了解我的人都知道我是非常愿意接受和尝试新鲜事物的,凡是有益于社区的发展我都会支持。好像到现在,除了类型注解我不喜欢以外,其他的我都觉得Ok,包含非常有争议的海象运算符(PEP 572)。

今天闲来无事给大家聊聊这件事,本文不是纯技术文章,更多的是我的个人观点,请按需阅读。

为什么不喜欢

作者给black的定义是「The Uncompromising Code Formatter」,也就是「不妥协的代码格式化程序」。什么意思呢,一句话: 你要听它的,由black按照它的审美帮助你处理代码格式问题。black的格式化规则是PEP8的超集,也就是除了处理成符合PEP8规范要求的代码,也有black的一些规则。

说到这里让我想到了Golang的gofmt工具: Golang的开发团队制定了统一的官方代码风格,使用官方的gofmt帮助开发者格式化他们的代码到统一的风格。虽然这样降低了自由度,但是极大的节省了开发者对于代码风格的纠结,争论等等,现在写Go代码时我会在编辑器配置保存时自动格式化,我非常喜欢这么用。


Read full article from Python之美


No comments:

Post a Comment

Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts