TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Why and how should someone learn functional programming?

21 pointsby dscalmost 15 years ago
A lot of people tell me that it's the holy grail of programming crafts -which I don't see. So enlighten me.<p>Thanks in advance.

11 comments

newhousebalmost 15 years ago
In terms of day to day programming, I've picked up the following habits:<p>* Natural terseness. A lot of functional code is freakishly short. Because functional code is similar to how we think of math, it's often times easier to simplify out over-computation and you end up with the bare minimum of what you actually need.<p>* Generic programming. Things like currying and first-order functions are great for separating (or combining) context from computation. When you understand where the difference lies, you can write your code such that it is adaptable in the most efficient way (read: generic).<p>* Lambda functions. Infinitely useful in a language that uses them, like Python. Lambda's are great for doing work over large collections of data without getting lost in for loops (i.e. map, reduce, sort, fold).<p>FWIW: I learned what I know from Haskell
评论 #1408323 未加载
bjgalmost 15 years ago
If you've really never had any functional programming experience and you are interested in haskell, I would recommend "Learn you a Haskell For Great Good" <a href="http://learnyouahaskell.com/" rel="nofollow">http://learnyouahaskell.com/</a><p>It's a little bit silly, but it's a great bottom up tutorial of haskell and a lot of functional programming paradigms.
vault_almost 15 years ago
I wouldn't say that it's the holy grail, but there are several reasons why it's good to know, and also many why we'll probably start seeing a lot more of it.<p>The biggest reason that its' a good thing to learn a functional language is a lot like the reason that it's a good idea to learn more languages than just Java. In this case, all you have is one paradigm to think in (object-oriented (probably procedural as well, but...)). Functional programming is a completely different beast that requires different ways of thinking. Lots of the neater concepts of many popular languages now are lifted right out of functional ones. Python's list comprehensions and generators come to mind.<p>A more pragmatic reason to learn about functional programming is that it is becoming increasingly useful. Functional languages are, in general, much easier to parallelize. More importantly than that though, they make it easier to make _correct_ parallel and multi-threaded programs.<p>As for why these are often presented as the 'holy grail' of programming, many of features exist to make it simple to create concise, correct programs. The features are all the foreign-sounding buzzwords that people tend to rave about: composition, laziness, currying, lambda-functions, monads, strong type systems, type inference, higher-order functions, loop abstractions, and any number of other nifty things.<p>If you're interested in learning more, check out the Haskell or Ocaml languages (or Lisp, but Lisp isn't entirely functional).
评论 #1407665 未加载
shahriarhaquealmost 15 years ago
I wouldn't say it's a Holy Grail or Magic Wand, or whatever you want to call it. I would say: learning a (pure) functional language, or taking a university course on it, is a religious experience. One that every programmer should go through to learn a new way of looking at problems.
评论 #1408045 未加载
gtanialmost 15 years ago
I thought these papers are useful:<p><a href="http://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf" rel="nofollow">http://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf</a><p><a href="http://www.ccs.neu.edu/home/matthias/Presentations/ecoop2004.pdf" rel="nofollow">http://www.ccs.neu.edu/home/matthias/Presentations/ecoop2004...</a><p><a href="http://www.bluebytesoftware.com/blog/2010/03/01/OnHaskellTypeClassesAndCInterfaces.aspx" rel="nofollow">http://www.bluebytesoftware.com/blog/2010/03/01/OnHaskellTyp...</a><p><a href="http://www.harukizaemon.com/2010/03/functional-programming-in-object-oriented-languages.html" rel="nofollow">http://www.harukizaemon.com/2010/03/functional-programming-i...</a>
daleharveyalmost 15 years ago
it isnt the holy grail, I can say I am a better programmer thanks to learning erlang though, half of that is due to its functional nature, half due to the erlangs idioms.<p>you learn the same way you learn any other language, just pick something to program and go for it.
pdelgallegoalmost 15 years ago
I learned using Elisp, it didn't make a better programmer, but I am much more pragmatic now.<p>Use the 3 schemer books The little schemer, the seasoned schemer and the The Reasoned Schemer, and read Structure and Interpretation of Computer Programs. You can work through the books using clojure or other more appealing languages.
评论 #1408046 未加载
pavelludiqalmost 15 years ago
Referential transparency makes things so much simpler, there is so much less stuff to keep track of, when your program is much less prone to random state in one part of your code affecting another.<p>Its not the "holly grail of programming", its more like "the less broken type of programming".
评论 #1407670 未加载
hgaalmost 15 years ago
How long have you been programming and in what languages?
评论 #1407646 未加载
Ixiausalmost 15 years ago
I got my first taste of functional programming with Erlang. Honestly, it had me befuddled for quite some time with pattern matching and the "functional" style; I was used to using objects to encapsulate rather than "modules" and "functions" - the distinction in nomenclature may seem frivolous, but the concepts are worlds apart when used in the context of Erlang or Java.<p>Erlang taught me a lot that I never even came close to learning with PHP, Python, and C++. Most notably what Erlang is good at - Concurrent Programming.<p>I still didn't fully "grok" functional programming though as I just completed the book and didn't complete any projects using Erlang. The real meal first started with Common Lisp which drove me to Scheme (Common Lisp is a mess, Scheme is minimal in nature, and Scheme is much more true to a functional language than CL). I then picked up the <i>Little Schemer</i> series of books and proceded to have my world view enlarged; with the addition of many other excellent resources, my knowledge of programming increased exponentially.<p>Within a few months of "grokking" functional programming and grooving with Scheme (it is my favorite language to date, Python comes second) the noted benefits were: an increased academic understanding of computing and the modality with which computable logic is represented, clearer/cogent/lucid and higher-caliber thought, my creativity in programming was unleashed, and I've found that I have a vested interest in the <i>philosophy</i> behind what I do. I also feel like my general perception of reality has changed too, I interpret my life experiences with a different set of concepts now.<p>The experience of learning a functional language and being committed to "grokking" it, has been remarkably similar to the time I went backpacking through India for two months on a budget...<i>alone</i>. I came back with a new kind of maturity and my mind just works different from everyone else I know that still hasn't left the states. It's like that, your mind just works different than all the others that haven't left procedural/OOP land.<p>As for production projects: there are plenty of companies that use Scheme, Erlang, and a other functional languages. I personally would love the opportunity to program in Erlang or Scheme over any other language (they are that much of a joy); alas, my industry (web application programming) is primarily enamored in Ruby/Python/PHP (Python and PHP being my primary marketable skills) so I would probably need to build my own startup or work for a company that uses the language (it wouldn't be in web application programming though!).<p>By the way, HN is built using a dialect of LISP based off of Common LISP (is that correct?) of which Scheme (Scheme is also a dialect of LISP) is a brother.
MisterWebzalmost 15 years ago
I'm curious as well.