Settings

Theme

Functional Programming at Facebook

scs.stanford.edu

196 points by stefans 10 years ago · 101 comments

Reader

rdtsc 10 years ago

Well also WhatsApp handling 1B+ users with Erlang, and with (what used to be?) only a handful of engineers.

But somehow the Haskell, OCaml and Scala users never want to include Erlang when talking about "functional". Even though it is probably the most practically used functional language.

  • incepted 10 years ago

    > Even though it is probably the most practically used functional language.

    Would love to get some evidence to back up Erlang being the most practically used functionally used language, because for all I know, it's hardly used at all these days.

    • seiji 10 years ago

      "practical" as in: the programing model fits the problem domain model of modern systems.

      But, "practical" doesn't show up on everybody's radar much these days with so much effort focused around fads-of-the-half-decade.

      Erlang is made by professionals with decades of experience who grow the system towards being the most stable, scalable, safe, and as understandable as possible. People use Erlang, solve problems, stay quiet, then make money using it.

      On the other hand, the thought leader these days seems to be Go (even though it's made by out of touch weirdos (review: http://www.evanmiller.org/four-days-of-go.html)) and has a creepy cult/fanatical following more suited to tribal sportsball teams than what we would expect from professional technical work needing to be stable over the long term.

      • tempodox 10 years ago

        A language like Go that has political campaigns encoded in its compiler has creepiness written all over it. For me, this is a no-go area, pun intended.

      • incepted 10 years ago

        > Erlang is made by professionals with decades of experience

        Who are they, besides Joe? Can you at least provide their names?

        I'd really like to take a look at their credentials because beyond WhatsApp and an obscure Ericsson router from 20 years ago, there isn't much data to go by.

        And there is plenty of evidence to show that C, C++, Java and more recently Go have some pretty strong success stories to justify their claim to scalability.

        • SanFranManDan 10 years ago

          Riot Games is a pretty big one. Looking at erlangs site selecting a few:

          AdRoll Facebook Chat TMobile

          http://erlang.org/faq/introduction.html

          Amazon SimpleDB Delicious From: http://stackoverflow.com/questions/1636455/where-is-erlang-u...

          Also many of the companies using Riak (written in Erlang) also leverage erlang. Some pretty big names use it.

          http://basho.com/about/customers/

          I would say that Erlang has more than proved itself.

          One aspect of it is that it is used more of an infrastructure language so not many people see it as glamorous as rushing out to the Go community to brag about their new backend. Its a lot of mature companies that have been around a while and don't really need to show off their infrastructure.

          Also Elixir is gaining momentum (but still a blip) as a very viable language built on erlang.

          Use what you want and what works.

          • incepted 10 years ago

            > One aspect of it is that it is used more of an infrastructure language

            Ah yes, the "dark matter" argument. It's out there but nobody can see it. You'll just have to trust me.

            • thinkpad20 10 years ago

              You posted asking for evidence of erlang being a practical, widely-used programming language. The posts in response have provided a huge number of examples of erlang not just "in production" but critically so. And yet, you seem to be resignedly unimpressed; all of your follow-up posts seem to be in the form of shrugs and harrumphs. What more are you asking for?

          • incepted 10 years ago

            I was asking for the names of the experts allegedly behind Erlang.

            As for listing companies that use Erlang, plenty of companies use PHP and COBOL too. This doesn't say anything about whether these languages are the most adequate for the task and whether these projects wouldn't be in a better shape if written in a different language.

            • querulous 10 years ago

              robert virding, richard o'keefe, francisco cesarini, mike williams, joe armstrong, ulf wiger, brian troutwine, fred hebert, jose vadim, steve vinoski, serge aleynikov?

        • exclusiv 10 years ago

          Not disputing your claim, but CouchDB is quite an impressive effort built on Erlang.

        • mavelikara 10 years ago

          > Who are they, besides Joe? Can you at least provide their names?

          One of them is here on HN: https://news.ycombinator.com/user?id=rvirding

    • kyllo 10 years ago

      Practicality is subjective, though. Unless you conduct an opinion poll, you will not find data objectively demonstrating that one language is more "practical" than another.

      • incepted 10 years ago

        Sure, but I interpreted OP's statement as saying "used in practice" as in "used in the real world".

        Pretty sure that Erlang would barely register as a blip on such a chart.

        • im_down_w_otp 10 years ago

          Almost all the successful non-Google ad networks and exchanges are written in Erlang, Goldman Sachs HFT platform is written in Erlang, several massive scale game platform backends are written in Erlang, several international "national net" banking switches are written in Erlang, a huge chunk of the global land-line and mobile telco switching infrastructure is written in Erlang, Heroku's control plane is written in Erlang, GitHub's RPC backplane is written in Erlang, Amazon SimpleDB is written in Erlang, Bet365's high-scale betting platform is written in Erlang, Pinterest is migrating services to Elixir (rooted in Erlang).

          There's a ton of stuff written in Erlang out there. A lot of really core infrastructure services that have to just run and run and run.

          It's not particularly trendy, but it gets shit done, and it does so with a quiet dignity. :-)

        • abiox 10 years ago

          RabbitMQ and CouchDB are written Erlang; Much of Ericsson's telephony infrastructure runs it; various companies in their industry like TMobile and Motorola use it.

  • Everhusk 10 years ago

    The feature set of Facebook is much more complicated than WhatsApp. Most of WhatsApps features come out of the box with ejabberd too (which is what they used in the beginning). Is it really a fair comparison?

    • rdtsc 10 years ago

      > The feature set of Facebook is much more complicated than WhatsApp

      But the feature set of Facebook is not all implemented in Haskell or OCaml either. There is lots of PHP etc.

  • meridional 10 years ago

    In part, this is due to Haskell et al. are statically typed, which provides a higher safety guarantee than dynamically typed languages like erlang.

    • krat0sprakhar 10 years ago

      Although this reason sounds plausible, it is quite surprising since one of the first functional languages - Lisp was dynamically typed.

      • tel 10 years ago

        Just to double down on the points of some other commenters here: "Functional" is a pretty difficult word to pin down these days. That said, there seems to be a clear camp in what might be better called "denotational" programming which centers around the ML-alike languages, the dependently typed languages, and Scala.

        Lisp is not much at all like these languages. Nor is Erlang, though it is vastly closer.

        • catnaroek 10 years ago

          I wouldn't call Scala a “functional” language. It's an object-oriented language that happens to be able to encode many Haskell idioms, with varying degrees of awkwardness. But you can write Java in Scala too, and, in the eyes of some, the result will even be more natural.

          Out of curiosity: Would you consider Prolog a language in which you can do “denotational” programming?

          • joostdevries 10 years ago

            I would call Scala a functional language. In the sense that object-orientation and FP are not eachothers opposite. Imperative and FP are. I guess awkwardness is in the eye of the beholder. I think it's an elegant language with which it is a joy to develop large code bases.

            • catnaroek 10 years ago

              I never said object-orientation and functional programming are opposites. (You can use objects to compute mathematical functions.) And, for that matter, imperative and functional programming aren't opposites either. (You can use imperative procedures to compute mathematical functions.) See: https://news.ycombinator.com/item?id=11180173 .

              The awkwardness I'm talking about comes primarily from the non-orthogonality of Scala's features. For instance, there are situations where subclasses and implicits are both reasonable alternatives for a given programming task. On the other hand, in ML and Haskell, it is often clear which language feature is the right tool for the job.

          • tel 10 years ago

            Scala I don't have too too significant experience with but it continues to feel like a functional language with commitment issues to me.

            I think Prolog counts here, too. But it's a weirder one.

      • nilved 10 years ago

        Lisp isn't a functional language.

        • seiji 10 years ago

          That's a very HN comment. Completely wrong but delivered with strong convictions.

          Lisp doesn't actually exist. Lisp is just axioms. You run an implementation of Lisp allowing various operations. Some flavors actually have (practically) zero mutability. You just create functions and cons cells and the rest of the world gets built on top of those.

          But, pure functional systems are useless (to be purely functional would mean you can't even do I/O... your program would just heat up the computer, which, in a way, is its own form of output, so you can't ever be fully functional).

          Every functional language gets non-functional at some point for data processing, bootstrapping, loading/saving programs, and the best functional languages even have optional mutability constructs for performance (see: !). You can't create the most performant data structures possible if all your operations require path copying, but mutability should be reserved for internal high performance library creation and avoided in business logic/application level code to make systems easier to reason about.

          • mbrock 10 years ago

            "Lisp doesn't exist" is also kind of wrong but with conviction, or at least debatable. Lisp was standardized in 1994 as ANSI Common Lisp, and there are a handful of other Lisp-like languages.

            And pure languages aren't useless. Not being able to do I/O can be good for many purposes. Pure Haskell is still able to model computations involving I/O, which are then executed by a trusted external runtime. There are benefits to disallowing arbitrary effects, which is also why several new languages take purity even further and disallow infinite recursion.

          • catnaroek 10 years ago

            For clarification, in a deduction system, an axiom is a proposition that is true just because. Similarly, an axiom schema is a predicate, such that substituting its free variables with closed terms yields a proposition that is true just because.

            Now, I repeat, how exactly is Lisp “just axioms”? What are the axioms in question? The mathematical ignorance of some of Lisp's proponents never ceases to amaze me.

        • incepted 10 years ago

          You're both right and wrong, it's just that "functional" has a lot of different definitions and nobody can agree on which one is correct.

          As a result, "functional" has become pretty much meaningless when describing a programming language.

          • catnaroek 10 years ago

            Functional programming has always been the name of a programming paradigm that treats computation as the evaluation of mathematical functions.

            • incepted 10 years ago

              That's one of the many definitions we have for it, yes.

              Plenty of people will disagree with it too.

              • sova 10 years ago

                Please correct me if I am off the right track here, but is not the distinction the fact that: in a "functional language" or maybe "parenthentical up-cup evaluating language"

                functions are invoked in an encapsulating way, and no state is kept between function-cup-up-segments-of-code, but there is a R.E.P.L that (replies) when you invoke a (parens) which is, in LISP-land known as a program.

                However, now that I have mind-dumped that ^ I recall haskell and erlang also being called "functional" but I don't know their syntax any more than a chimpanzee knows that the sun is round.

                • catnaroek 10 years ago

                  Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions. A function is a rule that assigns, to every element of its domain, a unique element of its codomain.

                  Note that the above definition says nothing about how functions are to be evaluated: strictly, lazily, memoizing previously computed results, or using magic. No general-purpose programming paradigm can make such decisions for the programmer.

        • vitno 10 years ago

          This person is getting downvoted... but it isn't.

          Lisp, especially in it's early implementations is highly imperative. This is why when people talk about Clojure they always talk about Immutability, it's part of what forces a functional style on the language.

          • catnaroek 10 years ago

            Immutable data structures don't “force” a functional style, cf. Prolog.

            And Lisp is highly imperative even today.

          • pjmlp 10 years ago

            They talk about Clojure because they weren't even born when we were using Lisp systems.

        • pjmlp 10 years ago

          CS language papers from the 50 and 60 don't share that opinion.

        • coldtea 10 years ago

          If you have been around 10 years ago, including on HN, everybody considered Lisp not only "a functional language", but "THE functional language".

          Heck, Haskell was barely ever mentioned.

          Not to mention that the whole idea of functional programming was introduced to the programming world with McCarthy and Lisp.

          (Except if you want to say that "Lisp is not functional, it supports many paradigms" -- but I find that tired. It is, at its core, functional).

    • akio 10 years ago

      Erlang does has static analysis though, through Dialyzer.

      http://erlang.org/doc/man/dialyzer.html

  • dreamdu5t 10 years ago

    Because there's functional as in only using pure functions (Haskell, ocaml) and functional as in access to higher order functions (JavaScript, erlang, clojure)

    • krat0sprakhar 10 years ago

      > Because there's functional as in only using pure functions (Haskell, ocaml)

      This is not true. Having written a good amount of OCaml I would argue that programming with side-effects in OCaml is extremely approachable - almost as much as Clojure. There are mutable data structures in the stdlib (Array, Hashtbl) and IO etc. is straightforward. Like Clojure, there exists a ref type which can be easily mutated. It's one of the reasons why OCaml strikes as an extremely pragmatic language to me.

      • catnaroek 10 years ago

        I'd distinguish between (at least) three degrees of “purity”:

        (0) Absolutely anything goes. Examples: Racket (in the REPL), Lisp, Clojure, Scala, Erlang, etc.

        (1) Values are immutable, but any computation might have any effect. Examples: Standard ML, OCaml (mostly), Racket (mostly).

        (2) Values are immutable, and computations are type-annotated with their possible effects. Examples: Haskell, Idris, Ur/Web.

        • i_s 10 years ago

          Pretty strange that you put Clojure in the "anything goes" category when it has been the clear leader when it comes to immutability. Lots of those languages you put in the other categories don't even have persistent data structures in their standard library.

          • catnaroek 10 years ago

            Here is why: http://pastebin.com/t3Q3CW4j

            This is particularly infuriating because the proper way to handle bound variables is already known: https://en.wikipedia.org/wiki/De_Bruijn_index .

            • i_s 10 years ago

              No one is maintaining state by constantly clobbering namespace level variables in Clojure, though. What actually comes into play are ways the language and standard library encourages passing data around and manipulating it, which in Clojure is as immutable as you'll find in any language.

              • catnaroek 10 years ago

                Clojure encourages me to program in the REPL, because there is no other way to know what is going on in such a semantically crazy language, other than trial and error.

                And the state of the Clojure REPL is as mutable and imperative as it gets, as my paste showed.

                • greydius 10 years ago

                  You can rebind variables in ghci, too. I certainly wouldn't say this is evidence that Haskell promotes mutable data.

                  • catnaroek 10 years ago

                    > You can rebind variables in ghci

                    No, you can't: http://pastebin.com/SdbKM7V7

                    In ML and Haskell, a new variable might shadow an old one (if they have the same name), but they are still different variables.

                    Shadowing is slightly harder to implement than rebinding, but it provides a useful guarantee for the user: the meaning of existing definitions remains stable even if new definitions are introduced into the environment.

                    • greydius 10 years ago

                      You are correct. I failed to consider the implications of the different mechanics in the repl. I'm inclined to think the clojure repl is more conducive to experimenting. That is, you can change any part of your program to see what happens. I guess one programmer's sandbox is another programmer's hellish nightmare of mutability. For what it's worth, I would never redefine a var actual code, but I can't say it hasn't been done by others.

                      • catnaroek 10 years ago

                        > I'm inclined to think the clojure repl is more conducive to experimenting.

                        I'm inclined to think the Clojure REPL is more conducive to flailing around. Now, this might sound like derision, but it isn't intended that way: Flailing around can be a very time-efficient way to familiarize oneself with an unknown domain, especially if the cost of making wrong design decisions is small.

                        But at some point one has to consolidate what one already has, and, in my experience, Clojure makes this very difficult.

                        > I guess one programmer's sandbox is another programmer's hellish nightmare of mutability.

                        If you absolutely want mutable definitions, you can have them in Haskell (with some noise) and ML (with no noise) too: http://pastebin.com/00ScnFxC . So a Haskell or ML programmer always has at their disposal whatever they think is the best tool for the job.

                        Can I have it the other way around in Clojure?

                        • greydius 10 years ago

                          > Flailing around

                          Haha, yes. This is how I feel about Matlab, actually. But I suppose Clojure is no different in this respect.

                          I much prefer the Haskell approach: make dangerous things hard to do. Unfortunately, a majority of programmers consider that to be "unpractical".

            • gclaramunt 10 years ago

              Interestingly, Scala handles it http://pastebin.com/CT36K6Hj It feels like an artifact of the REPL tho, as one shouldn't be able to redefine x

              • catnaroek 10 years ago

                Yep, statically typed languages tend to have no option but to handle this right. Otherwise, they risk unsoundness: Consider what would happen if you did `val x = "foo"` instead of `val x = 0`.

                But there's still no type-level distinction between immutable and mutable bindings, which is why included Scala in the “anything goes” category.

        • rdtsc 10 years ago

          > Absolutely anything goes. Examples: Racket (in the REPL), Lisp, Clojure, Scala, Erlang, etc.

          Well you can't mutate variables and data in Erlang. (Try X=1,X=2 in a repl, it will fail). There is a thing called process dictionary but it is frowned upon. Concurency is handled by processes. But that's a different thing.

      • Scarbutt 10 years ago

        leaving runtime asides, which do you enjoy more Ocaml or Clojure?

        • krat0sprakhar 10 years ago

          To add to ohnomrbil's succinct reply, I absolutely enjoy being scolded by OCaml's compiler. The type inference is just marvelous and the code is almost as concise as Python etc. OTOH, the library ecosystem for OCaml is not even close to the stuff that's available for Clojure.

        • ohnomrbill 10 years ago

          I use both, for different things. Clojure is more easily concurrent, and I love ClojureScript, so I tend to use it for web applications. OCaml is extremely useful for native code (I write a lot of personal productivity tools in OCaml).

    • rdtsc 10 years ago

      > Because there's functional as in only using pure functions (Haskell, ocaml) and functional as in access to higher order functions (JavaScript, erlang, clojure)

      Or functional as having proper closures.

      Or tail call elimination.

      Or using immutable data, or immutable variables.

      Or minimizing mutable state.

      Or being decalrative.

      etc...

      ;-)

      • catnaroek 10 years ago

        > Or functional as having proper closures.

        Closures are an implementation detail.

        > Or tail cail elimination.

        Tail call elimination is just the right way to implement tail calls in a strict language.

        > Or using immutable data, or immutable variables.

        Variables don't “mutate”, they are substituted with other expressions. What imperative languages have is “assignables”.

        > Or minimizing mutable state.

        Functional programs have plenty of state - which changes over time. You can't have computation without traversing a state space - over time.

        > Or being declarative.

        What (technical!) definition “declarative” are you using?

        • rdtsc 10 years ago

          > Closures are an implementation detail.

          Except when they are not there done properly (cough cough Python), it not so fun doing functional programming.

          > Tail call elimination is just the right way to implement tail calls in a strict language.

          Well Erlang is not strict and has tail call elimination. Because of lack immutability, recursion is used. Without tail call elimination recursion will blow the stack.

          > Variables don't “mutate”, they are substituted with other expressions. What imperative languages have is “assignables”.

          Yes they do. X=X+1 -- Variable mutated. Like it or not that is the bread and butter of programming. Unless someone did strictly functional programming and math. Then I can see how they'd be very confused by that statement.

          There is also immutable vs mutable data. For example both Erlang and Elixir have immutable data. But Elixir has mutable variable, while Erlang doesn't.

          As for assignables, I've never heard that word. I went to the standard 4 year CS program. Seemingly did a regular curriculum. Is that a translation from another langauge or a functional programming terminology?

          > Functional programs have plenty of state - which changes over time.

          Some have more, some less. Minimizing means making it explicit, passing it around, using immutable data. As opposed to say sticking it in a large object instance in a global singleton and then everything calls 100 something methods to mutate it.

          > What (technical!) definition “declarative” are you using?

          The point I think is, it is just as technical as "functional" is. It has a bit of a "No True Scotsman" thing going for it.

          But as a heuristic think maybe about when you'd use patern matching to destructure something vs say a nested set of if and elses.

        • julian_1 10 years ago

          Arguing about terminology and the correct definitions/properties of functional languages only demonstrates the point - that the properties of a functional language are context-sensitive and subjective.

    • raould42 10 years ago

      i thought ocaml ain't pure like that?

      • julian_1 10 years ago

        There are a couple of monadic IO systems for Ocaml - Lwt and Async which are pretty commonly used - and enable writing code using typed mutation/side effects.

      • pauldirac137 10 years ago

        You thought right. Ocaml is an impure functional language.

lxcid 10 years ago

In the comparison between Flow & TypeScript, he mentioned Flow gets non-nullability right. Anyone have any example to illustrate this?

  • lebek 10 years ago

    In Flow, `var a: string = null` would not typecheck. In Typescript it would.

draw_down 10 years ago

I feel like linking someone to a slide deck is akin to telling them to go fuck themselves.

  • stefansOP 10 years ago

    OP here: Would you prefer to have an indication that the link target is a slidedeck or do you think slidedecks should not be linked to at all?

kozikow 10 years ago

> Even though it is probably the most practically used functional language. Scala have 30th place on Tiobe index, while Erlang have 42th: http://www.tiobe.com/index.php/tiobe_index.

  • music 10 years ago

    I find it very interesting that Scheme beat out extremely fashionable languages like Rust and Go, not to mention Clojure didn't even make the first 50. I would expect Lisp and Prolog at the tail end of any such list.

  • runT1ME 10 years ago
    • ChemicalWarfare 10 years ago

      I'd venture to guess that once you start scanning github and to a lesser degree stackoverflow, the scale gets tipped away from the "enterprise applications" where Java reigns supreme.

  • jeremiep 10 years ago

    Are there people who actually take Tiobe seriously?!

    That seems like a very dangerous thing to do to me.

    • incepted 10 years ago

      Tiobe is consistent with pretty much any other measuring approach (job boards, github, stack overflow, etc...), so yes. It's a pretty reliable indicator.

      • jeremiep 10 years ago

        These are all based on popularity and online activity which are terrible indicators for a lot of application domains.

        They give you a rough head count yet you have absolutely no idea what percentage of them are actually good programmers you'd want to hire.

        Usually the more popular something is, the more you need to weed out bad candidates as well; its kind of killing the popularity argument.

        If you pick a technology based on its popularity or visible activity you're only making it much easier for your competitors to crush you really.

        I can only refer to pg's Beating the Averages at this point: http://www.paulgraham.com/avg.html

        • incepted 10 years ago

          You are missing my point.

          Their methodology matters little when their findings are consistent with a lot of other sources that use different methodologies.

          All these sites agree on the general brackets that these languages belong to. Until this stops being true, I'll keep accepting TIOBE as a reasonable indicator of language popularity (along with a bunch of other sources).

  • pmarreck 10 years ago

    https://en.wikipedia.org/wiki/Argumentum_ad_populum

    Has no relevance to actual language quality, potential or value.

    If this wasn't the case, then no language would ever pass, or fall behind, another language in popularity.

    Popularity is a reflection of already-realized value. That's all.

    • incepted 10 years ago

      When trying to assess popularity, measuring "ad populum" is exactly the right metric (hint: look at the root of the word).

      • pmarreck 10 years ago

        Ah, I thought he was making a different argument, my bad.

        Still, "most practically used" may not equal "most used"

ForHackernews 10 years ago

This from the people who brought us the 18,000 class iOS app?

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection