zoukankan      html  css  js  c++  java
  • 编写函数的12个参考意见

    1. Make use of return values to communicate information and to make error trapping easy for the calling program.
      用好返回值,使得错误处理简单一些。
    2. Do not exit from functions. Instead, return an error value to allow the calling program flexibility in handling the error.
      不要在函数中使用exit,明确的返回错误码,让caller来决定到底怎么办。
    3. Make functions general but usable. (Sometimes these are conflicting goals.)
      既通用,又好用。
    4. Do not make unnecessary assumptions about sizes of buffers. (This is often hard to implement.)
      不要对输入buffer的长度做不必要的架设。
    5. When it is necessary to use limits, use standard system-defined limits rather than arbitrary constants.
      尽可能使用系统的limits
    6. Do not reinvent the wheel—use standard library functions when possible.
      尽可能使用标准库
    7. Do not modify input parameter values unless it makes sense to do so.
      尽可能不要修改输入参数
    8. Do not use static variables or dynamic memory allocation if automatic allocation will do just as well.
      如果自动变量就能搞定,不要用static变量。
    9. Analyze all the calls to the malloc family to make sure the program frees the memory that was allocated.
      看好malloc,避免泄露。
    10. Consider whether a function is ever called recursively or from a signal handler or from a thread. Functions with variables of static storage class may not behave in the desired way. (The error number can cause a big problem here.)
      在函数被递归调用,或反复调用的情况下,static变量的存在,将会导致不可预期的行为。
    11. Analyze the consequences of interruptions by signals.
      要把signal的中断考虑进来。
    12. Carefully consider how the entire program terminates.
      小心处理程序的退出。
  • 相关阅读:
    Spring之IOC、AOP和事务
    Spring Aware接口
    ReentrantLock原理
    基于AnnotationConfigApplicationContext的容器创建过程(Spring Version 5.2.0)
    基于AnnotationConfigApplicationContext的Bean加载过程(Spring Version 5.2.0)
    Future和CompletableFuture
    ThreadLocal原理
    Oracle 11g R2 数据库卸载教程
    Oracle 11g R2 数据库安装教程
    SQL Server 2017数据库卸载教程
  • 原文地址:https://www.cnblogs.com/ohscar/p/3109634.html
Copyright © 2011-2022 走看看