What are potential disadvantages of functional programming?
I am currently studying the excellent <a href="https:&#x2F;&#x2F;www.amazon.com&#x2F;Concepts-Techniques-Models-Computer-Programming&#x2F;dp&#x2F;0262220695" rel="nofollow">https:&#x2F;&#x2F;www.amazon.com&#x2F;Concepts-Techniques-Models-Computer-P...</a>, and I believe that this book answers the questions in the OP very clearly, and although maybe you find it too theoretical, it does in fact provide loads of practical advice, and is very readable; not for the faint of heart though ;)<p>Anyway, just to practice what I&#x27;ve learned so far I will try to answer some of your questions from the top of my head; apologies in advance for my verbosity:<p>First of all, let&#x27;s define functional (in fact, to be strict, declarative; more on this below):<p>An operation (i.e. a code fragment with a clearly defined input and output) is functional if for a given input it always gives the same output, regardless of all other execution state. It behaves just like a mathematical function, hence the name.<p>This gives a declarative operation the following properties:<p>1) Independence: nothing going on in the rest of the world will ever affect it.<p>2) Statelessness (same as immutability): there is no observable internal state; the output is the same every single time it is invoked with the same input.<p>3) Determinism: the output depends exclusively on the input and is always the same for a given input.<p>So what is the difference between functional and declarative? Functional is just a subset of declarative = declarative - dataflow variables<p>These properties give a functional program the following key benefits:<p>1) It is easier to design, implement and test. This is because of the above properties. For instance, because the output will never vary between different invocations, each input only needs to be tested once.<p>2) Easier to reason about (to prove correct). Algebraic reasoning (applying referential transparency for instance: if f(a)=a^2 then all occurences of f(a) can be replaced with a^2) and logical reasoning can be applied.<p>To further explore the practical implications of all this lets say that, given that all functional programs consist of a hierarchy of components (clearly defined program fragments connected exclusively to other components through their inputs and outputs) to understand a functional  program it suffices to understand each of its components in isolation.<p>Basically, despite other programming models having more mindshare (but, as far as I can tell, aren&#x27;t really better known, and this includes me ;), because of the above properties functional programming is fundamentally simpler than more expressive models, like OO and other models with explicit state.<p>Another very important point is that it is perfectly acceptable and feasible to write functional programs in non strictly functional languages like Java of C++ (although not in C, I won&#x27;t explain why, it&#x27;s complicated but basically the core reason has to do with how memory management is done in C).<p>This is because functional programming is not restricted to functional languages (where the program will be functional by definition no matter how much you mess up).<p>A program is functional if it is observably functional, if it behaves in the way specified above.<p>This can be achieved in, say, Java, with some discipline and if you know what you are doing; the Interpreter and Visitor design patterns are exactly for this, and one of the key operations to implement higher order programming, procedural abstraction, can easily be done using objects (see the excellent MIT OCW course <a href="https:&#x2F;&#x2F;ocw.mit.edu&#x2F;courses&#x2F;electrical-engineering-and-computer-science&#x2F;6-005-elements-of-software-construction-fall-2008&#x2F;index.htm" rel="nofollow">https:&#x2F;&#x2F;ocw.mit.edu&#x2F;courses&#x2F;electrical-engineering-and-compu...</a>  for more on this).<p>Because of its limitations, it is often impossible to write a purely functional program. This is because the real world is statefull and concurrent. For instance, it is impossible to write a purely functional client-server application. How about IO or a GUI? Nope. I don&#x27;t know Haskell yet, it seems they somehow pull it off with monads, but this approach, although impressive, is certainly not natural.<p>Garbage collection is a good thing. It&#x27;s main benefit to functional languages is that it totally avoids dangling references by design. This is key to making determinism possible. Of course, automatically managing inactive memory to avoid most leaks is nice too (but not all leaks, like, say, references to unused variables inside a data structure, or any external resources).<p>However, functional programs can indeed result in higher memory consumption (bytes allocated per second, as opposed to memory usage, which is the minimum amount of memory for the program to run), which can be an issue in simulators, in which case a good garbage collector is required.<p>Certain specialised domains, like hard real time where lives are at stake, require specialised hardware and software anyway, never mind whether the language is functional or not.<p>So, for me, for the reasons above, the take home lesson so far is:<p>Program in the functional style wherever possible, it is in fact easier to get right due to its higher simplicity, and restrict and encapsulate statefulness (and concurrency) in an abstraction wherever possible (this common technique is called impedance matching).<p>Each programming problem, or component, etc, involves some degree of design first, or modelling, or a description, whichever word you prefer, it is all the same. There are some decisions you must make before coding, TDD or no TDD.<p>What paradigm you choose should depend first on the nature of the problem, not on the language. Certain problems are more easily (same as naturally) described in a functional way, as recursive functions on data structures. That part of the program should be implemented in a functional way if your language of choice allows that .<p>Other programs are more easily modelled  as an object graph, or as a state diagram (awesome for IO among other things), and this is the way they should be designed and implemented if possible. But even in this case, some components can be designed in a functional way, and they should be wherever possible.<p>There is no one superior way, no silver bullet, it all depends on the context. It is better to know multiple programming paradigms without preferring one over the other, and apply the right one to the right problem.