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

The plugin suggest using imperative code instead of lambdas #11

Open
tfij opened this issue Feb 3, 2022 · 0 comments
Open

The plugin suggest using imperative code instead of lambdas #11

tfij opened this issue Feb 3, 2022 · 0 comments

Comments

@tfij
Copy link

tfij commented Feb 3, 2022

Let's compare the two functions below

void fun1(List<Integers> ints) {
    ints.stream()
        .filter(it -> it > 100)
        .map(it -> it + 10)
        .map(it -> it / 2)
        .forEach(System.out::println)
}
void fun1(List<Integers> ints) {
    for (int i : ints) {
		if (i > 100) {
			int x = i + 10;
			int y = i / 2;
			System.out.println(y);
		}
    }
}

The first function uses a lambda, the second uses an imperative for loop. For the first function, the plugin calculates the complexity of 8 and only 6 for the second one.

If we increase the number of lambdas then the calculated difference of complexity will be even greater. In other words, the plugin suggests using imperative code instead of lambdas.

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

No branches or pull requests

1 participant