There is always a tussle going on between functional vs imperative language people.<p>But nowadays most languages are mixed paradigm. Still there are differences.<p>Functional people give arguments like:<p>1. Code is easy to reason about<p>2. Can be verified easily and less prone to errors<p>3. Use mutation only when necessary, not as a default.<p>Imperative people say:<p>1. More efficient as close to the machine<p>2. More space efficient hence faster. (although functional languages can be as fast with compiler optimisations)<p>Functional languages are used in industry now at large scale e.g: Jane Street, Twitter, etc. Imperative language has always been used in industries. I bring up industries because it proves that the languages are scalable.<p>Functional programming experts say that their code is efficient because the compiler translates it to an efficient representation on the CPU. They have TCO and other things. But they don't mutate data and hence every function call creates a new data in memory taking up space. How do they overcome that?<p>Also we can switch between imperative and functional implementations. Basically an algorithm can be implemented eitherwise.<p>Now my question is where do I learn about these nitty gritty's? Should I read about compilers more? Or systems? Or what?<p>Can you suggest books/blogs/courses?
> Functional programming experts say that their code is efficient because the compiler translates it to an efficient representation on the CPU. They have TCO and other things. But they don't mutate data and hence every function call creates a new data in memory taking up space. How do they overcome that?<p>By letting the compiler make assumptions. For example, consecutive map calls can be converted into a single one. If the data isn't shared with something else, the compiler can mutate it. MUCH easier to paralellize maps.<p>As a starting point for those nitty grittys, this talk is probably as good as any <a href="https://www.youtube.com/watch?v=vzfy4EKwG_Y" rel="nofollow">https://www.youtube.com/watch?v=vzfy4EKwG_Y</a>
Functional is easier to reason about, if you are the kind of person who prefers reasoning in that way. For some people, it fits the way they think better. For others, it doesn't.<p>But imperative is still the default first approach that everybody is taught. For those whose minds fit better with functional, when they encounter functional programming, it's like being let out of prison. It's amazing. The problem comes when they assume that it will be the same for everyone, and if someone else doesn't have the same experience, it's because they haven't "gotten" functional yet. No, some peoples' minds find imperative to be a more natural way to think.<p>So: Learn some functional. Learn it well enough to see if it fits how you think. If it does, great! And if it doesn't, also great! Then, primarily go with the tool that fits you.
> But they don't mutate data and hence every function call creates a new data in memory taking up space.<p>Well, only if you mutate the data. And even then, most functional languages provide persistent data structures that allow efficient sharing of the unchanged parts of the data structure.<p>> Now my question is where do I learn about these nitty gritty's? Should I read about compilers more? Or systems? Or what?<p>I'd recommend choosing a functional language and an imperative language and learning both.