addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1linklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [ljc] How to think as "functional language programer"

From: Kevin W.
Sent on: Thursday, October 3, 2013 8:16 PM

On 3 October[masked]:39, Linesh <[address removed]> wrote:
I asked below question to myself and searched through google, couldn't find a satisfactory answer yet.

Why a more (functional) programming language? (FPL)

FPL avoids State and Mutation:
You can achieve this in Java by using immutable objects, Collections class has very useful methods for this.

If you're thinking of java.util.Collections.unmodifiableXXX then you're mistaken.  These methods return a wrapper around a collection that will throw an exception for mutator methods.

This is *not* true immutability, as the collection underneath the wrapper can still be modified.  Not the kind of bug you want to come up in production!

Java collections are also not designed to be immutable, and so don't take advantage of the structural sharing techniques needed to be fast and efficient (especially in the face of garbage collection).  If you clone a Java collection to add an element then you must make a *very* wasteful clone of the whole thing.

If you want true immutable collections in Java, you should be looking at the Google Guava library.

Scala is good at concurrent execution of methods:
So is Java with all the tools in utils concurrent package, or communicating sequential processing may be also a good choice.

Java's concurrency is still very low level, dealing mostly with threads and synchronisation (fork-join being a notable exception).  This is "good" in the same way that assembly language is "good" (e.g. slow to write, slow to debug, very easy to shoot yourself in the foot).

I'm not aware of any mature CSP libraries for Java.
Scala code has smaller footprint:
At the cost of difficulty to make changes to that after few months(!), Java absolutely wins in that.

One of the prime benefits of FP is that logic is localised.  You can read the code for a function and understand what it does without also needing to read the code of every other function it calls, on the off-chance that one of them has mutated a supplied argument or some significant piece of shared global state.

Pure functions are also much, much easier to test.  There are no worries about setting up a full test harness to set up some required global state before calling them.  Exhaustive testing with e.g. ScalaCheck also becomes possible.

This works absolute wonders for code review, maintainability and bug fixing.  Future changes become easier to make, not harder.

Thoughts from and experiences of people using Scala for a while on these may be helpful I think.

Sent using BlackBerry® from Orange

Our Sponsors

  • Our Blog

    Read the latest news from the LJC

  • RecWorks Ltd

    Fixing Tech Recruitment using the Power of Community

  • jClarity

    Java/JVM Performance Analysis Tools & mentoring for Java related matters

  • LJC Aggrity

    Our LJC Aggrity site contains blog posts from our members

  • LJC Book Club

    Our Book club with book reviews from our members

  • Devoxx UK

    Java Community Conference in collaboration with the LJC, 8-10th June 16

  • SkillsMatter

    "Host, help organise, promote, film many of our meetings."

  • IBM

    Build Enterprise-grade apps at start-up speed.

  • New Relic

    New Relic makes sense of billions of metrics a day in real time.

  • Hazelcast

    Hazelcast is the leader in operating in-memory computing.

  • Java.Net

    We are an official Java User Group recognised by Oracle's JUG program

  • JRebel

    Free 3 month J-Rebel license.

  • O'Reilly

    40% discount on printed books and 50% on e-books.

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy