8 ms·
Ask HN: Reasons behind renaissance of functional programming languages
I've been curious about the renaissance of functional programming languages like Scala and Clojure in the software community. Is this a byproduct of our evolving hardware where instead of clock speeds the focus has been on pushing out more cores, so to reap the benefits software developers need better abstractions to make their code easily parallelizable? Is there some erlang-esque promise of pervasive immutability which is vaulting these languages into more popularity? Or is it simply the fact that these newer programming languages have simply learned from other languages' paint points and amplified the good parts by bundling them together neatly? I don't have anything against these languages, I'm just trying to get a deeper understanding of what appears to be a trend in the programming language space.
- tel 13y agoI think Haskell has been growing a lot fueled by having a really great base language finally getting a pretty comprehensive standard library. This was a highly intentional group effort that began probably 10 years ago and pushed the Haskell libraries to a level of maturity. I can't truly claim this has driven the adoption of other languages, but Haskell's (or pick some language from the ML roulette) influence on Clojure and Scala is undeniable. Clojure's commitment to immutability pales in comparison to Haskell's, while the latter demonstrates the advantages of such programming in spades. Scala's type system is a novel extension of the HM system which forms the basis of Haskell's. So am I claiming that the increased availability and "practicality" of Haskell has driven a renaissance in functional programming? Sort of, yes, but I don't feel it's the core underlying cause. More a symptom in its own right. These ideas are the leading edge of programming language research. They're smart to learn and to integrate into our next generation of tools. This evidence has long resounded from finding them at the center of the "Holy Trinity" of category theory, logic, and type theory. It's "practical" significance is still growing, however.
- NhanH 13y agoAdditionally, I think it's just a matter of "it's ready". We just couldn't have practical functional language 20 years ago, in term of both software and hardware. Back then, GC was a rarity, the JVM didn't exist yet. Software has to be ran on the user slow-ass computer, speed was everything and you didn't care much about concurrency/parallel problem. Nowadays, even if the clock speed didn't stagnate and we have just one super core in desktop computer, we would still write a lot more distributed system on the web now than we used to. Also, we're building more and more complex software over the year. I remember a question for Peter Norvig in "Coders at work", where he was asked about the differences in programming now and back there. In the past, programmers generally had to write (mostly) everything from scratch, and they kept the whole program in their heads. Nowadays, we actually spend most of our time reading other API and trying to plug different components together, referential transparency is simply a godsend. In a sense, I think the change from imperative programming to functional is similar to the one from GOTO to structure programming. May be we need a "Mutable state considered harmful" to push functional languages mainstream ? :-)
- chas 13y agoWe did have practical functional programming languages 20 years ago. PG has been very vocal about the advantages of using Common Lisp to create Viaweb. Viaweb started the summer of 1995 and meets my bar for practicality. To the best of my knowledge, functional programming languages weren't as widely used then but it was not because no practical languages existed.
- patrickg_zill 13y agoRAM is no longer a bottleneck. So you can "spend" some RAM in the search for increased programmer productivity. CPU is not really a bottleneck, either, so, you can also spend a few cycles there also.
- yati 13y agoThese reasons make sense when explaining the rise of, say, dynamic, interpreted languages luke Python/Ruby which are inherently slow(compared to conpiled, statically typed languages). Scala runs on the JVM, which is super fast once warmed up. So does Java. But Scala is more functional, more expressive and without a significant RAM or CPU hit compared to what we are already paying with Java.
- ShardPhoenix 13y agoIdiomatic Scala uses a lot more RAM than idiomatic Java, at least in my experience.
- deleted 13y ago[deleted]
- thinkpad20 13y agoHere are some reasons I can think of: * Parallelization and concurrency do seem to be easier in functional languages with immutable data. Not easier to write per se, but easier to reason about. * JavaScript was, as far as I can tell, arguably the first truly mainstream language to embrace first-class functions and closures. The ubiquity of JavaScript has exposed many to the benefits of such an approach. Similarly, Rails and other Ruby-based software make lots of use of functional programming through Ruby's do-blocks. These languages have made people more comfortable with first-class functions. * Languages like Haskell, Scala and Clojure have shown that functional programming can be high-performance and one need not necessarily trade speed for expressiveness. Similarly, many scripting languages (and/or the hardware they run on) have become fast enough to allow for them to be used for high-performance applications. * Functional programming is fun, and allows for beautiful and succinct code.
- sigil 13y ago> JavaScript was, as far as I can tell, arguably the first truly mainstream language to embrace first-class functions and closures. This is a nitpick, but Perl has had closures since the early 90s -- before Perl5 even.
- zoomerang 13y agoNot to mention Python and Ruby.
- Al__Dante 13y agoAnd Lisp :-)
- denibertovic 13y agoRuby doesn't have functions as first class citizens. Python does.
- yohanatan 13y agoThat's not a nitpick--that's getting the facts right.
- jesusmichael 13y agowhere would this "renaissance" be taking place? The most popular languages are java and C...
- revscat 13y agoJava just added lambdas.
- jesusmichael 13y agolambdas in java extend the object model not destroy it. So I don't get your point.
- mpweiher 13y agoSmalltalk has had blocks since at least 1976.
- angersock 13y agoJavaScript has both beat for deployment base and developer population, I wager.
- jesusmichael 13y agoI very much doubt that since java, c and python are the basis of most CS programs.
- catshirt 13y agoin our bubble this may ring true but pretty much the whole rest of the world is running on Java and C
- angersock 13y agoErm, you're ignoring a little thing called "The Internet as Experienced By Millions".
- 13y ago
- stonemetal 13y agoCynical answer: The consultants have decided that they need a new snake oil to sell since the Agile bus is running out of steam. Hopeful answer: FP languages have gotten enough better than the current mainstream that they can't be ignored. I believe it is a bit of the Hopeful answer but mostly the Cynical answer. If you compare java and Clojure(or Scala for that matter) on the programming language shoot out Clojure is neither more concise nor faster than Java. So why all the hype then? As far as I can tell it is book sells and the fashion cycle.
- tensor 13y agoClojure is much more concise than java, but ironically high performance clojure is not more concise, nor as fast, as java. But that said, high performance java is both slower and less concise than C by the same metrics. So if you think this is just fashion, then nearly every language outside of C is also just fashion. In my view, languages as a whole have been moving more and more towards the functional space over time. Newer languages, or versions of existing languages, typically have more functional features. Languages are trending towards higher order. As a result of this, the existing higher order languages, the functional languages, are suddenly much closer to mainstream and so have become more popular as the majority become aware of their benefits.
- weavejester 13y agoIf you stick to primitive operations like loop, if, let and data primitives, the bytecode generated by Clojure is the same as the bytecode generated by Java. Clojure's syntax isn't optimal for low-level in-place mutability, but macros can go some way to resolving that. The few times I've worked on high-performance Clojure code, it hasn't been too difficult to get performance comparable to an equivalent Java library. Java is somewhat slower than C, but it's generally within an order of magnitude if you stick to primitives.
- stonemetal 13y agoI would say choosing C is just fashion too. For any software development project technical merit limits language selection to a very broad category of languages. After you get to that broad selection of languages all narrowing is non technical (fashion) driven.
- mbenjaminsmith 13y agoAs a counterpoint I'll explain why I don't use Haskell. I like Haskell. I like it in theory and I like playing around with it. I like the discipline it requires having to re-think "everyday" things in order to solve them in a new paradigm. I started with Python and then learned half a dozen other imperative languages so Haskell is utterly alien to me apart from the most basic concepts like recursion. I liken it somewhat to learning Vim -- you make the simple complicated and gain something in the process. Haskell is the number one language I wish I was working in at any given time. So why am I not using Haskell? Most of my time is spent on OS X and iOS. While I could shoehorn Haskell into a project it doesn't make business sense to do so. I couldn't justify the extra time, complexity and I certainly couldn't justify it to a client. There simply is no good answer to "what about the next developer?" and other related questions. (I think this is why shoehorning a paradigm into an existing language is much better approach when you have a tight coupling of language and platform -- I'm thinking of RAC here.) Give me something to work on where Haskell is the obvious choice and I'd be all over it. Until then it has to stay in the toy box.
- dj-wonk 13y agoBut when you see a possible fit for Haskell (I would hesitate to make 'obvious' be the bar), have you tried to persuade or demonstrate the advantages? Why not find customers/areas that would be open to using Haskell? To some people, unfamiliar technology is scary, possibly unacceptable, and often far from 'obvious'. I don't like the metaphor or idea behind "you make the simple complicated". I prefer to say this: with functional languages, you name more things: mapping, folding, and so on, because you use them so often. Then you get comfortable thinking in higher-level ways. This means you can build on them more effectively.
- eropple 13y ago> Why not find customers/areas that would be open to using Haskell? I don't speak for him, but I don't because I don't want to do wrong by my customers. I don't do long-term support. I can maintain a heavily FP application (in Haskell or whatever else). Most programmers can't. That it has its advantages is good for me. Those advantages make it even harder for normal people to get good development help.
- pixelmonkey 13y agoIMO, it's something of a backlash against the rise of class-focused, object oriented languages (e.g. Java, C++, Ruby) leading to some complexity in the last decade. Pendulum now swinging back the other way. Functional, data structure oriented programming has many benefits above old-school procedural programming e.g. C, Fortran. But it also doesn't have the baggage of mainstream OO languages. Thus, this feels like an appealing -- and new -- ecosystems. This -- along with a rediscovery of some functional concepts that seem have more importance in a distributed setting, like immutable data, purity, higher-order functions -- have led to some renewed interest.
- seanmcdirmid 13y agoThis has gone on in academia for awhile, you are now considered mainstream if you embrace FP as the way, and you are considered a rebel if you instead believe that OOP is still the way. I predict that there will eventually be a FP backlash that reverses the situation again (hey, look how easy objects are to use vs. this crazy FP stuff!?).
- coolsunglasses 13y agoQuestion - why didn't you seek help in learning FP?
- seanmcdirmid 13y agoI worked with Martin Odersky team for awhile, and I saw the way...was to use some FP and a lot of the cool OO stuff that Scala provided (traits!). Scala is one of the most advanced OO languages out there.
- coolsunglasses 13y agoI'm very familiar with the PLT field, including OO languages like Scala and the history of its development. I was asking precisely because of your work on scalac. Much of your code had to get thrown out/refactored/cleaned up. The impression was that you didn't understand the FP part. Your recent comments on HN reinforce that. But that's besides the point. I'd like to find out what gaps can be filled so you no longer find FP difficult to understand or use. What material have you tried so far?
- badsock 13y agoPeople have covered a lot of the rational reasons, so here's an emotional one. I've been coding a bunch of Rust lately, and I'm happy to discover it has my favourite thing from Haskell: the "if it compiles it's usually correct" feeling is wonderful. My software feels rock solid to me, even while it's being heavily changed. It almost certainly translates into more reliable software, but even just the feeling is enough to hook me.
- sousousou 13y agoI agree. Once you understand typechecker error messages a little bit, refactoring becomes very simple (and fun!). 1. change a core type or function 2. fix all the type errors 3. yay This is wonderful. I think the tradeoff is that you start a new system, you have to delay running the code for a while. Until you have your core. (Fortunately there is undefined :: a for such uses.)
- weavejester 13y agoI suspect there are three main reasons. Limitations of hardware mean we're increasingly looking at computing in parallel, which is a natural fit for languages that emphasise immutability. Distributed computation also benefits hugely from immutable values, as it sidesteps much of the problem with cache expiry. We're also seeing a demand for more reliable systems. Taking mutability out of the equation eliminates a significant area of possible bugs, and allows for more sophisticated type-checking. The third reason is simply that it's only recently that we've gotten good functional languages with a comprehensive and mature set of libraries. Haskell has been around for decades, but when I first started learning it seven or eight years ago, the set of libraries on offer was very thin compared to Haskell today. Scala only popped onto the scene 11 years ago, and Clojure only 7 years ago.
- eslaught 13y agoI'm going to argue against the idea that functional languages are flourishing as a result of the availability of parallelism. There are two reasons for this: * Performance is not that big an issue for many applications. And if performance is not an issue, then neither is parallelism: the only reason to do parallelism is for performance (as opposed to concurrency, which makes sense even on sequential processors). So parallelism only really matters for performance-critical applications, because in most non-performance critical applications, you can squeeze out 10x by just running a profiler and writing better serial code. * If you do want performance, parallelism alone is not sufficient. On modern processors, data movement is significantly more expensive than computation. And in that regard, most functional languages perform poorly. Imperative languages, for all their faults, give you much more fine grained control over memory usage patterns. So for performance-critical applications (which are again, the only applications where you really care about parallelism), it is not uncommon to see the core of the application written in C/C++, even if the rest of the application is written in something else. By the way, if you aren't measuring your performance by comparing it against the peak compute/memory bandwidth of the machine, then you don't really care about performance, because you don't really have any idea what you're leaving on the table. This is why it's possible, for many applications, to give the code to an experienced performance programmer and see speedups in excess of 10x.
- ShardPhoenix 13y agoI agree - for me, immutability is much more about making code easy to reason about than it is about making it parallelizable.
- vandeekamp 13y agoI'm frankly tired of this rich hickey meme of "reasoning about" code. And I'm sorry but when you and even rich says it it's misleading conflation intended to confuse the listener. Implementing stateless systems in OOP is trivial. As in fucking a child can do it. And we have been doing it for DECADES. This "reasoning about" meme also implies that all code we write is inherently algorithmic and simply a computation. It is NOT.. 90 percent of code is just moving data around. The ten percent of algorithmic code, That involves actual math is usually trivially implemented in OOP languages. So lets rid ourselves of blowhard statements like "reasoning about' Because if you had any real experience you would understand we deal with these problems quite simply in OOP every day. Here's something for YOU to reason about. Us OOP guys can do the same thing better and actually understand the code 2 weeks later. We don't need to "reason" about it
- frik 13y agoA bit offtopic: It would be great if there was a 10GHz CPU (single-core), for some special domains. A hardware startup company that designs a new CPU that interrups the status-quo would be great. (3GHz in 2004, 3.8GHz in 2006, ~4GHz in 2014) Like in the 1990s 3dfx (GPU) and Cyrix (CPU): http://en.wikipedia.org/wiki/3dfx http://en.wikipedia.org/wiki/3dfx http://en.wikipedia.org/wiki/Cyrix http://en.wikipedia.org/wiki/Cyrix
- DanWaterworth 13y agoIt would be great if there was a 10GHz CPU (single-core), for some special domains. There's a reason it hasn't happened.
- frik 13y agoWhat are the reasons? Moore's law? What are the physical reasons beside heath transfer? In 2014 we have now the Intel Haswell (14 nm) with 3D tri-gate transistors yet just 3.7 GHz single-core clock rate. A 10 GHz CPU from Intel would be possible today, we just need dielectric liquid cooling (not water, but pressured Fluorinert) like the http://en.wikipedia.org/wiki/Cray_2 http://en.wikipedia.org/wiki/Cray_2 and http://en.wikipedia.org/wiki/Fluorinert http://en.wikipedia.org/wiki/Fluorinert General public cannot buy such equipment, but it does exist.
- gradschool 13y agoAt 10GHz, a signal can propagate no more than 300 microns in a cycle due to the speed of light. The CPU would have to be designed either asynchronously or with many more clock domains than currently. The performance probably wouldn't scale linearly by any realistic metric, and you'd still have the same memory latency.
- knz42 13y agoArguably the previous poster only mentioned he wants a 10GHz processor, not fast off-chip memory accesses. Also you can achieve a lot of performance in signal processing applications using a fast-clocked single core with on-chip SRAM scratchpads.
- pbiggar 13y agoThere has always been an interest in these languages. What's changed is that using a functional language no longer cripples you. That is, the rise of service-oriented architectures, horizontal scaling, javascript, and REST APIs mean that it is no longer suicide to build your product using a functional language. 20 years ago you needed to write desktops apps, so you were limited to C/C++. Then 15 years ago you needed access to java libraries, and the only real JVM language was Java. Now, you just need to build a service that speaks HTTP, so you just need a HTTP server, a HTTP client library, and a database adapter. That means you can build your product in any language you like, and not lack the ability to succeed. CircleCI is written in Clojure. We communicate with all our vendors over simple REST APIs - it only took a few minutes to write our own client bindings for Stripe and Intercom.
- frozenport 13y agoThere is a lot more demand for tasks that FP is good at such as data processing where state is a means to an end, and hence the program can be stateless. Contrast this with the 90s were we needed to write user interfaces where state was the point, or C++ gamedev.
- AYBABTME 13y agoI would conjecture that your perception of FP languages making progresses is an echo of your own development or of people immediatly surrounding you, and that possibly, numbers would show that there is no increase in FP language adoption. I'm not taking a stand here, just posing a possible alternative explanation. At least, I've thought about the OP's question and guessed it was a false generalization of my own progress. Data in (dis)favor of either.
- AnimalMuppet 13y agoFP is quite popular on HN. The more time you spend on HN and perhaps similar sites), the more you think FP is popular. Is there an actual increase in FP language adoption? Probably there is, within the population that reads HN. Within the programming world at large? I have no data, but from seeing some places that claim to measure usage, my perception is that any increase in FP in general usage is fairly small.
- deleted 13y ago[deleted]
- drudru11 13y agoIt is a side-effect of larger memories.
- erikb 13y agoI've read a lot of interesting things here, but no post really covered my perspective, so here it is: Reason 1: Object Oriented Programming becomes less popular. After the 90s people started to see that OOP is not really the solution that scales to unlimited complexity. It was a step forward but nothing more. Many different things got tried, like Aspect Oriented Programming, but none of that really stuck. Reason 2: The moment we had processors with more than one core we suddenly had a need for general purpose parallel processing. While the solution to this now seems to be using tools/frameworks like ZeroMQ, another reasonable option were languages with different paradigms, like functional. I think that both these things happened nearly at the same time got a lot of traction to functional languages. I am following this since 2008, though. That functional languages still didn't make it to the top of popularity currently results in me no longer believing that they will ever be. Functional languages always had this kind of swingy popularity where a small group of people where strong hearted followers while the general opinion always swings between "this is ridiculous" and "maybe we could use it for that use case". All in all I would say, the question is a great one, now that the current renaissance of Functional programming is pretty much over.
- alkonaut 13y agoThese come to mind (there are probably even more) 1) Complexity: Managing complexity is just easier with compact syntax, immutability etc. Applications are becoming larger and more complex, and languages that help reducing coupling and code size will become more popular than those that easily allow getting the job done at the expense of high complexity (e.g. OO/imperative). 2) Concurrency: With concurrent/multi-threaded applications being par for the course rather than something exotic, functional thinking is now required for many applications regardless of language. 3) Modularity/Decoupling/Interoperability: SOA and API's means you can develop independent bits of software that communicate in some language agnostic way (e.g. http). The CLR and JVM now both have support for functional languages that work well with their imperative siblings. This means you don't even have to be loosely coupled by http, you can write an application where the logical/computational bits are F# and the UI is C# while in the same application. Apart from these we must not forget that almost all the large imperative languages (C++/C#/Java) have gained numerous functional constructs in recent years. Few of us can imagine working in an imperative language without lambdas these days. So functional thinking has slowly been sneaking into the imperative programmers day job too. This has made more of us interested in these languages that consist almost only of these bits we find to be the most elegant in our OO languages. It's simply less scary. In 1998 the difference between Haskell and Java 1.1 was quite large. In 2014 the difference between C#5 and F#3.1, or between Java 8 and one of the functional JVM languages, is no longer big enough to make it scary.
- aaron695 13y agoHow about a boring theory, Internets. It's just a subculture that couldn't gain critical mass without the internet. Like furries it has a wide but sparse appeal. It is a subculture that's not simple though, it takes a while to get into, unlike being a furry you really need to do it in your job to be good at it hence it's only starting to hit it's peak.