Follow

For some reason when I write methods with a complex sequence/flow, I always stumble into these choices:

- Do I assert the input or do I merely document the method's API contract?
- Do I create specific exceptions for out-of-scope edge cases or return null or an empty array/collection/stream/iterable/etc.?

How do I determine what values I should take into consideration when making a choice?

Should there be a convention for each of these, in the programming language or platform or the project?

@dammkewl I think it depends on the purpose of the function (or the project). Explicitly failing on edge cases gives a more predictable behavior which (IMHO) is usually to be preferred. Documenting the precise behavior is also fine but might still leave the door open for abusive use of the API.

Sign in to participate in the conversation
Bitcoin Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!