Skip to content

Refactoring : Replacing anonymous classes using lamdas#67

Merged
mperry merged 19 commits into
functionaljava:masterfrom
amarpotghan:master
Jan 10, 2015
Merged

Refactoring : Replacing anonymous classes using lamdas#67
mperry merged 19 commits into
functionaljava:masterfrom
amarpotghan:master

Conversation

@amarpotghan

Copy link
Copy Markdown
Contributor

No description provided.

@amarpotghan

Copy link
Copy Markdown
Contributor Author

these refactorings are not adding much value, so closing the request, thanks.

@hugueschabot

Copy link
Copy Markdown

Actually, it can.

  • Lambdas and anonymous classes are not compiled into the same bytecode. See [http://blog.takipi.com/compiling-lambda-expressions-scala-vs-java-8/].
  • Furthermore, lambdas are usually easier to read.

I think the PR raise the question regarding the adoption of the lambda syntax throughout the whole project. As a potential contributor, I would be interested by the project's maintainers on this.

@amarpotghan

Copy link
Copy Markdown
Contributor Author

Thanks Hugues.

I have seen a pull request where @mperry asking to use java 8 lambda instead of anonymous class. Not sure if we want to do it project wide.

@MartinSeeler

Copy link
Copy Markdown
Contributor

In #64 , @mperry wrote

Please use lambdas in your code (rather than anonymous inner classes). The old code has not been updated to use them, but we should be using them in new code.

@mperry

mperry commented Dec 22, 2014

Copy link
Copy Markdown
Contributor

I think we should use lambda expressions throughout the project.

We are using the Retrolambda project to backport lambda expressions to Java 7 bytecode (https://github.com/orfjackal/retrolambda). Retrolambda does has a potential risk under known limitations:

"May break if a future JDK 8 build stops generating a new class for each invokedynamic call. Retrolambda works so that it captures the bytecode that java.lang.invoke.LambdaMetafactory generates dynamically, so optimizations to that mechanism may break Retrolambda."

It would be nice if someone went through to change existing methods to use lambdas.

Is it necessary to put parenthesis around one argument function parameter lists, e.g.

static public <A, B, C> F<C, B> o(final F<A, B> f, final F<C, A> g) { return (c) -> f.f(g.f(c)); }

instead of c -> f.f(g.f(c));

@mperry mperry reopened this Dec 22, 2014
@techtangents

Copy link
Copy Markdown

It would be nice if someone went through to change existing methods to
use lambdas.

Intellij could probably do it all in one go.

@amarpotghan

Copy link
Copy Markdown
Contributor Author

@techtangents IntelliJ is a good idea, but has to be very careful when refactoring in IntelliJ, it is not safe enough :)

@amarpotghan

Copy link
Copy Markdown
Contributor Author

@mperry : c -> f.f(g.f(c)); looks better. parenthesis are unnecessary. will update. Thanks

@amarpotghan amarpotghan changed the title Refactoring F1Functions : Replacing anonymous classes using lamdas Refactoring : Replacing anonymous classes using lamdas Dec 23, 2014
@amarpotghan

Copy link
Copy Markdown
Contributor Author

@mperry Could you please review this PR?

@mperry

mperry commented Jan 7, 2015

Copy link
Copy Markdown
Contributor

@amarpotghan I will have a look.

Comment thread core/src/main/java/fj/Bottom.java Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the curly brackets necessary for this lambda because we are throwing, rather than returning something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mperry here (throw error not an expression) brackets are necessary. Parser fails in absence of them.

Comment thread core/src/main/java/fj/Effect.java Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the use of curly brackets here necessary when we are returning a void value?

@mperry

mperry commented Jan 10, 2015

Copy link
Copy Markdown
Contributor

Overall comment: I think these changes can be merged as is, but they would be better if we changed some of the code to use the static constructors where applicable to take advantage of type inference.

@amarpotghan Thank you for your changes. Can you update the PR to reflect my comments?

@amarpotghan

Copy link
Copy Markdown
Contributor Author

@mperry thanks for the feedback, will update the PR soon.

@amarpotghan

Copy link
Copy Markdown
Contributor Author

@mperry Suggested changes are accommodated . please let me know in case I have missed anything

@mperry

mperry commented Jan 10, 2015

Copy link
Copy Markdown
Contributor

Thanks for making those changes @amarpotghan. I will merge the PR now.

That is quite an effort to chase up all those lambdas. Did you get every single one or do you think there are more to do?

mperry added a commit that referenced this pull request Jan 10, 2015
Refactoring : Replacing anonymous classes using lamdas
@mperry
mperry merged commit 6e0d7ce into functionaljava:master Jan 10, 2015
@amarpotghan

Copy link
Copy Markdown
Contributor Author

@mperry I did not chase every single :). There are quite a few still remaining to replace. They can be replaces while and when we touch the code there!

mperry added a commit that referenced this pull request Jan 10, 2015
@mperry mperry added this to the v4.3 milestone Jan 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants