python代码该怎么简化_如何评价Python为简化代码而简化代码的行为?

谢邀

“为简化代码而简化代码”有点质疑动机了,这点是不可取的

当然我理解题主的意思,有可能代码看着简化了,但实际没什么x用,甚至还降低了可读性,那肯定会让原来代码的编写者有点恼怒了

代码写得好不好,是很主观的,有的人追求行数少,有的人追求命名长,有的人追求让别人看不懂,甚至还有人刻意追求圈复杂度高……不过英雄所见略同,你只有通过大量阅读源代码,尤其是知名项目和大牛的源代码才能感受到符合社会认同的逼格层次来。这个时候你就更能下定决心,对于修改你代码的人是尊敬还是唾弃了

Python有一个极大的好处,即社区认同比较一致,大家称之为pythonic,对代码的审美和评价也相对固定,对题主是个好消息。假若是C++或perl,我是断不敢回答此题,也不敢与人就代码审美做争吵的。怎么做是所谓的pythonic,最简单的是import this

The Zen of Python, by Tim Peters

Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Complex is better than complicated.

Flat is better than nested.

Sparse is better than dense.

Readability counts.

Special cases aren't special enough to break the rules.

Although practicality beats purity.

Errors should never pass silently.

Unless explicitly silenced.

In the face of ambiguity, refuse the temptation to guess.

There should be one-- and preferably only one --obvious way to do it.

Although that way may not be obvious at first unless you're Dutch.

Now is better than never.

Although never is often better than *right* now.

If the implementation is hard to explain, it's a bad idea.

If the implementation is easy to explain, it may be a good idea.

Namespaces are one honking great idea -- let's do more of those!

然后对照着去看看requests/celery/flask等知名项目的代码。然后再回过头来看看,现在修改你代码的人的简化到底是有没有意义的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值