Defining point of functional programming

前端 未结 8 1638
无人及你
无人及你 2020-12-31 01:17

I can enumerate many features of functional programming, but when my friend asked me Could you define functional programming for me? I couldn\'t.

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 01:33

    From wikipedia:

    In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast with the imperative programming style that emphasizes changes in state.

    Using a functional approach gives the following benefits:

    • Concurrent programming is much easier in functional languages.
    • Functions in FP can never cause side effects - this makes unit testing much easier.
    • Hot Code Deployment in production environments is much easier.
    • Functional languages can be reasoned about mathematically.
    • Lazy evaluation provides potential for performance optimizations.
    • More expressive - closures, pattern matching, advanced type systems etc. allow programmers to 'say what they mean' more readily.
    • Brevity - for some classes of program a functional solution is significantly more concise.

    There is a great article with more detail here.

提交回复
热议问题