主页 » WEB开发 » 简单的代码易于调试

简单的代码易于调试

2008-05-13添加留言

今天看一篇英文博客 [url=http://porteightyeight.com/archives/151-9-PHP-Debugging-Techniques-You-Should-Be-Using.html]9 PHP Debugging Techniques You Should Be Using[/url] ——《你应当会用的九种PHP调试技术》。在最后一条,也提到了简单的代码一般更健壮。对于PHP,写简单代码的方法是:

[quote]Keep Things Simple:
1. [b]Keep an eye on functions that are growing[/b]. You may find that you can split the code into several smaller functions.
2. [b]Functions that are only called in one place may be too specific[/b]. You can either bring the code inline, or generalise using several smaller functions. You can always keep the specific function and just use that to call and aggregate the new, smaller, functions.
3. Watch out for [b]functions with very long names or lots of arguments[/b]. This can be a sign that the function could be split into several smaller functions, or it could even be replaced with a class.
4. [b]Use built in functions where possible[/b]. This will help avoid spurious amounts of PHP code and there is a good chance the internal function will be faster as it is written in C (and by the pros!) Some of the most underappreciated internal functions are the array functions.
5. If you really must have long and complex sections of code, then make sure you [b]add some documentation[/b]. You and your fellow developers will be thankful of this when it comes to debugging. [/quote]

No related posts.

以上关联文章由 Yet Another Related Posts Plugin 提供支持。

相关文章

发表评论