手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>Java技术>列表

Progamming style guidelines

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

http://home.earthlink.net/~huston2/books/programming_books.html

The Practice of Programming
Brian Kernighan, Rob Pike

Style
  1. Use descriptive names for globals, short names for locals.
  2. Be consistent.
  3. Use active names for functions.
  4. Be accurate.
  5. Indent to show structure.
  6. Use the natural form for expressions.
  7. Parenthesize to resolve ambiguity.
  8. Break up complex expressions.
  9. Be clear.
  10. Be careful with side effects.
  11. Use a consistent indentation and brace style.
  12. Use idioms for consistency.
  13. Use else-ifs for multi-way decisions.
  14. Avoid function macros.
  15. Parenthesize the macro body and arguments.
  16. Give names to magic numbers.
  17. Define numbers as constants, not macros.
  18. Use character constants, not integers.
  19. Use the language to calculate the size of an object.
  20. Don't belabor the obvious.
  21. Comment functions and global data.
  22. Don't comment bad code, rewrite it.
  23. Don't contradict the code. Clarify, don't confuse.
Interfaces
  1. Hide implementation details.
  2. Choose a small orthogonal set of primitives.
  3. Don't reach behind the user's back.
  4. Do the same thing the same way everywhere.
  5. Free a resource in the same layer that allocated it.
  6. Detect errors at a low level, handle them at a high level.
  7. Use exceptions only for exceptional situations.
Debugging
  1. Look for familiar patterns.
  2. Examine the most recent change.
  3. Don't make the same mistake twice.
  4. Debug it now, not later.
  5. Get a stack trace.
  6. Read before typing.
  7. Explain your code to someone else.
  8. Make the bug reproducible.
  9. Divide and conquer.
  10. Study the numerology of failures.
  11. Display output to localize your search.
  12. Write self-checking code.
  13. Write a log file.
  14. Draw a picture.
  15. Use tools.
  16. Keep records.
Testing
  1. Test code at its boundaries.
  2. Test pre- and post-conditions.
  3. Use assertions.
  4. Program defensively.
  5. Check error returns.
  6. Test incrementally.
  7. Test simple parts first.
  8. Know what output to expect.
  9. Verify conservation properties.
  10. Compare independent implementations.
  11. Measure test coverage.
  12. Automate regression testing.
  13. Create self-contained tests.
Performance
  1. Automate timing measurements.
  2. Use a profiler.
  3. Concentrate on the hot spots.
  4. Draw a picture.
  5. Use a better algorithm or data structure.
  6. Enable compiler optimizations.
  7. Tune the code.
  8. Don't optimize what doesn't matter.
  9. Collect common subexpressions.
  10. Replace expensive operations by cheap ones.
  11. Unroll or eliminate loops.
  12. Cache frequently-used values.
  13. Write a special-purpose allocator.
  14. Buffer input and output.
  15. Handle special cases separately.
  16. Precompute results.
  17. Use approximate values.
  18. Rewrite in a lower-level language.
  19. Save space by using the smallest possible data type.
  20. Don't store what you can easily recompute.
Portability
  1. Stick to the standard.
  2. Program in the mainstream.
  3. Beware of language trouble spots.
  4. Try several compilers.
  5. Use standard libraries.
  6. Use only features available everywhere.
  7. Avoid conditional compilation.
  8. Localize system dependencies in separate files.
  9. Hide system dependencies behind interfaces.
  10. Use text for data Exchange.
  11. Use a fixed byte order for data exchange.
  12. Change the name if you change the specification.
  13. Maintain compatibility with existing programs and data.
  14. Don't assume ASCII.
  15. Don't assume English.

The Elements of Programming Style
Brian Kernighan, P. J. Plauger

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!