? Favorite Answer
I am a programmer, and I DON’T prefer object-oriented programming. I lean toward functional programming.
To each their own
Anyway, as Abelson says “It’s all air”. cons (construct cell) car (first of cell) cdr (second of cell) are normally considered “fundamental” with lists – first is the data, and second is a pointer to the rest of the list. But, as Abelson shows in “Structure and Interpretation of Computer Programs”, if you have first-class functions and closures:
(define (cons x y)
……((= m ) x)
……((= m ) y))))
(define (car z) (z ))
(define (cdr z) (z ))
works as definitions of cond, car, cdr. cons returns a function, that, if invoked with an argument of , returns the first part of the cell, and with an argument of , the second part. Indeed, you can easily add to it (say, to make triplets, etc.).
Oh… and you notice that the function has methods? x and y are not accessible, except by calling the anonymous returned function with an argument. This is “object oriented programming”, even though it is a function that is a closure over x and y.
Is your head hurting?
As to the “answer”
– data and methods are encapsulated and may be easier to reason about. Isolation helps.
– classes can model the problem domain
Who said that programmers prefer object-oriented programs? Object-oriented programming is just another in a long series of programming fads, and neither helps nor hurts the profession. Good programmers know this.
I like procedural programming.
I debate this often with colleagues. They claim an advantage of having useful reusable classes. I claim, I know how to write organized sub-routines and functions. To top it off I can get done with a project quicker since I spend time thinking about the best way to write code. Not the efficient way to organize OOP structure.
OOP is encapsulation, therefore you can locate the line of code you want to evaluate because Objects have a name grouping () values () states () behaviors.
The objective of OOP is to have a common named method() and loop over a collection of Objects invoking one line of code — one command different behaviors across different Object types.
. adding data structures is much more straightforward
. building a modular program is much easier