Re: [Vala] "checked vs unchecked exceptions" && API design guidelines for Vala



Thomas Chust wrote:
My personal opinion is that no matter what type of exceptions is used,
your alternative #3 is the most readable and logical way of doing it,
since peeking at an empty stack is not really an error of any kind. A
peek operation is precisely intended to check whether something is empty
and to possibly also return an element if it is not. This should be
represented by an appropriate return type, for example with a boolean
return and an output parameter or with a polymorphic return type that
can either hold a value or represent the absence of one.

Thanks for the reply (and also thanks to Fredrik), both replies made
excellent points and I certainly understand this issue more in depth now.

In the end I opted for alternative #3 and besides your arguments
I also noted that this alternative makes it possible to implement the
API in a thread safe way should this be desired. There will always be
a potential race between checking .Length and doing .peek() so it
seems like a good habit to favor trypeek instead of peek by default.


                Martin



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]