4 ms·
I love OO - but C++s objects are so bad that most of the time I just end up using functions-where-the-struct-is-the-first-argument, C style. If I'm feeling part
by lacampbell 9y ago
I love OO - but C++s objects are so bad that most of the time I just end up using functions-where-the-struct-is-the-first-argument, C style. If I'm feeling particularly energetic I might use the PIMPL idiom. But naiive use of C++ objects is absolutely painful for me.
All language constructs can be broken down into simpler ones, at the end of the day. We might talk about how subroutines are just overrated assembler macros. C++ isn't very clean so the fact that these fancy schmancy objects are just structs + function pointers is very obvious. But when done cleanly, I'd argue that an object is more powerful than the sum of its parts.
- nkurz 9y agoBut when done cleanly, I'd argue that an object is more powerful than the sum of its parts. I think I agree with your assessment of C++. What languages do you feel deal cleanly with objects so they exceed the sum of the parts?
- lacampbell 9y agoHonestly pretty much all of them if C++ is your reference point. Java, C#, Scala, Ruby, Ocaml...
- seanmcdirmid 9y agoI've seen objects recreated in Scheme and Clojure. They are really much more common than most FP people appreciate, just look for noun-ish naming conventions in your abstractions.
- lacampbell 9y agoIt's controversial for some people. OO is that horrible verbose enterprise code with all the mutable state. And if you suggest that certain features or patterns approximate OO they get very defensive. There are certain famous FP language implementers that should probably read what Guy Steele wrote in the topic, because listening to their talks I strongly get the impression they haven't.
- seanmcdirmid 9y agoOne could also just use a synonym of object, like "entity." "Hey...we aren't using objects here, we are using entities!" (Facepalm) I saw Guy's growing a language talk before, but I don't think he's ever chimed in on this debate before. Most people at his level simply except the world without much bias, and are comfortable using object and functional styles when necessary.
- LoSboccacc 9y ago"Actually I made up the term "object-oriented", and I can tell you I did not have C++ in mind" - Alan Kay
- gpderetta 9y agoGood thing then that Stroustrup didn't have Smaltalk in mind when he designed the C++ object model. He based it on Simula which predates Smaltalk.
- stinos 9y agoC++s objects are so bad that most of the time I just end up using functions-where-the-struct-is-the-first-argument, C style Can you explain more in depth why exactly? Is it because of e.g. http://stackoverflow.com/questions/5989734/effective-c-item-23-prefer-non-member-non-friend-functions-to-member-functions#5991173 http://stackoverflow.com/questions/5989734/effective-c-item-...? Or just not liking the syntax? Or private members?
- evacchi 9y ago> I just end up using functions-where-the-struct-is-the-first-argument, C style. I've been saying this for a while: of all C++/Java-style OOP we're mostly saving uniform function call syntax (cf. go, rust, nim, D and a bit C++17) !