性能与可读性/可维护性 [英] performance vs. readability/maintability

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

问题描述

在我参与的另一个在线小组中,我们讨论了特定的一段代码,这些代码在打破

的未来风险很高(因为它取决于那些没有改变的东西,而不是开发人员的控制范围之外的东西,但性能略高一些。一位参与者

发布:


"我倾向于采取表演轨道,如果影响

isn,则增加可读性太棒了然而,即使在

软件领域也会发生奇怪的现实。不确定我能解释得太好但只是简单地说,

如果你编写代码来处理改变

a字段的序数位置的影响,还是会出现一些其他错误。


我觉得这很危险。


我知道这是一些意见问题,但我只是想知道

,其中每个人都落在连续统一体上。

In another online group in which I participate, we were discussing a
particular piece of code that had a pretty high risk for breaking in the
future (because it depended on something not changing that was outside the
developer''s control) but was slightly more performant. One participant
posted:

"I tend to take the performance track also, adding readability if the impact
isn''t too great. There is also an odd reality that takes place even in the
software field however. Not sure I can explain it too well but simply said,
if you write code to handle the effects of changing the ordinal position of
a field, some other error will surface anyway."

which I found to be ridiculous to the point of being dangerous.

I know this is somewhat one of those opinion issues, but I just wondered
where everyone fell on the continuum.

推荐答案

就我个人而言,我更愿意编写代码'首先是可读的和可维护的

(在一些

场景中,模块明显的性能胜过StringBuilder和DataReader)。代码工作后,使用分析器查找性能

瓶颈。话虽如此,我经常为此目的建造原型

的性能分析。这是我的经验,大多数人在没有分析的情况下,在错误的地方进行优化并且有一些不可维护的代码而且没有可维护的代码。


-

Mickey Williams

作者,Microsoft Visual C#.NET核心参考,MS Press
www.servergeek.com

" Daniel Billingsley" <分贝********** @ NO.durcon.SPAAMM.com>在消息中写道

新闻:e5 ************** @ TK2MSFTNGP11.phx.gbl ...
Personally, I prefer to write code that''s readable and maintainable first
(modulo obvious perf wins like StringBuilder and DataReader in some
scenarios). After the code works, use a profiler to look for performance
bottlenecks. Having said that, I''ve often built prototypes for the purpose
of profiling perf . It''s my experience that most people that obsess over
perf without profiling optimize in the wrong places and have butt-ugly
non-maintainable code.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com
"Daniel Billingsley" <db**********@NO.durcon.SPAAMM.com> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
在另一个在线组中我参与其中,我们正在讨论一个特定的代码片段,这些代码具有很高的风险,可以打破未来(因为它取决于那些不会改变的东西,而不是开发人员''控制)但性能略高。一位与会者发布了:

我倾向于采用性能跟踪,如果
影响不是太大,则增加可读性。然而,即使在软件领域的
中也存在奇怪的现实。不确定我能解释得太好但只是
表示,如果你编写代码来处理改变字段的序数位置
的影响,那么其他一些错误也会浮出水面。

我觉得这很危险,这很荒谬。

我知道这有些意见问题,但我只是想知道
每个人都在连续统一体上。
In another online group in which I participate, we were discussing a
particular piece of code that had a pretty high risk for breaking in the
future (because it depended on something not changing that was outside the
developer''s control) but was slightly more performant. One participant
posted:

"I tend to take the performance track also, adding readability if the impact isn''t too great. There is also an odd reality that takes place even in the software field however. Not sure I can explain it too well but simply said, if you write code to handle the effects of changing the ordinal position of a field, some other error will surface anyway."

which I found to be ridiculous to the point of being dangerous.

I know this is somewhat one of those opinion issues, but I just wondered
where everyone fell on the continuum.



对于它的价值我几乎总是站在可靠性的一边。我讨厌修改代码,特别是当我代表我做出错误的决定时。我想b / b
假设我的情况下某些代码绝对必须运行

更快(show-stopper),并且修改是克服这个问题的唯一方法

行,可靠性问题不是随机的,而是维护问题,

(如果表结构发生变化,只有一个bug),以及可靠性问题

不会比跑得太慢造成更大的伤害..


那么也许我会在会议中提起它,这样我的同事就可以了b / b $ b告诉我它。


问候


" Daniel Billingsley" <分贝********** @ NO.durcon.SPAAMM.com>在消息中写道

新闻:e5 ************** @ TK2MSFTNGP11.phx.gbl ...
For what it''s worth I would almost always side with reliability. I hate
fixing code, especially when it''s due to a bad decision on my behalf. I
suppose that if I were in a situation where some code absolutely had to run
faster (show-stopper), and the modification was the only way to get over the
line, and the reliability problem was not random, but a maintenance issue,
(only a bug if the table structure changes), and the reliability problem
would not cause more damage than running too slow..

Then maybe I would bring it up in a meeting, just so that my coworkers could
talk me out of it.

Regards

"Daniel Billingsley" <db**********@NO.durcon.SPAAMM.com> wrote in message
news:e5**************@TK2MSFTNGP11.phx.gbl...
在另一个在线组中我参与其中,我们正在讨论一个特定的代码片段,这些代码具有很高的风险,可以打破未来(因为它取决于那些不会改变的东西,而不是开发人员''控制)但性能略高。一位与会者发布了:

我倾向于采用性能跟踪,如果
影响不是太大,则增加可读性。然而,即使在软件领域的
中也存在奇怪的现实。不确定我能解释得太好但只是
表示,如果你编写代码来处理改变字段的序数位置
的影响,那么其他一些错误也会浮出水面。

我觉得这很危险,这很荒谬。

我知道这有些意见问题,但我只是想知道
每个人都在连续统一体上。
In another online group in which I participate, we were discussing a
particular piece of code that had a pretty high risk for breaking in the
future (because it depended on something not changing that was outside the
developer''s control) but was slightly more performant. One participant
posted:

"I tend to take the performance track also, adding readability if the impact isn''t too great. There is also an odd reality that takes place even in the software field however. Not sure I can explain it too well but simply said, if you write code to handle the effects of changing the ordinal position of a field, some other error will surface anyway."

which I found to be ridiculous to the point of being dangerous.

I know this is somewhat one of those opinion issues, but I just wondered
where everyone fell on the continuum.



Daniel Billingsley< db ********** @ NO.durcon.SPAAMM.com>写道:


< snip>
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote:

<snip>
我知道这有些意见问题,但我只是想知道
哪里每个人都落在连续统一体上。
I know this is somewhat one of those opinion issues, but I just wondered
where everyone fell on the continuum.




因为我怀疑很多读者已经知道了,我会编写可读性代码

,性能稍晚,几乎总是。


话虽如此,我当然会使用StringBuilder在循环过程中创建一个

字符串等。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要给我发邮件



As I suspect many readers know already, I would code for readability
first, performance later, almost always.

Having said that, I will of course use a StringBuilder to create a
string over the course of a loop etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


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

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