stable-structures icon indicating copy to clipboard operation
stable-structures copied to clipboard

The inconsistency of `init` APIs

Open zhangwei983 opened this issue 1 year ago • 4 comments

The init APIs of StableBTreeMap and StableVec returns inconsistent results:

  1. StableBTreeMap::init returns StableBTreeMap
  2. StableVec::init returns Result<StableVec, InitError> Actually MinHeap also returns a Result.

Looks like StableVec uses the safe_write method which returns a Result.

Should StableBTreeMap::init do the same thing and return a Result?

zhangwei983 avatar Jun 04 '24 15:06 zhangwei983

Is there a specific concern that you have or is it mostly about consistency/uniformity of the APIs?

dsarlis avatar Jun 06 '24 16:06 dsarlis

The (not very good reason) this inconsistency exists is because these structures were written by different authors. The current thinking is to update them to all not return a Result, since the errors returned aren't really recoverable. Would be curious to hear your opinions on this issue.

ielashi avatar Jun 07 '24 09:06 ielashi

Is there a specific concern that you have or is it mostly about consistency/uniformity of the APIs?

It's not a usage issue. For me, it's just a convention or a habit to make the high-level APIs consistent. :)

zhangwei983 avatar Jun 12 '24 04:06 zhangwei983

The (not very good reason) this inconsistency exists is because these structures were written by different authors. The current thinking is to update them to all not return a Result, since the errors returned aren't really recoverable. Would be curious to hear your opinions on this issue.

If it's not recoverable or doesn't expect the users to handle the error, then not returning a Result is a better option IMO.

zhangwei983 avatar Jun 12 '24 04:06 zhangwei983