[owncloud-devel] Defensive programming
rmccorkell at karoshi.org.uk
Wed Feb 4 12:32:39 GMT 2015
Agreed, that was just a function I made up on the spot :-) returning an
empty array/object is a much nicer way to go about it, like the Memcache
Null backend I introduced a while ago
> On 4 Feb 2015 12:28, "Jan ten Bokkel" <jan at tenbokkel.net> wrote:
>> A "getListOfThings" function should return an empty list if there is
nothing to get, not false.
>> As Bernhard already states one should try to stick with a single return
type to avoid type conversion Abracadabra.
>> On 04-02-15 13:21, Robin McCorkell wrote:
>>> I feel as though we are in limbo with regards to exceptions. Some code
uses exceptions to report an error, while others return null or false. I
suspect this is one of the reasons why these situations have occurred.
>>> It is my opinion that a function should only return values that make
sense. If a function is named getUser, it should only return the user, and
if it can't that is clearly an error situation where an exception should be
thrown. On the other hand, a function like getListOfThings could viably
return false if there is nothing to get (unless those things are expected
to be there!).
>>> A change to a fully exception based system won't happen overnight, but
it'd be nice to see it promoted more in the code base.
>>> Just my thoughts,
>>> Robin McCorkell
>> Devel mailing list
>> Devel at owncloud.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Devel