This question already has an answer here:

There's a lot of hype over functional languages right now, and I've spent the last year studying Haskell as my intro to FP as a result. Seeing the advantages FP provides is easy (such as referential transparency and easy concurrency due to the emphasis on immutability).

The question I have been asking myself, now, is whether imperative programming provides any clear advantage over the functional paradigm? I'm not considering more controversial advantages like, oh, more people in the industry know the imperative style. I'm looking more for advantages inherent to the style, regardless of popularity (such as, oh, it's actually better for writing performant low-level code quickly, or it's easier to debug because of x, y, and z, etc). We could pretend that it's an ideal world, if you like, when talking about each paradigm (for example, let's pretend that UNIX was written in SML when talking about functional disadvantages, instead of saying, imperative is advantageous because UNIX is written in C).

It seems I'm having a harder time these days finding out what the advantages of the imperative style are, especially as processor architecture get's more complex so that a Haskell vs C implementation of optimized low-level code looks equally frightening to me.

marked as duplicate by gnat, Bart van Ingen Schenau, GlenH7, user22815, Kilian Foth Apr 13 '15 at 10:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 5
    Why do we use screwdrivers to tighten screws and hammers to pound in nails? – user22815 Apr 10 '15 at 16:39
  • 1
    @Snowman: This question is more of, if imperative programming is a hammer, where are the nails? – Josiah Apr 10 '15 at 16:51
  • 3
    @Snowman because you don't have a nailgun? – enderland Apr 10 '15 at 17:04
  • 4
    Truth be told, you're bumping into the same thing everyone I've seen learn FP has bumped into: There seems to be no reason not to use it, other than people don't know it; and all the negatives people tend to throw around are generally thrown around by folks who haven't taken the time to actually learn FP first. I've yet to find someone who actually knows FP who doesn't prefer it over imperative. – Jimmy Hoffa Apr 10 '15 at 17:21
  • 1
    @Josiah: I program in C++ and Java at work and use Haskell and Lisp in my free time. In my experience, the only advantage of imperative programming is speed, i.e. destructive updates can be faster than updating persistent data structures in FP. Other than that, I cannot think of any other advantages. – Giorgio Apr 22 '17 at 19:38

Well, you already hinted at the answer. Imperative programming is closer to the metal, so it makes more sense in places (like embedded) where you're working closer to the metal. Nobody would bother programming an Arduino in Haskell (well, except maybe for @JimmyHoffa), though programming one in Scheme is not unheard of.

Some other reasons:

  1. Computing model more readily maps to the underlying hardware.

  2. Imperative programs can be written in a functional style, with a small amount of additional effort.

  3. A huge base of preexisting imperative code guarantees the need for people having imperative skills.

The last point is perhaps the most important one. Imperative code has an advantage because its already out there, in great volume. And as long as we keep making languages like Java, we'll be writing more of it.

  • So it's still a valid case, then, that C, for example, is still better for embedded despite the complexities of modern processors where your C code caters to the fact that, if you want to optimize, you need to think about keeping things in the cache and avoid hitting the RAM? I agree on point 1, however point 2 seems like opinion and point 3 seems more like a side-note than an actual reason to choose an imperative language. – Josiah Apr 10 '15 at 17:06
  • I think FP advocates would contest the first two, though the first only because of different definitions of simpler (you refer to implementation, FP advocates look at denotational semantics or something similar). – user7043 Apr 10 '15 at 17:07
  • @delnan: Well, not the first. Processors are decidedly imperative. – Robert Harvey Apr 10 '15 at 17:09
  • The keyword they'd take issue with is "simpler", which you wisely edited out ;-) – user7043 Apr 10 '15 at 17:15
  • While the third point sort of touches on something less inherent to imperative programming and more based on language popularity (something I tried to avoid by adding my statement about pretending UNIX was written in ML in the Question statement), I accept that point as completely true and valid. – Josiah Apr 10 '15 at 17:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.