The difference between OOP and functional programming (diagram)

I watch a video course / lecture from Stanford. Course "Structure and interpretation of computer programs"

In the first lecture of OOP, the teacher (Brian Harvey) describes the OOP method as one that gives different answers to the same question, and a function in functional programming gives a certain conclusion for a certain input.

The following code is an example of a method in OOP that gives a different answer with each call: -

(define-class (counter)
  instance-vars (count 0))
  (method (next)
    (set! count (+ count 1))
    count) )

Now, although the course is illustrated by a diagram, I did not pay much attention to the language itself, so I cannot explain the code; but can't a similar "next" function do the same thing as this "next" function? In C, I declare a global variable and each time I increment it by one when calling next. I know that C is procedural, but I assume that a similar thing can be done in the Scheme.

+5
source share
4 answers

. , "", " ". , , , , , . , , , , - , , - , "", , , .

, :

  • . ( - ) ? , - ? x = 4, , x 4 x , , - ( x)?

  • . , , ? , , , , ?

, C struct, . , , (. "" ).

, , .

, , , .


- , : , /, , / , , , . , , .: P

+7

Haskell wiki, . Haskell - , , Haskell.

OOP

- :

-:

:

  • ?
  • : Class
  • :

:

  • ( ), , , . - , .

:

:

  • ?
  • :
  • :

:

- ( ) - , :

1. :

, , .

  • Lisp car, Haskell first, .

  • Haskell take, n , , , .

  • first map, reduce fold .

  • map apply .

2. :

( ).

  • () (). . , . , concurrency!

3.

  • (, , ), , .
+7

"" . . .

, , C, . . , , Haskell.

( ) . , , , .

+1

, , C.
- ++ count.

0

All Articles