Hacker News new | ask | show | jobs
by dreta 3571 days ago
If you’re going to learn OOP, you need a larger project to go along with it so that you can understand ASAP that it only makes you write more code, over-complicate problems, and makes your applications hard to understand, and debug. It’s going to save you from spiralling into the typical “OOP is fine, i’m just not doing it right, i should’ve designed that differently” loop that most college graduates go through during their first professional years.
3 comments

I don't like OOP very much myself, but it doesn't have to result in "more code" (depends on a language support for concepts), doesn't have to lead to "over-complicating problems" (depends on language support and design skills) and it doesn't necessarily make your application hard to understand and debug (depends on the language, tooling and domain).

As with every tool you need to know how and when to use it, but it can be quite effective if done right.

(Over)using inheritance hierarchies can have negative effects, but if you think that in general OOP results in more code then you need to go and develop some serious C. You spend a lot of time manually accounting for multiple instances of things, in a way that you get for free in an OOP language like C++.
Right now i do iOS development mostly in pure C, outside of the unavoidable Objective-C. So i do have the right experience.

The issue with OOP is that as soon as you introduce inheritance, and things like virtual functions, you’re introducing variable program behaviour based on context. And most of the time you end up having to special-case things up in the hierarchy because nothing ever goes as you envisioned it.

Structuring your code so that you have simple data and code that operates on the data means that what’s happening in the code at a particular time is always explicit, and any deviations based on objects the code operates on are right there in front of you, not hidden in 4 virtual function implementations in different files.

It’s all special-case code you have to write anyway, but if written in OOP fashion, the complexity of it is most of the time unclear, and it’s hard to judge what code will actually be doing just by glancing at it.

More code, more complexity? See this: https://www.youtube.com/watch?v=8bZh5LMaSmE
The speaker just introduces more OOP complexity into already complex OOP code. All that’s going to do is make the code even harder to modify or step through.