The Artima Developer Community
Sponsored Link

Weblogs Forum
How Has Functional Programming Influenced Your Coding Style?

27 replies on 2 pages. Most recent reply: Nov 23, 2010 6:03 AM by Pavel Mendl

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 27 replies on 2 pages [ « | 1 2 ]
Michael Swierczek

Posts: 2
Nickname: mikeswierc
Registered: Apr, 2008

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Apr 25, 2008 11:02 AM
Reply to this message Reply
Advertisement
> Don't forget about procedimental. Some times what you need
> to do is precicely step #1, #2, #3...
>
> The expressive blessing and limitation of functional is
> that it always seeks a value. But many times one just
> needs to get something done to the world (a side effect in
> functional).

But many functional languages have constructs to manage evaluation order. Instead of step1(); step2(); step3(); You can do step3(step2(step1())) to guarantee order.

And for side effects, there are defined constructs for handling them in many (all?) functional languages. The majority of the code you write will not need them or allow for them, but of course if the whole language can't handle them you're sunk (no IO, etc...).

Adam Olsen

Posts: 11
Nickname: rhamph
Registered: Jun, 2007

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Apr 25, 2008 9:44 PM
Reply to this message Reply
> > Don't forget about procedimental. Some times what you
> need
> > to do is precicely step #1, #2, #3...
> >
> > The expressive blessing and limitation of functional is
> > that it always seeks a value. But many times one just
> > needs to get something done to the world (a side effect
> in
> > functional).
>
> But many functional languages have constructs to manage
> evaluation order. Instead of step1(); step2(); step3();
> You can do step3(step2(step1())) to guarantee order.
>
> And for side effects, there are defined constructs for
> handling them in many (all?) functional languages. The
> majority of the code you write will not need them or allow
> for them, but of course if the whole language can't handle
> them you're sunk (no IO, etc...).

Syntax matters. Functional programming is a great addition to a programmer's tool set (I'd argue essential), but if you start throwing out the procedural tools you are, as you say, sunk.

Cameron Zemek

Posts: 17
Nickname: grom358
Registered: Dec, 2006

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Apr 25, 2008 10:25 PM
Reply to this message Reply
> A lot of these techniques are a lot more natural in dynamic languages like haskell,

Haskell is not dynamic, it has static type checking.

And in order todo things in sequence, Haskell has the do notation which uses Monads. State is also managed with Monads. Monads are functional still.

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Apr 27, 2008 11:17 PM
Reply to this message Reply
> > A lot of these techniques are a lot more natural in
> dynamic languages like haskell,
>
> Haskell is not dynamic, it has static type checking.
>
> And in order todo things in sequence, Haskell has the do
> notation which uses Monads. State is also managed with
> Monads. Monads are functional still.

My bad, I meant functional or dynamic, the main point being that functions can be passed around easily. Or I could have just left off 'dynamic'. To the average working programmer, that and the lack of state making parallelization easier are, to me, the two main benefits.

I'm thinking that based on the number and focus of the responses here, it hasn't influenced enough people's coding style, which makes me a little sad :-(

Achilleas Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Apr 28, 2008 5:35 AM
Reply to this message Reply
Although I tried FP many times, I haven't found it useful even a tiny bit. Things that are pretty easy with imperative programming (like updating a variable and triggering a change in the UI, for example), become a nightmare of monads and other fancy FP constructs.

I have also found that the phrase "in FP, if a program works, then it's correct" is largely a myth. Implementing the wrong algorithm in Haskell or ML is as easy as in Java or C++, and the compiler will say nothing about it (that's understandable, because the FP compiler does not know the program specifications!).

FP has also not help me with concurrency because in my concurrent programs I have very little need for using synchronization objects; I use message queues, and I don't have any synchronization issues.

The conclusion after playing with FP over the years is that it simply does not worth the effort. Logical bugs (i.e. the implementation not agreeing with specification) are not caught by any compiler, FP or not, and therefore FP is pretty much useless for me, especially since FP languages do not have the broad spectrum of libraries Java and C++ enjoy.

Michael Feathers

Posts: 448
Nickname: mfeathers
Registered: Jul, 2003

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Apr 28, 2008 6:40 AM
Reply to this message Reply
> Although I tried FP many times, I haven't found it useful
> even a tiny bit. Things that are pretty easy with
> imperative programming (like updating a variable and
> triggering a change in the UI, for example), become a
> nightmare of monads and other fancy FP constructs.
>
> I have also found that the phrase "in FP, if a program
> works, then it's correct" is largely a myth. Implementing
> the wrong algorithm in Haskell or ML is as easy as in Java
> or C++, and the compiler will say nothing about it (that's
> understandable, because the FP compiler does not know the
> program specifications!).
>
> FP has also not help me with concurrency because in my
> concurrent programs I have very little need for using
> synchronization objects; I use message queues, and I don't
> have any synchronization issues.
>
> The conclusion after playing with FP over the years is
> that it simply does not worth the effort. Logical bugs
> (i.e. the implementation not agreeing with specification)
> are not caught by any compiler, FP or not, and therefore
> FP is pretty much useless for me, especially since FP
> languages do not have the broad spectrum of libraries Java
> and C++ enjoy.

How about the brevity? Did you enjoy it?

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Apr 28, 2008 11:22 AM
Reply to this message Reply
>
> How about the brevity? Did you enjoy it?

Yes, but only briefly? ;-)

Daesung Park

Posts: 10
Nickname: grayger
Registered: Apr, 2006

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Apr 30, 2008 9:36 PM
Reply to this message Reply
Can you elaborate how to do functional programming with Method class in Java?

Terje Slettebø

Posts: 205
Nickname: tslettebo
Registered: Jun, 2004

Re: How Has Functional Programming Influenced Your Coding Style? Posted: May 8, 2008 5:31 AM
Reply to this message Reply
> > Don't forget about procedimental. Some times what you
> need
> > to do is precicely step #1, #2, #3...
> >
> > The expressive blessing and limitation of functional is
> > that it always seeks a value. But many times one just
> > needs to get something done to the world (a side effect
> in
> > functional).
>
> But many functional languages have constructs to manage
> evaluation order. Instead of step1(); step2(); step3();
> You can do step3(step2(step1())) to guarantee order.

I don't think is the case for a language using lazy evalutation (like Haskell). It may start at step3() and only evaluate its parameters when (and if) needed.

However, for example in the case of Haskell, you have monads which allows you to specify an explicit sequence.

> And for side effects, there are defined constructs for
> handling them in many (all?) functional languages. The
> majority of the code you write will not need them or allow
> for them, but of course if the whole language can't handle
> them you're sunk (no IO, etc...).

Yes, a language without side effects is pretty useless (how do you know that you've run it?). :)

Brian Reilly

Posts: 1
Nickname: breilly
Registered: Jul, 2006

Re: How Has Functional Programming Influenced Your Coding Style? Posted: May 22, 2008 1:17 PM
Reply to this message Reply
> can you give a link to the yui tutorial, please (i
> googled, but didn't find anything obvious)? thanks.

It looks like there's a link in the post to http://developer.yahoo.com/yui/theater/. Though I haven't watched any of this content yet (but looking forward to it!), I'm guessing that's where the tutorial on structuring larger programs is... likely in one of the multi-part series from Douglas Crockford:

The JavaScript Programming Language (1/4): http://video.yahoo.com/watch/111593
Advanced JavaScript (1/3): http://video.yahoo.com/watch/111585
Theory of the DOM (1/3): http://video.yahoo.com/watch/111582

Jeff Heon

Posts: 40
Nickname: jfheon
Registered: Feb, 2005

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Jun 9, 2008 10:39 PM
Reply to this message Reply
FP has influenced how I have tried to change my coding style, but not how I code yet.

In brief, FP has only brought me frustrations in my attempts to use it in Java ;)

Here's a description of my attempt (and failure) at it 8)
http://thecarefulprogrammer.blogspot.com/2008/06/scala-influence.html

Rob Stewart

Posts: 5
Nickname: robstewart
Registered: Aug, 2005

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Sep 11, 2008 1:57 PM
Reply to this message Reply
> can you give a link to the yui tutorial, please (i
> googled, but didn't find anything obvious)? thanks.

Obviously, your mistake was using Google to find a Yahoo API! ;-)

Pavel Mendl

Posts: 1
Nickname: pmendl
Registered: Nov, 2010

Re: How Has Functional Programming Influenced Your Coding Style? Posted: Nov 23, 2010 6:03 AM
Reply to this message Reply
I am very new to the functional programming paradigm. In fact I came here to learn about this concept and understand, where I can get benefit from it in my programmer praxis.

I always stream to understand the substance, not the various outer signs of any new phenomenon; thus I do not speak about various languages, just about the concept itself.

Initial impulse was this Slashdot thread: http://tech.slashdot.org/comments.pl?sid=1878200&cid=34303544 stating IMHO far too authoritatively:
Future of Programming by igreaterthanu on Monday November 22, @08:31AM (#34303544)
This just goes to show that if you care about having a future career (or even just continuing with your existing one) in programming, Learn a functional language NOW!


What I learned so far is, that functional paradigm streams to have no states and that this is because of target of as easy an unlimited multithread scaling as possible.

My first question thus is: Do I understand the basic premise of functional programming well, or did I miss something?

If I am true, than the proper functionally programmed code will not store any "intermedial" values, but in case they are needed just recompute them again from the original generating functions. Am I still right here?

If yes, then all the object vs. functional paradigm resembles me the well known true, that you can freely trade CPU time for memory and vice versa. As if you recompute eventually complicated generating functions instead of storing state (i.e. the already once computed value) in the memory, you spare memory but waste CPU time (what is obviously better suited for massive multithreading on multi-core processors). However, once you hit the scaling boundaries (power dissipation, price...) you can increase throughput only by saving some intermittent results, i.e. allow some states into game. Can this be used as the rule of thumb where (and how much strictly) use functional programming paradigm? Or where am I wrong?

Thank you for any comments and clues.

Flat View: This topic has 27 replies on 2 pages [ « | 1  2 ]
Topic: The Holistic Approach to Software Engineering as a Way to Handle Complexity Previous Topic   Next Topic Topic: Google Groups Data To Be Destroyed!


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us