如何编写更好的代码. [英] How to Write a Better Code.

查看:80
本文介绍了如何编写更好的代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写更好的代码,该代码易于理解且LOC较少.
我的意思是编写代码时必须记住哪些要点.
以及如何针对大多数环境计算代码的可执行时间.
如果我在任何地方都出错,请更正它.

How to Write a Better Code Which is easy to understandable and has less LOC.
I mean What are the Key Point i have to Remember when writing a code.
and how to calculate the executable time of a code in aspect to most Environment.
If I am wrong at anywhere Please Correct it.

推荐答案

通常,更易理解"和更少的代码行"是互斥的.减少代码行通常会降低可读性,从而降低可读性.

没有神奇的公式可以给您编写出色的代码.它是可读性强,风格一致,设计和文档良好以及(通常)遵守标准和最佳实践准则的结合.它的经验可以生成良好的代码,而不是关键点.


从源头看很难计算执行时间-当然,代码行"估计值无济于事:单行代码看似无害,但要花几分钟才能执行:
In general, "more understandable" and "less Lines of Code" are mutually exclusive. Reducing lines of code frequently reduces readability, and thus understandability.

There is no magic formula we can give you to write good code. It''s a combination of a readable, consistent style, with good design and documentation, and (in general) adherence to standards and Best Practice guidelines. It''s experience that makes good code, not Key Points.


It is difficult to calculate execution time from a look at the source - certainly Lines of Code estimate will not help: a single line of code could look innocuous but take minutes to execute:
foreach (MyClass mc in list) mc.Save();



不过,您可以进行衡量-查看 ^ ]



You can measure it though - look at the Stopwatch class[^]


计算代码的可执行时间

在您的应用程序中启用跟踪.它将提供执行时间的详细信息

要了解更多信息,请访问以下网址
http://msdn.microsoft.com/en-us/library/0x5wc973.aspx [ ^ ]

http://msdn.microsoft.com/en-us/library/94c55d08.aspx [ ^ ]
To calculate the executable time of a code

Enable trace in ur application. which will provide the execution time details

To know more about it, visit the following urls
http://msdn.microsoft.com/en-us/library/0x5wc973.aspx[^]

http://msdn.microsoft.com/en-us/library/94c55d08.aspx[^]


这篇关于如何编写更好的代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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