软件工程

本类阅读TOP10

·PHP4 + MYSQL + APACHE 在 WIN 系统下的安装、配置
·Linux 入门常用命令(1)
·Linux 入门常用命令(2)
·使用 DCPROMO/FORCEREMOVAL 命令强制将 Active Directory 域控制器降级
·DirectShow学习(八): CBaseRender类及相应Pin类的源代码分析
·基于ICE方式SIP信令穿透Symmetric NAT技术研究
·Windows 2003网络负载均衡的实现
·一网打尽Win十四种系统故障解决方法
·数百种 Windows 软件的免费替代品列表
·收藏---行百里半九十

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
rules of thumb!

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

  • To conserve resources, be selective in the choice of data type to ensure the size of a variable is not excessively large.
  • Keep the lifetime of variables as short as possible when the variables represent a finite resource for which there may be contention, such as a database connection.
  • Keep the scope of variables as small as possible to avoid confusion and to ensure maintainability. Also, when maintaining legacy source code, the potential for inadvertently breaking other parts of the code can be minimized if variable scope is limited.
  • Use variables and routines for one and only one purpose. In addition, avoid creating multipurpose routines that perform a variety of unrelated functions.
  • When writing classes, avoid the use of public variables. Instead, use procedures to provide a layer of encapsulation and also to allow an opportunity to validate value changes.
  • When using objects pooled by MTS, acquire resources as late as possible and release them as soon as possible. As such, you should create objects as late as possible, and destroy them as early as possible to free resources.
  • When using objects that are not being pooled by MTS, it is necessary to examine the expense of the object creation and the level of contention for resources to determine when resources should be acquired and released.
  • Use only one transaction scheme, such as MTS or SQL Server™, and minimize the scope and duration of transactions.
  • Be wary of using ASP Session variables in a Web farm environment. At a minimum, do not place objects in ASP Session variables because session state is stored on a single machine. Consider storing session state in a database instead.
  • Stateless components are preferred when scalability or performance are important. Design the components to accept all the needed values as input parameters instead of relying upon object properties when calling methods. Doing so eliminates the need to preserve object state between method calls. When it is necessary to maintain state, consider using alternative methods, such as maintaining state in a database.
  • Do not open data connections using a specific user's credentials. Connections that have been opened using such credentials cannot be pooled and reused, thus losing the benefits of connection pooling.
  • Avoid the use of forced data conversion, sometimes referred to as variable coercion or casting, which may yield unanticipated results. This occurs when two or more variables of different data types are involved in the same expression. When it is necessary to perform a cast for other than a trivial reason, that reason should be provided in an accompanying comment.
  • Develop and use error-handling routines. For more information on error handling in Visual Basic, see the "Error Handling and Debugging" chapter of the Microsoft Office 2000/Visual Basic Programmer's Guide, available in the MSDN Library. For more information on error handling and COM, see "Error Handling" in the Platform SDK. For more information on error handling for Web pages, see http://msdn.microsoft.com/workshop/author/script/weberrors.asp.
  • Be specific when declaring objects, such as ADODB.Recordset instead of just Recordset, to avoid the risk of name collisions.
  • Require the use Option Explicit in Visual Basic and VBScript to encourage forethought in the use of variables and to minimize errors resulting from typographical errors.
  • Avoid the use of variables with application scope.
  • Use RETURN statements in stored procedures to help the calling program know whether the procedure worked properly.
  • Use early binding techniques whenever possible. For more information on early versus late binding, see "A Primer on Early Binding (or How to Make OLE Automation Faster)."
  • Use Select Case or Switch statements in lieu of repetitive checking of a common variable using If…Then statements.
  • Explicitly release object references.



相关文章

相关软件