Functional Programming at Facebook
scs.stanford.eduWell 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.
> 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.
"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.
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.
> 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.
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.
> 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.
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?
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.
robert virding, richard o'keefe, francisco cesarini, mike williams, joe armstrong, ulf wiger, brian troutwine, fred hebert, jose vadim, steve vinoski, serge aleynikov?
Aww shucks. Bless your heart.
Not disputing your claim, but CouchDB is quite an impressive effort built on Erlang.
And Riak
and Elixir
> 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
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.
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.
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. :-)
Do you have references for the claim about telco switching?
http://erlang.se/publications/ericsson_review_axd301_1998012...
erlang was literally developed for telephone switches
That's a product from the late nineties. I have no idea how broadly it's used today.
A talk by Joe Armstrong I watched recently indicated that around 50% of 3G and more than that of 4G infrastructure uses Ericsson technology, specifically with swoftware written in Erlang. He made a joke about 'sweating over every bit' sent over the network and then complaining that all the apps are going crazy with their JSON.
https://en.wikipedia.org/wiki/Ericsson#Products_and_services
Erlang is mentioned only once in this entire article, and it's in the "See also" section. Nothing in this Wikipedia article supports the claim that Ericsson uses Erlang at all.
Sorry, you're right. I was more indicating at the fact that they power a huge amount of the infrastructure of mobile and telecoms.
Here's some sources that indicate that Erlang is still in daily use at Ericsson:
http://www.ericsson.com/ericsson/corpinfo/publications/revie...
http://www.ericsson.com/news/141204-inside-erlang-creator-jo...
I'm sorry I can't find the exact video I saw from Joe, but he's generally quite proud of the reach of Erlang so you'll find him stating the facts about how much of the mobile and telecoms infrastructure it supports in a few of his videos! I hope that helps.
Watch this video it explains clearly how it is used:
https://youtu.be/rQIE22e0cW8?t=662
And it is also fun!
That was the reason Erlang was created in the first place: https://en.wikipedia.org/wiki/Erlang_%28programming_language...
I know that. The last I heard was that Erlang decided to stop developing with Erlang, causing Armstrong and others to leave. I see they've reverses that decision and there are mentions of use at various mobile companies, so that's cool.
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.
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?
> 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.
In part, this is due to Haskell et al. are statically typed, which provides a higher safety guarantee than dynamically typed languages like erlang.
Although this reason sounds plausible, it is quite surprising since one of the first functional languages - Lisp was dynamically typed.
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.
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?
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.
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.
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.
Lisp isn't a functional language.
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.
"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.
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.
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.
Functional programming has always been the name of a programming paradigm that treats computation as the evaluation of mathematical functions.
That's one of the many definitions we have for it, yes.
Plenty of people will disagree with it too.
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.
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.
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.
Immutable data structures don't “force” a functional style, cf. Prolog.
And Lisp is highly imperative even today.
They talk about Clojure because they weren't even born when we were using Lisp systems.
CS language papers from the 50 and 60 don't share that opinion.
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).
Erlang does has static analysis though, through Dialyzer.
Because there's functional as in only using pure functions (Haskell, ocaml) and functional as in access to higher order functions (JavaScript, erlang, clojure)
> 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.
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.
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.
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 .
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.
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.
You can rebind variables in ghci, too. I certainly wouldn't say this is evidence that Haskell promotes mutable data.
> 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.
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.
> 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?
> 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".
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
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.
> 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.
leaving runtime asides, which do you enjoy more Ocaml or Clojure?
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.
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).
> 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...
;-)
> 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?
> 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.
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.
It is not context-sensitive: https://news.ycombinator.com/item?id=11179695
i thought ocaml ain't pure like that?
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.
You thought right. Ocaml is an impure functional language.
In the comparison between Flow & TypeScript, he mentioned Flow gets non-nullability right. Anyone have any example to illustrate this?
In Flow, `var a: string = null` would not typecheck. In Typescript it would.
I feel like linking someone to a slide deck is akin to telling them to go fuck themselves.
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?
> 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.
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.
Yes, but it is #14 Redmonk's rankings:
https://redmonk.com/sogrady/2015/07/01/language-rankings-6-1...
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.
Are there people who actually take Tiobe seriously?!
That seems like a very dangerous thing to do to me.
Tiobe is consistent with pretty much any other measuring approach (job boards, github, stack overflow, etc...), so yes. It's a pretty reliable indicator.
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
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).
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.
When trying to assess popularity, measuring "ad populum" is exactly the right metric (hint: look at the root of the word).
Ah, I thought he was making a different argument, my bad.
Still, "most practically used" may not equal "most used"
This from the people who brought us the 18,000 class iOS app?