This is a read-only archive!

C++, blech

I decided to try a GUI app. I decided to use QT4. I then quickly remembered why I don't ever use C++ for anything. The amount of bullcrap you have to go through just to get a simple program going isn't worth the bother for the kinds of programs I write. I spent an hour on this and I haven't even started writing any of the actual program yet. Just setting up boilerplate garbage, using qmake to make the project file used to make the Makefile used to compile my program someday if I ever actually progress far enough to write it. But no, the compiler couldn't find some of Qt's headers, so I get to hunt them down and pray. Nope, not worth my time. You know it's a bad sign when you can copy/paste a Qt tutorial right from the Qt docs and it won't compile.

I've always detested C++. I thought maybe I'd start liking it more as I learned more about how computers and compilers and interpreters work, but no, actually I like C++ less and less. I read some books on C++ a while back and it seemed nice at the time, but reading about a language and using it yourself are two very different things. I find myself disliking statically typed languages in general in ever-increasing amounts. And languages without garbage collectors seem archaic to me. And any language that requires you to learn multiple new languages just to be able to configure and use the tools used to build your program is ridiculous. I have a hard enough time getting my logic right, let alone having to hand-hold the computer while it laboriously and clumsily stumbles through my code. Ruby and Lisp have spoiled me.

And God help me if I ever want to run it on someone else's machine. Or a different OS. I started looking into how to compile Qt apps in Windows and now I shudder to think what I almost got myself into.

Interpreted languages are as close as anyone's going to get to "Write once, run anywhere". Step 1: Install Ruby. Step 2: Write Ruby code. Step 3: Run it. Short of places the OS leaks through like pathnames or system calls, your program will work. End. Underneath all of that, someone still had to figure out all the low-level crap. But someone smarter than me figured that out, and had to figure it out ONCE, and then it's done with and I can take advantage. Worst thing that can happen is I get some missing Ruby files and throw them in a directory somewhere Ruby can find them.

Programming after all is all about abstraction. Abstraction layers help us deal with complexity. Ruby is an abstraction layer over a mess of C code and compiled and linked binaries and libraries that I never have to look at. That's the way I likes it.

I was going to use Ruby's QT bindings for this app, but I want it to be multithreaded, which probably rules Ruby right out. Sad. Maybe Python has good Qt4 bindings. Horrifying though the thought of writing Python may be, at least the syntax is more stomach-able than C++.

April 01, 2008 @ 3:15 PM PDT
Cateogory: Programming
Tags: Python, Ruby, C, Rant


Adam Sloboda
Quoth Adam Sloboda on April 01, 2008 @ 4:36 PM PDT

AFAIK Qt has C++-like bindings in all languages (unlike Gtk+)

Quoth Brian on April 01, 2008 @ 4:38 PM PDT

Indeed, lots of languages. Qt is great. I think I actually figured out how to get my app working in Ruby without needing threads, which is great. If this doesn't work I'm sure Python will.

Adam Sloboda
Quoth Adam Sloboda on April 01, 2008 @ 5:24 PM PDT

So how can you not like C++ and be comfortable with Qt?

Quoth anonymous on April 01, 2008 @ 8:58 PM PDT

I thought with KDE4 all these coding problems were supposed to be abstracted away by the various frameworks? Wasn't this exactly the problem they were trying to fix when going KDE3 -> KDE4

Quoth Brian on April 02, 2008 @ 4:36 AM PDT

Adam: I like how the framework is designed and how nicely it runs. I don't necessarily like the language it's written in natively, which is a different concern. The other bindings mean I don't really have to worry about C++ if I don't want.

Quoth numerodix on April 02, 2008 @ 6:57 AM PDT

Woh, what? What's so bad about python all of a sudden? :/

Ciaran McCreesh
Quoth Ciaran McCreesh on April 02, 2008 @ 12:12 PM PDT

Garbage collection with C++ is largely pointless. If you don't want to deal with memory management yourself, don't. Just do every allocation using std::tr1::shared_ptr and you're set.

There're several advantages for not doing garbage collection, and providing easy memory management to people who want it...

First, garbage collection doesn't prevent memory leaks. It just means that when you do get memory leaks, they're a lot harder to track down and fix.

Second, garbage collection means you don't have controlled destruction. This means you have to arse around with try..finally blocks (which are verbose and easy to screw up) or Ruby-style resource blocks (which get messy when you have twenty levels of indenting) rather than simple RAII holders.

Third, garbage collection is in some cases too expensive. Forcing people to use it means some people can't use your language.

There's this strange notion that garbage collection is a 'more advanced' memory model. This may be true when compared to what C offers, but it isn't when compared to what C++ offers.

Quoth Brian on April 02, 2008 @ 12:37 PM PDT

All valid points. Point three depends what kinds of programs you write. Ruby is good enough for my purposes.

I'm not overly concerned with preventing memory leaks necessarily; I'm more interested in being as lazy as I can get away with.

numerodix: Sorry, Python is evil. :( Actually I can see why people like it, but it doesn't mesh with my thought processes at all.

Adam Sloboda
Quoth Adam Sloboda on April 02, 2008 @ 11:05 PM PDT


Well, I said the bindings are C++-like, so you have to bear with that -- unlike comfortable usage of blocks in Ruby bindings for Gtk+, if Qt bindings (copy of C++ API?) are now better than used to be, I'd like to hear about it!

Quoth Brian on April 03, 2008 @ 1:42 AM PDT

Qt slots / signals are kind of clunky in Ruby, yeah.