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

new check to forbid use of short lambdas #340

Open
AlexHaxe opened this issue May 3, 2017 · 6 comments
Open

new check to forbid use of short lambdas #340

AlexHaxe opened this issue May 3, 2017 · 6 comments

Comments

@AlexHaxe
Copy link
Member

AlexHaxe commented May 3, 2017

Some people might want to prevent developers from using short lambdas.

Not sure what opposite of this check should look like, should it enforce use of short lambdas, e.g. mark every anonymous function as violation? Or should we split it into two individual checks?

@remiX-
Copy link

remiX- commented Dec 10, 2019

would this also allow to forbid use of using anonymous functions instead of short lambdas? :D

@AlexHaxe
Copy link
Member Author

It could act as an anonymous function style check, where it enforces either short lambdas or anonymous functions. For short lambdas it could make exceptions to allow anon functions when they use a curly body.

Writing a check that will detect if an anon function with curly body should be rewritten using short lambdas is a bit more involved. It's easy if there is only a return expression inside curlies, but beyond that one would have to identify cases, where it makes sense to use arrow syntax instead of anon functions.

@Gama11
Copy link
Member

Gama11 commented Dec 10, 2019

FWIW, I think forbidding anon functions in favor of short lambdas is a bad idea. There are some special cases where arrow functions don't work well due to their implied return or the inability to specify the return type.

@remiX-
Copy link

remiX- commented Dec 11, 2019

True... maybe not forbid, but just configurable to be shown as a info/warning log :)

@AlexHaxe
Copy link
Member Author

well, a checkstyle violation is as good as forbidding something, because the only way to get rid of it is either to suppress it, or to fix your code to be compliant.

So if you run anon function style check with options to enforce arrow syntax, then any place not using arrow notation is in violation of that check and will produce an info, warn or error message (depending on severity setting).

I am not sure how easy it would be to detect cases where arrow syntax can't or shouldn't be used in order to let them pass as compliant.

@remiX-
Copy link

remiX- commented Dec 12, 2019

Ah indeed.

People can also just convert anon functions where short lambda's couldn't be used into actual functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants