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

From: Kevin W.
Sent on: Wednesday, October 2, 2013 1:31 PM
As Martijn correctly stated, experience with Smalltalk will help, as will experience with LOGO, or Lisp, or *any* other declarative language - including SQL.

It also helps to remember that the core paradigm shift here is imperative -> declarative.  OO is completely orthogonal to this, and you can write object-oriented code in both imperative and declarative styles.

Draw on every bit of experience you have in working with immutability.  For most Java devs this is going to be SQL and JodaTime, you might also have some experience with Hadoop or NoSQL databases that can help here.

Top Tip: Most established Scala devs will view the difference between declarative/imperative in the same way as Java devs view the difference between JodaTime and Java's Date/Calendar types.  The imperative way used in Java is risky; You're dealing with values that can be changed in another thread even as you're working on them, or simply because you passed them as an argument to another method - just try using an instance of SimpleDateParser across multiple threads to see a terrifying and eye-opening example of this in action.  Use your experience of JodaTime, it'll help you out a lot here.

Finally, draw on mathematics and real-world intuition about how things work.  If you pass `christmas` as an argument to some function, you still expect it to still be December 25th when that function returns.  At it's heart, Functional Programming is applying this same core expectation to every value that you pass to every function in your program.  You should work wherever possible with pure functions (don't mutate their arguments, don't mutate any state external to the function, and always return the same output given the same inputs). An "FP Language" is just a language with constructs and syntax that make it easier to program in this style; there's nothing to stop you writing a functional program in C or Java, if you so wish.


Finally... Just keep at it.  You'll reach a point where recursion (and tail recursion) just "clicks" and begins to make perfect sense.  And remember that with coursera you're not *just* learning FP; you're also learning algebraic data types, pattern matching, and working with a more powerful type system. These are all concepts that work very well alongside FP, but aren't essential to the paradigm.


On 2 October[masked]:49, Joel Gluth <[address removed]> wrote:
My main piece of advice would be simply to stick with it.

The Coursera "FP in Scala" course is a decent introduction (I had my team of OO developers take it, at my last job). It might feel like you are spraining a frontal lobe making the transition from mutable to immutable coding styles, but the exercises in Odersky's course are presented in a reasonably well thought out order.

Struggle through... the lightbulbs will go off. Having someone to talk to about it might be a good thing - are the Coursera forums of use?

Scala is a bit of a funny one in that it gives you the tools for mutable programming up front and it can be tempting to lean on them (unlike, say, Clojure, where the mutability keys are put on a slightly higher shelf). Ignore the crutches. Don't be put off by the fact that you are finding it hard... if you are totally new to FP, it's definitely a lot of mental gear shifting.

Hang in there.


On Wed, Oct 2, 2013 at 10:38 AM, Sivaji <[address removed]> wrote:
Hi all,
recently I have started learning Scala course offered by coursera (by martin odersky) but I am still not getting the crux of it by writing programs in functional way. Most of the time I am thinking like a imperative prog language developer and all examples/exercises are given in the course need to be solved with out mutation (complete functional).

so my question is, Is this quite normal for a developer from java background or you have any learning resources to tune my mind to write programs in functional programming language as well... I am loosing confidence for the first time as I am struggling to write a simple dummy tweeter application,.Scala language syntax/constructs/concepts are not a problem to understand but thinking everything in recursion and thinking very abstraction is nightmare for me now. Anybody faced similar issue (may not be with scala but other functional prog language) and want to share their experiences, it is highly appreciated??

thanks
sivaji k




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Sivaji ([address removed]) from LJC - London Java Community.
To learn more about Sivaji, visit his/her member profile
To report abuse or block this person, please click here
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]



--
[what were the skies like when you were young?]




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Joel Gluth ([address removed]) from LJC - London Java Community.
To learn more about Joel Gluth, visit his/her member profile

To report abuse or block this person, please click here
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]



--
Kevin Wright
mail: [address removed]
gtalk / msn : [address removed]
vibe / skype: kev.lee.wright
steam: kev_lee_wright

"My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra

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 12/13 Jun 14

  • SkillsMatter

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

  • Packt Publishing

    A publishing company specializing on specific technologies and solutions

  • 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