Hacker News new | past | comments | ask | show | jobs | submit login

Another best practice: Please do not use logging as an excuse to avoid implementing proper error propagation in libraries or utility code.

Bad:

  void something_failable(void *data) {
    if (!is_valid(data)) {
      log_err("invalid data"); 
    }
    
    /* ... */
  }
Less bad:

  int something_failable(xxx_t *ctx, void *data) {
    if (!is_valid(data)) {
      return xxx_err(ctx, "invalid data"); 
    }
    
    /* ... */
  }



Another best practice, don't write logic to deal with BUGS but instead assert.

Bad:

  int something_failable(xxx_t *ctx, void *data) {
    if (!is_valid(data)) {
      return xxx_err(ctx, "invalid data"); 
    }

    /* ... */
  }
Less bad:

  int something_failable(xxx_t *ctx, void *data) {
    ASSERT(is_valid(data));

    /* ... */
  }


Maybe "is_valid" is checking the validity of externally-provided/third party data, that is, it being invalid is a problem, but its not a bug.


If it's failable, it's not a bug.


A fair point, but where is the evidence it applies here?




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: