Link Details

Link 90146 thumbnail
User 235974 avatar

By warpedjavaguy
via warpedjavaguy.wordpress.com
Published: Jun 25 2008 / 12:40

Avoiding redundant code is a basic programming instinct. Java closures make it easier to eliminate redundant code and avoid it altogether! All other benefits are derived benefits inherited from this fundamental benefit.
  • 11
  • 5
  • 1031
  • 339

Comments

Add your comment
User 270877 avatar

killerweb replied ago:

0 votes Vote down Vote up Reply

Makes lots of sense but preaching to the informed. Anytime explaining something like Closures, you really need to give REAL world examples. Devil is in the details and just saying it makes DRY easier doesn't help, you need to show it. Reusable code isn't enough of a reason, since that could be done other ways. Just a suggestion.

User 264741 avatar

Dhananjay Nene replied ago:

0 votes Vote down Vote up Reply

I voted this down since the argument is both weak and incomplete.The essence of closures is not avoiding redundancy (closures distinguish themselves by "closing over" a runtime context) and if the primary focus is to avoid redundancy, closures is not likely to be the primary tool (there are just many of them eg. function, class etc.)

User 235974 avatar

warpedjavaguy replied ago:

0 votes Vote down Vote up Reply

Hi Dhananjay,
I am not saying that avoiding redundancy is the primary essence or focus of closures, but rather that it is the primary benefit that closures bring to the Java language. They eliminate boilerplate and facilitate much greater reuse in our code. If we already have the tools for achieving this, then why are we still writing boilerplate code and why is redundant code still a problem?

User 264741 avatar

Dhananjay Nene replied ago:

0 votes Vote down Vote up Reply

Hi,
There are two primary aspects of closures (a) The ability to close around and (b) The ability to treat code blocks as function objects. The latter capability can easily deliver almost bordering on the same reduction in redundancy that you would like to see with closures. To meet the redundancy reduction objective one only needs to introduce what are variously called as function objects / functors / lambdas - one does not need closures. A substantial part of the redundancy you seek to bring down can also be had by simply restructuring your code just a little differently without even using function objects.

I am very certain that the reason we still continue to write boilerplate code has to do with peopleware and not software and most certainly not the lack of closures. Better mentoring and training is the answer there .. not closures.

User 235974 avatar

warpedjavaguy replied ago:

0 votes Vote down Vote up Reply

I'm sorry, but no amount of training or mentoring will ever eliminate boilerplate and redundancy from closure-less Java code.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.