DEV Community

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

Collapse
 
netinlet profile image
Doug Bryant

If the intent is to always return a user object, perhaps a different method name such as find_or_initialize_by_login would make the intent more clear. get_by_login makes me think a login object or null/error as a result.

Collapse
 
mjb2kmn profile image
MN Mark

Renaming to something like "find_or_initialize_by_login" would be more accurate and in at least one way is the right answer. Except that it's not the right answer here which helps me see that it's the behavior of the method that is wrong. Thanks for the alternate angle on it.