4 ms·
To play devil's advocate for a minute: Nearly all useful, reusable software today is written in a mostly or entirely imperative language. This is despite the f
by btmorex 12y ago
To play devil's advocate for a minute:
Nearly all useful, reusable software today is written in a mostly or entirely imperative language. This is despite the fact that functional programming has been around for at least 20-30 years. So, my basic question is, if functional programming is so much better, why isn't more software written in a functional language? Or put another way, why are there so many blog posts promoting functional programming when it clearly hasn't produced results.
- rjknight 12y agoI have a suspicion that it's due to the "unreasonable effectiveness of software", to paraphrase Eugene Wigner. The ability to do large amounts of computation quickly and cheaply is just so powerful that we can get away with doing it relatively badly and still create a lot of value. Functional programming might well produce better software, for some criteria of "better", but these quality-based criteria are dominated by the "is it cheaper and more effective than paying a person to do this" criterion employed in industry. This isn't necessarily a bad thing - if even the "worst" imperative software is value-creating, then there's a lot of scope for superior functional software to create even more value, there just isn't a lot of pressure to do this within industry because imperative programs are good enough for most use cases. There are other factors, such as path-dependency issues relating to developer skill-sets and toolchains, which give an advantage to imperative programming too. It seems likely to me that functional languages will close at least part of this gap, and perhaps Erik Meijer is underestimating the importance of "mostly functional" programming as a stepping-stone to "totally functional". Dijkstra was wrong when he claimed that learning BASIC was a mental mutilation preventing a person from ever understanding programming, and by the same token I suspect that we'll see plenty of people becoming good functional programmers who first encountered FP in passing callback handlers around in JavaScript.
- JeanPierre 12y agoThat's a red herring: You're asking why the majority of software is written in imperative languages instead of functional ones, which is a very complex question with very many factors. It is not an argument which invalidates nor counters the author's claim: Namely that "mostly functional languages" is unfeasible and only increases the bugs caused by side effects.
- stinos 12y agoAfter reading the article I tend to agree. Just this excerpt seems to confirm: Pure functional programming is programming with mathematical functions. ... Calling a function with the same arguments will return the same result every time. That leaves a whole lot of other functions, the non-mathematical ones, the real-life ones where you read files or I/O or user input out of the "Pure" definition, if I understand it correctly that is. And by that logic, means '"Pure functional" programming does work, but only if...'. Or, in other words: '"Pure functional" programming does NOT work in real-life software'
- icebraining 12y agoI believe the whole fuss of monads is because they allow you to write pure functional programming while still doing I/O and similar things. http://chris-taylor.github.io/blog/2013/02/09/io-is-not-a-side-effect/ http://chris-taylor.github.io/blog/2013/02/09/io-is-not-a-si...
- davidw 12y agoOk, but if we're being picky about things, you can use all the monads you want, but if you read a file and display its output two different times, you may well get completely different results. The contents could have changed, someone may have removed the file, and so on.
- yvdriess 12y agoMathematically, you have two different inputs in that case, the environment changed since.
- JonnieCache 12y agoIn practice functional languages have ways to mark certain code as having side effects for I/O and the like, which stops the badness from escaping to the rest of the program. You're right in thinking that software with no side effects at all wouldn't be very useful.
- yvdriess 12y ago
- electronvolt 12y agoFunctional programming has been around since the late 50s/early 60s, depending on what you count as the start of LISP as a programming language. In some ways the reason it isn't used a lot is for historic reasons as much as anything else. Functional programming, for a long time, was seen (often rightly so) as more computationally expensive than the same imperative code for most tasks. For a long time, that meant that you weren't going to use functional programming: when every single byte and cycle matters, you're going to go with assembly or whatever is closest to it/translates really well to it. (e.x. C) We now live in a world with abundant memory and excessive unused clock cycles. If I remember correctly, there's also been a good bit of research and work in the last 20-30 years The historic reasons for not using functional programming are gone for many (but definitely not all; people still hand roll assembly, too) of the original use cases. However, you then have 30+ years of programmers who were largely trained in and almost exclusively used imperative languages over the course of their career. That kind of market share is hard to compete with (because it's similar to market share; if everyone is using imperative languages, you need to be familiar with them too if you want to stay in most parts of the industry), and is self perpetuating (if you want to work in CS, you're going to need to know imperative languages for most jobs). I'm also fairly certain there's a good number of useful, reuseable programs that're written in functional languages, but I'm in an airport and nothing immediately comes to mind.
- deleted 12y ago[deleted]
- gotofritz 12y agoBy the same token, Windows is much better than Unix, McDonald's much better than a healthy diet, Justin Bieber is much better than [insert musician], ....
- TuringTest 12y agoFunctional programming is something you learn, more than something you do. Every time you create a procedure without side effects, you're using the paradigm. Learning when it's useful to use state, and restricting side effects to those parts of the program that require it, is a good skill to have. Now, pure functional languages may have had a slow adoption, but they are a good way to learn the paradigm that can be translated to other environments. Also, if you think FP hasn't produced results you haven't been paying attention, or you don't program neither web applications nor database APIs. Declarative libraries like jQuery selectors and LINQ have spread like fire, and any programmer of complex asynchronous applications should take a look at Reactive Programming (which represent state changes in a functional style with the Streams and Futures abstractions) and Agent-based Models (which encapsulates them through message passing).
- lelf 12y ago> why isn't more software written in a functional language? Because (1) honesty the “industry” programming is in the stagnation. Otherwise the boring Java♯'d run on Martin-Löf type theory; (2) it may require more brain; (3) we all learn imperative programming first. (And of course this reasoning is ignoring one aspect: we (mostly) don't want to write bug-free software. Who would pay for support?)
- art2 12y agoThat's a good question and a proof that pure FP isn't good for creating "stuff that works". For years the mantra was "bad industry doesn't want to use FP". But nowadays, especially inside a community like HN, this statement doesn't make much sense. There are plenty of side projects and startups, and how many of the successfull ones use pure FP? I think the reason for this is that pure FP replaces classic programming with puzzle solving. It satisfies math-oriented minds by forcing usage of this math-oriented layer. But it looks like software isn't math and you often need to work with a computer in a more direct way.
- deleted 12y ago[deleted]
- bachmeier 12y agoThis article is about pure functional programming. As for functional programming, all of the recent languages (Rust, D, Go, Clojure, Scala, etc.) have functional features such as lambda functions. I don't think it's a stretch to say lack of support for functional programming is not an option for new languages. As a couple of examples of software written in a functional language, consider Twitter and (ironically) Hacker News.
- jlouis 12y agoIt does produce results, but the results are probably more hidden. Rumor has it that 50% or more of all telecommunication uses Erlang, a mostly-functional programming language. This is a tremendous success, but few people know of the fact. I like to think that the whole discussion is straw-man. The useful, reusable software can be created in any language. But when every project is a gamble, and most projects starts out as imperative in orientation, then the chance of those bubbling to the top is greater. Good modularity of software happens on a higher level than picking the programming language of choice.
- blablabla123 12y ago>It does produce results, but the results are probably more hidden. Rumor has it that 50% or more of all telecommunication uses Erlang, a mostly-functional programming language. This is a tremendous success, but few people know of the fact. Probably the statement "> 50% of large telecommunications companies have done something with Erlang at some point in time" is correct. I guess you could even make it a 100% considering that parts of routers are often programmed with FP. However, most stuff is done in imperative languages. ;) Routing and Connection handling is certainly nice using FP, just consider the amazing Hot Code Swapping features in Erlang. On the other hand, writing APIs, connecting those etc. is much more convenient in imperative languages.
- pjmlp 12y agoIt is called legacy. For several reasons, the hardware required to run Lisp code was too expensive vs what was required to run C, Pascal, Algol and their descendants. Business don't change programming languages, just because. Unless you are doing greefield projects, there is a whole eco-system from tooling, building, trainings, developers, legacy code that needs to be taken into consideration. By the time computers were getting cheap enough to handle FP at reasonable price, the OOP finally managed to get into the industry at the enterprise level. As such it got the place that could have been taken by FP. OOP goes back to Simula and Smalltalk, which happen to also be Lisp inspired. As for not producing results, many train schedule systems run on Lisp. http://www.siscog.pt/ http://www.siscog.pt/
- mamcx 12y agoI get aware about functional language years after I learn to program. I think I lot of devs I know barely know it (in fact, because I'm dreaming in build a language, I get more info about). Probably swift will be a significant cause of exposure for it. However, I don't think a total functional language is the best, but a mix (like swift, julia).