Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion of smell: options changing the return type #6

Closed
josevalim opened this issue Mar 28, 2022 · 4 comments
Closed

Suggestion of smell: options changing the return type #6

josevalim opened this issue Mar 28, 2022 · 4 comments
Labels
suggestion of smell Elixir-specific smells suggested by the community

Comments

@josevalim
Copy link
Contributor

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.

@lucasvegi lucasvegi added the suggestion of smell Elixir-specific smells suggested by the community label Apr 7, 2022
@lucasvegi
Copy link
Owner

What do you think about naming this smell as "Alternative return types"?

@josevalim
Copy link
Contributor Author

Great!

@lucasvegi
Copy link
Owner

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

@josevalim
Copy link
Contributor Author

Beautiful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
suggestion of smell Elixir-specific smells suggested by the community
Projects
None yet
Development

No branches or pull requests

2 participants