4 ms·
"There are some things that are easier to do efficiently with imperative languages. And one can generally easily write functional code in a modern imperative la
by j_baker 16y ago
"There are some things that are easier to do efficiently with imperative languages. And one can generally easily write functional code in a modern imperative language (C# for example has many, if not most, of the tools available in popular functional languages)."
Really? When did they add pattern matching, algebraic data types, and reliable tail call elimination?
Reality is that imperative languages provide about as much support for functional programming as functional languages have for imperative programming: just enough to get by. And I would even say this is a good thing (perhaps excluding lisp: it can do everything due to sheer elegance rather than due to bloat).
- silentbicycle 16y agoOCaml is a pretty decent imperative language, actually. It's intentionally multiparadigm rather than pure FP, though.
- kenjackson 16y ago"Really? When did they add pattern matching, algebraic data types, and reliable tail call elimination?" I didn't say all features. In fact I said "has many, if not most". I was trying to be explicit that not all features that exist in every functional language exist. Now with that said, the specific features you list, while popular, weren't widely considered "necessary" features to be classified as a functional language. For example, Scheme has neither pattern matching nor ADTs. Although I'll grant you that for modern functional languages its near a prerequisite. And AFAIK tail call elimination is less a function of the language, and more of the implementation (and I'd argue to the extent that you write in a functional style, many/most production quality compilers of imperative languages will do this optimization). Of course I could be wrong and maybe some functional languages define in their spec exactly when tail call elimination must invoked. If you look at what is commonly the crux of functional languages you'll see things like: * Recursion -- yes, there was a time imperative languages didn't support recursion. So when they were arguing Lisp vs Fortran this was relevant. Now this seems like such a passe feature of all languages, but I think its worth point out. * First class functions. * Lambdas and closures * Immutable data * Pure functions * ADTs or other interesting type systems And there are some second order features like list comprehensions. Again, I think if you go through this list, you'll see that modern imperative languages capture a lot of these features. Not necessarily all of them, but I have discovered that I've been able to do some relatively straightforward ports of functional algorithms, keeping all of the functionalism intact.
- philwelch 16y agoOf course I could be wrong and maybe some functional languages define in their spec exactly when tail call elimination must invoked. Scheme does. I believe it was widely considered an innovation in the field of programming language specification that they specified that.