“Functional programming” has a clear meaning, but does “functional language”?

后端 未结 10 2071
悲哀的现实
悲哀的现实 2021-02-01 16:12

I understand very clearly the difference between functional and imperative programming techniques. But there\'s a widespread tendency to talk of \"functional languages\

10条回答
  •  醉酒成梦
    2021-02-01 16:21

    I think the same question can be asked about "OOP languages". After all, you can write object oriented programs in C (and it's not uncommon to do so). But C doesn't have any built-in language constructs to enable OOP. You have to do OOP "by hand" without much help from the compiler. That's why it's usually not considered an OOP language. I think this distinction can be applied to "functional languages", too: For example, it's not uncommon to write functional code in C++ (think about STL functions like std::count_if or std::transform). But C++ (for now) lacks built-in language features that enable functional programming, like lambdas. (Let's ignore boost::lambda for the sake of the argument.)

    So, to answer your question, I'd say although it's possible to write function programs in each of these languages:

    • C is not a functional language (no built-in functional language constructs)
    • Scheme, Python and friends have functional constructs, so they're functional languages. But they also have imperative and OOP constructs, so they're usually referred to as "multi-paradigm" languages.

提交回复
热议问题