DEV Community

Discussion on: Returning type-safe & non-nil failure in Crystal?

Collapse
 
mjb2kmn profile image
MN Mark

That is a good point.
One thing I didn't point out is: another purpose of returning the empty User object, beyond satisfying the return type, is that it's a blank object that should be safe to use anywhere.
If you were to fetch an object and ignored the errors and tried to populate the view anyway, you would get blank values as the objects would have to be initialized with valid values such as empty strings, 0, or whatever is appropriate.

I think this addresses the concern, if I've understood you right.

Collapse
 
itr13 profile image
Mikael Klages

Well, it depends on what the user object will be used for. If you only use it for displaying values then it should be fine.

If there's a chance the caller will be comparing a field to another, there may be unexpected behaviour if they don't check the error.

If the user plans on changing the object them storing it somewhere, then they may end up with lots of near-empty fields.

I must admit I haven't tried crystal, and I don't know the extent of what you're making, so I'm just listing issues that may occur with stuff that seems similar :-P