Suggestion of smell: options changing the return type
josevalim opened this issue · 4 comments
Options should not drastically change the return type of a function. For example, you should not have an option that changes the return type. Fictional API:
Integer.parse("13")
=> {13, ""}
Integer.parse("13", discard_rest: true)
=> 13
Because options are optional and sometimes set dynamically, if they change the return type it may be hard to understand what the function actually returns. It is best to introduce a separate function, like Integer.parse_no_rest
.
What do you think about naming this smell as "Alternative return types"?
Great!
Hi Valim,
I also added this smell to the catalog. I've tried to detail the code examples a little more so the internal structure of the smell is more clear. What do you think?
https://github.com/lucasvegi/Elixir-Code-Smells#alternative-return-types
Beautiful!