Extending C++ Objects

Member
Posts: 254
Joined: 2005.10
Post: #1
I was wondering if anyone knows enough about Objective-C's runtime system to write a new root C++ object that implements some of Objective-C's dynamic features? Is that even possible? Just a thought I had the other day.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
http://doc.trolltech.com/4.1/qobject.html

It's horrible. If you want a dynamic OO language, use a dynamic OO language. Like ObjC, perhaps Wink Or Python, Ruby, or any number of others.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #3
While I agree with OSC that it's horrible, it's horrible only in that it's a pre-compiler hack, rather than a true language feature.

Trolltech's C++ API is actually quite nice, so long as you use a build system which runs the moc ( meta-object compiler ) before passing the code to GCC. I've done a *lot* of Qt programming, and in my opinion, it runs a close second to Cocoa/ObjC. It gives you pretty much everything ObjC does, except that you get proper C++ RAII and templates, which is *awesome*. The only reason it's a close second to Cocoa/ObjC is because it *is* a hack, and as such you need to understand that it's a hack when you write code for it.

I can't speak for truly dynamic interpreted languages, since while I have written a fair amount of Python and a touch of Ruby, I've never written anything complex in them.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
I've also done a lot of Qt programming, and I'm going to have to violently disagree with TomorrowPlusX. Aside from the "hacking dynamicity into a completely non-dynamic language" horrible-ness, Qt goes out of its way to force you to design your application poorly. The way that setting a widget's value programmatically fires the same value change notification that the user typing in it would is particularly nasty. I also don't know how you can say it's a "close second" when its table view is completely useless... I understand Qt 4.x is better in that regard, but I haven't tried it.

I wouldn't touch Qt with a barge pole, basically. If you want a cross-platform GUI, Java's Swing is a *long* way from perfect, but it has a workable table view, and doesn't try to force poor designs on you, even if it doesn't help much with good ones. If you don't need cross-platform-ness, Cocoa on the Mac is of course uncontested, and I've heard very good things about both Delphi and .NET's System.Windows.Forms, and GTK is nice if programmed from Python or Ruby as opposed to C...
Quote this message in a reply
Member
Posts: 254
Joined: 2005.10
Post: #5
On a related note, what about a retain/release/autorelease system for c++?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
That works, of course, and you can even get C++ to automatically retain and release at appropriate moments via smart pointers. The downside is that you either have a second indirection, or make all your objects subclasses of a class that handles the reference counting.

There are also garbage collectors for C++: http://www.hpl.hp.com/personal/Hans_Boehm/gc/
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #7
OneSadCookie Wrote:I've also done a lot of Qt programming, and I'm going to have to violently disagree with TomorrowPlusX. Aside from the "hacking dynamicity into a completely non-dynamic language" horrible-ness, Qt goes out of its way to force you to design your application poorly. The way that setting a widget's value programmatically fires the same value change notification that the user typing in it would is particularly nasty. I also don't know how you can say it's a "close second" when its table view is completely useless... I understand Qt 4.x is better in that regard, but I haven't tried it.,

Yes. Actually, I forgot about the complete lack of MVC in Qt. Doing a tree in Qt, while easier than in Cocoa, was a mess of context-specific hackery, completely unencapsulated. I wouldn't call it useless, though. It worked, and it was easy to program for, and the documentation was excellent. But table and tree code got spaghetti'd instantly. Cocoa does, in a sense, *enforce* good app design, and that's a plus.

Quote:I wouldn't touch Qt with a barge pole, basically. If you want a cross-platform GUI, Java's Swing is a *long* way from perfect, but it has a workable table view, and doesn't try to force poor designs on you, even if it doesn't help much with good ones. If you don't need cross-platform-ness, Cocoa on the Mac is of course uncontested, and I've heard very good things about both Delphi and .NET's System.Windows.Forms, and GTK is nice if programmed from Python or Ruby as opposed to C...

I would happily touch Qt with a barge pole, but since I'm not concerned with cross-platform programming anymore, I'm happy to stick with Cocoa. As much as I love C++ ( and 95% of what I write is C++ ) I actually prefer ObjC. I generally write my models in C++ and write my Views and Controllers in Cocoa. Works for me.

Regarding the .NET languages and APIs, Mono's GTK# and Cocoa# are appealing, and it looks like it will have a reasonably strong future on the Mac platform.

And, I have to agree with OSC on one front -- GTK is a mess when you're programming in C. Just a god damned unforgivable mess. From Python and C#, however, pretty slick.
Quote this message in a reply
Post Reply