4 ms·
Imperative programming wont die, but more an more of the languages we use are functional. SQL, CSS, HTML.. The last two are declarative, I know, but they fit ve
by bjourne 12y ago
Imperative programming wont die, but more an more of the languages we use are functional. SQL, CSS, HTML.. The last two are declarative, I know, but they fit very well into a functional paradigm.
I don't think Haskell or F# will ever make it big (for many reasons, to many to go into detail on here). But regular imperative languages are getting more functional oriented. Like LINQ expressions, list comprehensions, immutable data structures (Clojure is big on that) and TCO (very beneficial for fp).
It's a sliding scale and it doesn't matter so much if the language is categorized as functional or imperative. It's how you approach problems you solve with your language. I think more and more programmers are realizing that the functional approach is almost always superior.
- theseoafs 12y ago> SQL, CSS, HTML None of these languages are "functional" by any reasonable definition of the term "functional". CSS and HTML aren't even programming languages.
- AnimalMuppet 12y ago> I think more and more programmers are realizing that the functional approach is almost always superior. Only for a very limited definition of "almost always". It's almost always superior if you don't hit performance constraints, and if your problem isn't dominated by sequencing, and if your team can handle the functional approach, and if... Why is it superior? It controls the state space explosion, and therefore makes it easier to understand and reason about your program. Why could performance be a problem? Think about a functional quicksort algorithm. It doesn't do mutation, so at each stage, it has to return a new sorted list rather than sorting the list in place. As the list gets longer, the performance gets worse compared to an imperative quicksort. Now, quicksort would actually be implemented as a library, and would be tuned for speed. But the same issue comes up in other ways. If you have to transform data structures, imperative can be more efficient than functional, and the difference grows as the size of the structure increases. (I could have called this area "scaling" instead of "performance".) When could your problem be dominated by sequencing? It often is in embedded systems, where you're sequencing external hardware to get it to do real-world things. I mean, yes, you could write all that in a monad, but if that's the dominant thing you need to control, what does it gain you? All that said, making any individual function pure (in the FP sense) is always at least a local win, because that function becomes simpler to understand, debug, and test.
- Superpelican 12y ago>When could your problem be dominated by sequencing? It often is in embedded systems, where you're sequencing external hardware to get it to do real-world things. I mean, yes, you could write all that in a monad, but if that's the dominant thing you need to control, what does it gain you? That was exactly what I was referring to with the Arduino board example ;)
- chas 12y agoHaskell has been used to build embedded software to great effect. As you move out of the domain of simple sequencing in embedded systems and into hard realtime systems, coordinating tasks correctly becomes very difficult. Being able to track and infer information about timing and dependencies with the type system becomes extremely useful in order to make it easier. This is a very simple intro example of an DSL built in Haskell for realtime systems[0]. This is a talk on using Haskell for robotics in particular[1]. [0] https://leepike.wordpress.com/2009/05/05/an-atomic-fibonacci-server-exploring-the-atom-haskell-dsl/ https://leepike.wordpress.com/2009/05/05/an-atomic-fibonacci... [1] https://vimeo.com/77164337 https://vimeo.com/77164337
- bjourne 12y ago99% of all programming isn't cpu bound. Yes, programming to minimize your programs runtime on modern cpu:s, in contrast to keeping stuff simple, is a niche.