Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Why Functional Programming? (hamletdarcy.blogspot.com)
21 points by raganwald on July 3, 2008 | hide | past | favorite | 13 comments


I don't grok OCaml at all, since I've never even laid eyes on it, but I identified with his personal story of moving from one mind-warp to the next as he matured as a developer. I've now hit the OMG! Functional Programming! stage myself, which leads to an uncomfortable (some days actually painful) cognitive dissonance while I toil away for 8 hours a day writing VxWorks-based C code for a mega-corporation.


I never really went through any stages, i just started using python and suing functions seemed better for some reason than using classes. Now im learning scheme and i am sort of starting to get it.


For me it was the same.

Python offers it all, functional, procedural, object-oriented. So you just choose hwta fits the problem best and dont worry about politics.

Personally while learning Python I was also learning functional languages and I started to naturally drift towards a more functional style.

My functional code is just much more modular and natural than my OO-code.

Classes I to represent some data every now and then but it is not central to my designs.


"Python offers it all, functional, procedural, object-oriented. So you just choose hwta fits the problem best and dont worry about politics."

I find the idea that Python offers it all surprising, for example my understanding is that anonymous functions can only be one line and you cannot write generic functions a'la CLOS.

If that is the case, while Python may offer a terrific language for Getting Stuff Done, you may want to consider learning other languages on the off chance that they actually do more in each of their respective areas. Then, when you return to Python you can apply what you've learned.


Yes that is true and I know a lot of languages and while Python perhaps doesnt offer as deep possibilities within each paradigm it offers every paradigm.

As you said this makes it very good for writing programs and does so in a lot of different domains but perhaps when digging really deep into one area you can find something better suited.


yeah, im learning django now and models have to be classes and views are functions. You generally have to understand both functional and OOP to be good. Im not a fan of any of the pure languages. Multi paradigm is my choice, but i still would prefer functional to oo solutions to problems.


I'm not familiar with OCaml, so maybe I'm missing something.

But why does no one gush over Erlang and Javascript when the FP hat gets passed around? Is OCaml really much better than either of these?

(Javascript, granted, has no shortage of warts. But it's the browser language we have, so it's worth learning to love it.)


Without being an expert, I'm pretty sure that OCaml is more strictly functional than Erlang and Javascript, though they all support functional programming to one extent or another. With languages like Javascript and Ruby, you can program for years without really learning functional concepts. I think OCaml is the opposite; the paradigm of least resistance is functional, even though you can program in other styles (OO, imperative).

In terms of functional purity, Haskell > Lisp/Scheme/OCaml/ML > Erlang > Ruby/Javascript > Python > Java > etc.


I'd say Erlang enforces functional style more than Lisp does... there's no Erlang object system.


True, it is virtually impossible to do much of anything in Erlang without using a bunch of little functions. Immutability is a harsh mistress, but one that I've already fallen in love with.


Learning to love the one you're with is fine, however that does not necessarily lead to the type of "mind warp" he's describing.

I like JS enough to blog about it, but I confess I haven't found in it that marvelous thing that makes me see programming in a new light. So it may be that although Javascript is where you want to use your FP chops, Lisp or Ocaml is where you want to acquire them.


A lot of that has to do with Javascript's environment. While it is a functional language, it's living in a decidedly procedural world. The DOM is defined in IDL, for goodness sake, and even the really cool libraries like jQuery don't make much use of the functional paradigm. So there's not a lot of clever code to study that doesn't look like C, basically.

Nonetheless, there are all sorts of clever things you can do with closures in Javascript to avoid big declarations of global variables, etc... You just have to dig really hard to find the sample code that appears in the tutorials for lisp, haskell, ML, etc...


"proclaiming the death of patterns due to closures and dynamic typing."

Can somebody explain that?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: