Hacker News new | past | comments | ask | show | jobs | submit login

> I had no trouble understanding object oriented programming

Indeed, Object-Oriented Programming is harder to learn for programmers who have experience with other languages already (no pun intended) ;-)

When you know a language like C/C++/Java and you learn about OOP you think you understand, but in fact, you don't. So while functional programming was probably the easiest course for me in university, it took me 1,5 semesters to actually understand OOP. In the end, it is not that complicated, it is just that you have to think more on the meta-level than on the implementation-level and I think, for someone who doesn't have access to the implementation-level, it is easier because it doesn't get in the way.




These programming paradigms are really all about impedance match with a model that's already in some human's brain -- going from the brain-space model to code with the least amount of transformation. So if you're struggling to get to the mind-model, something is wrong! It definitely doesn't make sense to begin looking at the implementation details. They're only there to facilitate that simple transformation from thoughts to code.


I dunno I think it might be kinda like quantum mechanics. If you think you understand OOP, then you definitely don't understand OOP.


Do you have a tl;dr you would care to share?


Well, my attempt to summarize OOP:

OOP is a concept. It doesn't care about the implementation and neither should you. So if you are talking about integers, don't care about the implementation which might have limitations like MAX_INT, care about the idea of having a number which you can increase and decrease. That is a concept and it can be implemented in different languages and with different limitations.

Next, understand the idea of 'Everything is an Object'. This means that you have a class hierarchy and at the top is the class 'Object' (so everything can do, what 'Object' can do). Objects can receive so-called 'Messages'. When an Object receives a Message, it calls the corresponding method. So for example, in Smalltalk (the mother of Object-Orientation) the expression '1 + 2' means, you have an Object '1' (always the first thing) which receives a message '+ 2' and when the method '+' is being called, it returns an Object ('3').

This leads to some odd situations like

  1 + 2 * 3
  = 9
because

Object 1 receives message + 2 returns object 3. Object 3 receives message * 3 returns object 9.

I think that is part of the secret sauce that many tutorials are missing. You can read a lot about the class hierarchy (inheritance, class variables, instance variables, ...), but few seem to care to explain what 'Everything is an Object' really means.

So your OOP program is basically sending different messages to different objects.

Finally, what makes OOP so powerful is that there are some attributes which are being enabled by placing your classes in the right spot of the class hierarchy, so that an object of that class does not just inherit all the attributes, but can also be used as one of its superclasses (polymorphism). That way you can write code that works with a wide variety of objects.

I am sure I missed a few things, but for me, understanding the clean syntax of Smalltalk and the implications of 'Everything is an Object' changed my perception of the OOP concept.


Frankly and in retrospect, I consider this difficulty a sign of the unsoundness if OOP. While with typed FP you can get entangled into some seriously complex mathematical models, in OOP it’s just a bunch of metaphors and mental models you have to convince yourself are true. The effort poured into memorizing one rarely transfers to unrelated frameworks or different languages, or at least does so to such a high level that it doesn’t help that much anyway.

OOP is easier to use when describing a mental model as-is, without the analytical deconstruction that (typed) FP would demand.


>1+2*3=9

I think this is a failure of Smalltalk, not OOP. I tried it in Ruby and Python (languages where everything is an object), both return 7.


You could certainly see it that way, but I found that it is a good example to illustrate the intention of having a very simple syntax and processing logic (up to the point where arithmetic expressions are not what you expect them to be).




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: