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

WPS331 should recommend the opposite #2927

Open
Andrej-Marsic opened this issue Apr 17, 2024 · 2 comments
Open

WPS331 should recommend the opposite #2927

Andrej-Marsic opened this issue Apr 17, 2024 · 2 comments
Labels
rule request Adding a new rule

Comments

@Andrej-Marsic
Copy link

Rule request

WPS331 should recommend the opposite, so to be explicit about what the returned value is, instead of leaving it to the cognitive load of the reader to understand it.

Thesis

The return statement should not be the place to call additional functions, but should instead only pass variables.

Reasoning

The only reasoning for this rule is that it provides better readability, but I'd argue that

return whatever_this_function_returns()

is less clear than

bananas = whatever_this_function_returns()
return bananas
  • Developers might opt for the first one because saving characters, but if the priority is clarity, there's an additional investigation that one needs to perform with the first option, while the name might clearly giveaway what we're getting in the latter
  • It's easier to track where the first creation of the variable came to be as without it the actual function that creates bananas might not mention bananas at all, even if that's its only purpose
  • It allows for easier tracking when traversing the inputs and outputs of a series of functions as the outputs are spelled out
@Andrej-Marsic Andrej-Marsic added the rule request Adding a new rule label Apr 17, 2024
@rkittens
Copy link

+1

1 similar comment
@Stanislav-Carny
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

3 participants