OOP is overrated.
by
, 01-24-2010 at 04:55 PM (1627 Views)
Don't get me wrong. I have nothing against OOP. I just don't see what's with all the hype about it. Everyone's like "Yay! OOP! Now I can have things in my program. I can ecapsulate data and do modular programming and $hit." But the reality, at least as I see it, is that "object-oriented" is just a buzzword that is nothing more than a rebranding of something that has been in existence since programmers stopped using machine language. It's an empty shell. Pretty much anything you can do with OOP you can do with procedural programming. Let me explain...
Data abstraction:
Data abstraction provides separation between the interface to an object and its implementation. OOP provides data abstraction by allowing the programmer to group related data and functions into discrete units. What exactly does this do that can not be done with records or structures?
Here is how you create methods and properties in Java:
Here's how you would do almost the exact same thing in C:Code:public class Foo{ public bar( ){ /* do something with var */ } private var; }
One method knows to use a member of that class because it's included in the class. The C function knows to use a member of the structure because it takes the structure as input. They are practically the same thing.Code:struct Foo{ int var; }; void bar( struct Foo foo ){ /* do something with foo.var */ }
Both the Java class and the C structure are abstract data types. But the C function does not require the programmer to know that var exists, which actually means that in a way the information hiding scheme is better.
Encapsulation:
Encapsulation is the grouping of related properties and methods into a single unit. Many object-oriented languages force you to group functions and variables together, even if they are completely unrelated. Java is a good example of this in that everything has to be encapsulated in a class. C gives you more flexibility. You get to choose whether you want to encapsulate your data or not. And if you do, just use a header file.
Inheritance:
This is the only area that procedural programming languages are really lacking in. The ability to reuse information is invaluable to a programmer. However, the frequency of having to reuse information in this sort of way is, as far as I can tell, not very great. I have tried to find a way to use inheritance in a useful way, but with no success. All it does in my opinion is make the code look messy, and force whoever is reading the code to search up through the entire hierarchy of parent classes to gain any comprehensive idea of what properties and methods a class uses.
Public and private members:
In my opinion, having members be public and private is just a waste of time. Every variable you create has to have a corresponding set or get function, which adds 3x more lines of code, where x is the number of private variables. If you want to make a variable read-only, just use const.
To add to that, pretty much any language with pointers will allow the programmer unlimited access to private members. This is what C++ does. That sort of takes away the whole point, and all the set and get functions you created just take up space.
Spaghetti code vs. lasagna code:
Both OOP and procedural languages are susceptible to producing spaghetti code, that is, code in which the control flow is hopelessly unclear. OOP languages, however, have an added danger: lasagna code. This is when layers are used to such an extent that they practically lose their meaning and are impossible to make sense of. Procedural languages are in their own way susceptible to the lasagna code effect as well, but it's a lot easier to avoid. One primary cause of lasagna code is the abuse of inheritance.
Widgets:
Apparently, using widgets to create a GUI makes programs easier to write and more compact. Well, let me show you a very simple GUI program in Java that does almost nothing:
All this does is create a button that says "Click me", and when it is clicked, the button says "I've been clicked". It isn't even scaled or anything.Code:import javax.swing.*; import java.awt.event.*; public class SimpleGuiB implements ActionListener{ JButton button; public static void main(String[] args){ SimpleGuiB gui = new SimpleGuiB(); gui.go(); } public void go(){ JFrame frame = new JFrame(); button = new JButton("Click me"); button.addActionListener(this); frame.getContentPane().add(button); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 300); frame.setVisible(true); } public void actionPerformed(ActionEvent event){ button.setText("I've been clicked"); } }
I hate Java.
In conclusion, I think that OOP capabilities are good for a language to have, as long as they aren't over-emphasized and don't get in the way. Forcing the programmer to use classes for everything is not good practice (one exception to this is Javascript, in which there are predefined classes and objects that actually do something, without you having to write 20 extra lines of code to use them). OOP should be an extra tool that you can use, sort of like the bitwise operators. It should not be the heart and soul of the language.
Perl is a good OO language. So is PHP. They represent the ideal situation, a balance between paradigms.










