开发者

What's the difference between functional, structured and procedural programming?

开发者 https://www.devze.com 2023-01-29 23:06 出处:网络
I have read some articles 开发者_StackOverflow社区on all subjects, but I don\'t quite get the differences.Structured programming is an old term that I think would encompass functional, procedural, and

I have read some articles 开发者_StackOverflow社区on all subjects, but I don't quite get the differences.


Structured programming is an old term that I think would encompass functional, procedural, and much else. It basically means using explicit control-flow structures rather than jumping about directly from instruction to instruction.

Functional and procedural programming are both, in that sense, structured paradigms. Functional programming is also declarative programming -- the structure given to your code corresponds to its meaning -- a program is a function that changes the state of the world. Procedural programming is what you'd consider "typical" programming in any C language or its descendants, including OO languages such as Java and C++. A program is a series of instructions, to be executed serially, and invoking subprocedures along the way.

Or, as it has been famously described:

Functional programming is like describing your problem to a mathematician. Imperative programming is like giving instructions to an idiot.

    --- arcus, #scheme on Freenode


Functional programming is using functions as first-class elements. Making use of higher order functions (taking and/or returning functions); leading to powerful constructs and well factored code. Some people focus also on the purity aspect of FP which is to say that functions should always return the same result, given the same input. These, I believe, are the two basic pillars of FP. I also see avoiding side effects as essentially abstracting a bit away from the load/store machine level instructions.

Structured programming goes back to Djikstra's "Goto Considered Harmful" paper. It means using if/then/else/elif structures, do/while/until/for loops, etc. instead of resorting to goto. It's essentially abstracting a bit away from the compare/branch machine level instructions. Structured programming is orthogonal to both functional and procedural programming.

Procedural programming, I believe, refers to programming with imperative "subroutines" (as opposed to pure "functions") consisting generally of a series of "statements" (as opposed to "expressions") leaving behind side effects.


Also see:

  • Can someone give me examples of functional programming vs imperative/procedural programming?
  • OOP vs Functional Programming vs Procedural
  • truly understanding the difference between procedural and functional
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号