Dare wrote:Thanks for the response. Do you mean simpler in "readability" or in actual end-product (app generated)?
I agree that OOP syntax is nice to read. However I think it could produce mammoth code, with functions calling functions, extra data, etc.
Object oriented code, in my personal opinion, is easier to read and maintain than functional code. However, I've also been programming in C++ for many years, and more recently, C#. The "readability" of something is very subjective, so it really depends on the programmer.
In general, object oriented programming languages tend to create larger executables. To some extent that's because of the infrastructure of the language itself, but mostly it's because of the class libraries that are typically linked in. Note that doesn't mean that object oriented code is inherently slower than functional code; that depends on implementation. It just means that its typically larger.
If you want a practical example of where OOP is beneficial, just consider Windows programming and its massive API. As an example, let's say that you wanted to change the the Z-order of a window so that it was brought to the front. Quick, using the SDK and without looking at the API reference, how would you do that?
Here, I'll give you a hint: it's the SetWindowPos function. Now, what are all of the arguments that you need to pass to it? Another hint: there's 7 arguments to the SetWindowsPos function.
So, with SDK style programming, you end up writing code that would look like this:
Code: Select all
bResult = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW);
The last argument to SetWindowsPos has about 15 bitflags, I've just used three of them. Can you remember them all? (I know I sure as heck can't).
However, in an object oriented language, you'd have something like a CWindow class and you could have a method like:
Because the API is encapsulated in a class, you don't need to worry about all of those complex API calls and what the parameters are because they're "wrapped" by methods in the class. And, because that CWindow class serves as the "base class" for other window objects, that means that the Show method above could be used for all kinds of windows.
The programmer doesn't need to understand how Show() works, or that under the covers, it calls SetWindowPos with a lot of arguments and bitflags he knows nothing about. He just knows that it works.
Of course, that's just a simple example. But the basic idea is that it lets the consumer of that object (the programmer) focus on the result, not the implementation. On the other hand, that's why some programmers object (no pun intended) to OOP. They feel that it isolates you too much from the underlying system and presents too much of a "black box" to the programmer. They argue that instead of being a "real programmer", you're little more than an assembly line worker, fitting together the pieces of a jigsaw puzzle (mostly) created by someone else.
Like I said, it's all a matter of perspective.