Best modern language to learn object oriented programming
11–16 of 16 posts
Re: Best modern language to learn object oriented programming
#12I don't know if it's best, but I took on OOP in little bites: - ECMAScript 5 Mixins, scopes, instance variables, and instantiation. As a bonus, but not OOP, callbacks. It's a straight-forward language that's available abundance. - Python For it's class inheritance being easy to navigate. Instance variables, instantiation, method resolution order (MRO), mixins. - C++ This is the hardest language I can think of. It doe…
C++ doesn't do everything OOP: it doesn't support the late bound message-send style OOP of Smalltalk at all. In particular, you can't implement #doesNotUnderstand: ( http://wiki.c2.com/?DoesNotUnderstand ) or replace one object with another unless they have a superclass-subclass relationship.
Despite it looking cool and useful, IMO it's more of a (quite pleasant) sugar than an OOP concept. There's also a try/catch example where you'd get similar behavior.
I feel this is a bit opinionated:
> "but this is clearly rather verbose and it has to be repeated for every call."
I think the example in the link is what try/catch is meant for. Message passing systems in C/C++ handle situations where a disabled/unavailable service receives communication and recovers.
As for C++ and replacing objects:
I feel this is also a language-specific gotcha that doesn't hinder a learner understanding OOP. But C++ has many more gotchas than that.
For instance, there's no pure "interface" keyword. It can still be done (and is), code example: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines..., how Google Style guide defines it: https://google.github.io/styleguide/cppguide.html#Interfaces
Re: Best modern language to learn object oriented programming
#13Have you tried F#? Its multi-paradigm and might make some thingd clearer. You can later move to C# and onto others. :)
I've tried OCaml, which I absolutely loved. I'd considered approaching F# before, since the language seems promising from a functional perspective, but I'm skeptical of the multiparadigm claim. In your experience, is F#'s OOP support beginner friendly? Also, is there decent literature available on F# as an OOP language?
The OOP docs for F# are average (not amazing). Feel free to email me!
Re: Best modern language to learn object oriented programming
#14Earlier quoted context omitted.
C++ doesn't do everything OOP: it doesn't support the late bound message-send style OOP of Smalltalk at all. In particular, you can't implement #doesNotUnderstand: ( http://wiki.c2.com/?DoesNotUnderstand ) or replace one object with another unless they have a superclass-subclass relationship.
It's the first time I heard of #doesNotUnderstand Despite it looking cool and useful, IMO it's more of a (quite pleasant) sugar than an OOP concept. There's also a try/catch example where you'd get similar behavior. I feel this is a bit opinionated: > "but this is clearly rather verbose and it has to be repeated for every call." I think the example in the link is what try/catch is meant for. Message passing systems i…
The core difference is "late binding" -- in languages like Smalltalk, the mapping from names to methods is evaluated at runtime, not at compile time like Java or C++. Looking things up at runtime makes the system less efficient, but makes it easier to change pieces of the system independently.
Re: Best modern language to learn object oriented programming
#15Earlier quoted context omitted.
It's the first time I heard of #doesNotUnderstand Despite it looking cool and useful, IMO it's more of a (quite pleasant) sugar than an OOP concept. There's also a try/catch example where you'd get similar behavior. I feel this is a bit opinionated: > "but this is clearly rather verbose and it has to be repeated for every call." I think the example in the link is what try/catch is meant for. Message passing systems i…
In C++, if you try to call obj->method() where `method` is not defined on the object, it won't throw an exception: it simply won't compile. In Java, the "class cast exception" is a somewhat different concept. Even if both classes support the same method, you can't cast between them if they don't have a superclass-subclass relationship. The core difference is "late binding" -- in languages like Smalltalk, the mapping…
I read the page, I liked it. It shows a try/catch is how it'd be done.
> In Java, the "class cast exception" is a somewhat different concept. Even if both classes support the same method, you can't cast between them if they don't have a superclass-subclass relationship.
I find that fascinating. But still, another case where it's more a rule and intricacy of the language.
This is the latest C++17 draft (2017-03-21) http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n465....
So here's why I go on about it being an intricacy of the language: The amount of casting / type rules and so on in C++, for instance, is mind-boggling.
> The core difference is "late binding" -- in languages like Smalltalk, the mapping from names to methods is evaluated at runtime
Which is interesting. And cool.
Isn't that similar to, an extent, virtual functions / vtable'd methods in C++?
But how does this wrap into C++ not handling an aspect of OOP? In your words. Even though I feel #doesNotUnderstand is a sugar and not necessarily a whole OOP concept, I think it can handled via an event system and try/catches.
Re: Best modern language to learn object oriented programming
#16Earlier quoted context omitted.
In C++, if you try to call obj->method() where `method` is not defined on the object, it won't throw an exception: it simply won't compile. In Java, the "class cast exception" is a somewhat different concept. Even if both classes support the same method, you can't cast between them if they don't have a superclass-subclass relationship. The core difference is "late binding" -- in languages like Smalltalk, the mapping…
> In C++, if you try to call obj->method() where `method` is not defined on the object, it won't throw an exception: it simply won't compile. I read the page, I liked it. It shows a try/catch is how it'd be done. > In Java, the "class cast exception" is a somewhat different concept. Even if both classes support the same method, you can't cast between them if they don't have a superclass-subclass relationship. I find…
Dog *dog = new Dog()
LoggingWrapper *wrapper = new LoggingWrapper(dog)
wrapper->runAround()
The program should output a log entry like "Dog->runAround() called", then the dog should run around.In Smalltalk, you can implement `LoggingWrapper doesNotUnderstand:` to output the log entry; something like:
doesNotUnderstand: aMessage
Logger log: target class, ' ', aMessage selector, ' called'.
^ aMessage sentTo: target.
It's not impossible to implement a class like LoggingWrapper using vtables -- in order to make a vtable, you have to know all a class's methods at compile time, but LoggingWrapper can respond to any method its target responds to.