Hello,

I'm trying to understand when it is recommended to return a Status
instance and use an out parameter for the result value, vs. when it is
allowed to return the result value naturally.

For instance we currently have the following methods on the Schema class:

  Status AddField(int i, const std::shared_ptr<Field>& field,
                  std::shared_ptr<Schema>* out) const;

  std::shared_ptr<Schema> AddMetadata(
      const std::shared_ptr<const KeyValueMetadata>& metadata) const;

The only reason the Status return is used in `Schema::AddField()` is
when the user passes an invalid column index `i`, a condition which is
usually only checked via the debug mode assertions DCHECK_*.

On the one hand, returning the result value results (!) in more natural
code, both in the callee and in the caller.  On the other hand,
returning a Status allows for finer-grained error reporting later on.

Regards

Antoine.

Reply via email to