性能与可读性 [英] Performance vs Readability

查看:43
本文介绍了性能与可读性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读这个问题我发现这是(注意引号)代码"来解决问题(顺便说一下,这是 perl).

Reading this question I found this as (note the quotation marks) "code" to solve the problem (that's perl by the way).

100,{)..3%!'Fizz'*\5%!'Buzz'*+\or}%n*

显然,这是一个没有实际意义的智力示例(我希望永远不会在我生活中的真实代码中看到),但是,当您必须做出选择时,您何时会为了性能而牺牲代码可读性?你是否只是运用常识,你是否总是把它作为最后的手段?你的策略是什么?

Obviously this is an intellectual example without real (I hope to never see that in real code in my life) implications but, when you have to make the choice, when do you sacrifice code readability for performance? Do you apply just common sense, do you do it always as a last resort? What are your strategies?

对不起,看到答案我可能把问题表达得很糟糕(英语不是我的母语).我的意思不是说性能与可读性只是在您编写代码之后,我也在您编写代码之前询问.有时,您可以通过进行一些更暗的设计或提供一些使您的类更暗的属性来预见未来的性能改进.您可能决定使用多个线程或仅使用一个线程,因为您期望此类线程可能为您提供可扩展性,即使这会使代码更难以理解.

I'm sorry, seeing the answers I might have expressed the question badly (English is not my native language). I don't mean performance vs readability only after you've written the code, I ask about before you write it as well. Sometimes you can foresee a performance improvement in the future by making some darker design or providing with some properties that will make your class darker. You may decide you will use multiple threads or just a single one because you expect the scalability that such threads may give you, even when that will make the code much more difficult to understand.

推荐答案

我认为性能可能成为问题的情况下的流程:

My process for situations where I think performance may be an issue:

  1. 让它发挥作用.
  2. 说清楚.
  3. 测试性能.
  4. 如果存在有意义的性能问题:重构以提高速度.

请注意,这不适用于在后期更难更改的更高级别的设计决策.

Note that this does not apply to higher-level design decisions that are more difficult to change at a later stage.

这篇关于性能与可读性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆