Well, it looks like this poll is split down the middle.
NGRhodes":agretst6 said:I have been told numerous times by various people and see it written numerous times that it is best for a method to return null when there is no data, why should the split method of a string object be any different ?
I have been told numerous times by various people and see it written numerous times that it is best for a method to return null when there is no data
fitten":2kbs7lbc said:^^ Also, null and a string of length zero are not the same thing.
NGRhodes":ggc8lbd0 said:If the table is missing, would it be better to throw an error than return null, and what about if is a collection should be returned?
it can return the null set
fitten":1z43c9n0 said:^^ Also, null and a string of length zero are not the same thing.
Unfortunately, in languages where all reference types are nullable, that mess you allude to exists whether you use an option type or not. Creating an option type just adds a third case: null, explicit data found, and explicit data not found. IMO it's cleaner just to use the null that's already there in this case. Furthermore, it's idiomatic and you don't get every library implementing its own option type or relying on an additional library for one.ShuggyCoUk":3rqz4zoo said:Any thing else is a mess.
If you need to indicate some 'out of bound but not utterly unexpected' result then the correct way is either discriminated unions, tuples, Option<T> moral equivalents, output parameters and a boolean (in roughly descending order of utility but also probability of language support)