Thinking About Programming

Ask Me How Much I Hate XCode and C

Posted: 12/12/2007, Readers: 2883 Perm Link


In the mid-90's I spent 5 years working exclusively in C++ after years of C. I learned all the ins and out of STL, templates, overloading and the like. Now after 10 years of Java I've spent a little time working with C++ again - working on some game code for WWIIOnline, rewriting my sound code again to support Core Audio in Leopard (and eliminating OpenAL use).

Argh, C++ is so painful to me now, and XCode as an IDE is beyond lame compared to my beloved IntelliJ and even the recently learned Eclipse. Poke me in the eye with a C# stick, it would hurt less.

XCode is the latest generation from Apple, going back to the early days of MPW in the 80's, and then passing through the tools from NEXT. Some days I really feel that the folks at Apple have never worked with a real Java IDE. Other days I feel sorry for them having to carry the baggage of a generation of make files and command line tools around all day. I mean IntelliJ and Eclipse are constantly compiling the Java source while I am typing it in, making it easy for the IDE to spot errors, inconsistencies, provide tips and hints and refactorings on the fly. C++ (and even Objective-C) despite on paper being faster in execution, apparently cannot be compiled fast enough to provide the same level of feedback. With IntelliJ I rarely ever see a compiler error. With Eclipse I rarely even see the compiler at all.

So working in C++ and XCode is really painful for a Java guy like me. Yeah if I was working in Cocoa and Objective-C, it might be more pleasant, but that's not the option here. Even then, in XCode I miss all the help I get from the IDE's that I'm used to. I know people love vi and emacs and swear by command lines but I don't miss the command line these days anymore than I miss the IBM PC XT.

Of course C++ all by itself is a painful language anyway. Sure, I can create the most complicated meta-templated code I'll never understand 5 minutes later but how is that productive? I remember when I first started working on this it took me ages to remember all the requirements for storing objects in a map. Maybe my brain has been too comfortable in Java where putting an object in a HashMap is just that. Maybe the occasional overriding of hashCode() and equals() but nothing much to remember.

Don't get me thinking about memory management. In Java I don't. In C++ you always have to remember when to get rid of stuff. At least in the latest Objective-C they finally added automatic garbage collection. This is the 21st century after all. As Homer Simpson once sang in an episode where he becomes the garbage commissioner "let someone else do it".

I wrote a commercial C++ memory manager in the 90's so I'm well aware of what it takes, and even wrote the whole thing in heavily templated C++, but that was a century ago it seems. Today I'd rather work on the problem at hand instead of futzing with a language and tools that get in the way. Of course for some folks even Java gets in the way (and I understand that as well but it's not a choice for my job yet) but at least it's not C++.

When I read about the newer features being added to C++ I can only think of all the profits the Tylenol folks are going to get. Effective use of C++'s features requires a real dedication to understanding their strengths and weaknesses. It's not a language for occasional use. When I used it everyday it was painful but familiar; today having worked with Java I have a hard time keeping C++ features in my head.

The bottom line for me is I want the computer to do all the heavy lifting, and let me focus on the actual work to be done with as little annoyance and loss of focus as possible. No matter what language or tools you choose they better meet that requirement (for you) or try something else.

Or break out the pain killers.

Tags: xcode, java, c
codist 12/12/2007 21:51

My blog code ate the C++ in the title. Must be a Java problem :-)

teqman 12/13/2007 04:28

You are aware that Apple is writing a new compiler (llvm-clang) so that it can support many of the very features you're complaining about?

Anonymoose 12/13/2007 04:45

In C++ you always have to remember when to get rid of stuff.

C++ has a better resource management setup than Java or Objective-C. It's called a destructor. As soon as your object leaves scope, it's cleaned up, instantly. Sure, sometimes objects have more dynamic lifetimes, but that's what smart pointers are for.

As a Java programmer, I'm sure you're familiar with the pain of writing a correct try/catch/finally (it's not hard, it's just -annoying-) sequence to make sure all of your files, sockets, etc. are all closed. Isn't it a bit crazy that .close() can throw exceptions? C++ fstreams are closed automatically, whether by exception or early return, hook or by crook.

Agreed on all other points, though.

Stephane Grenier 12/13/2007 10:57

That's exactly the reason why I can't go back to my old C++ days.

Above this, languages like Java have also removed things that can greatly reduce productivity like operator overloading. Sure it helps the original author write faster, but every person afterwards can be negatively affected. It's hard to read code where every other file the operators can mean something else. And the reality is that over the code's lifecycle, a lot more time is spent trying read and understand it than writing it.

But you're absolutely right. The IDE's are great. The language does a lot of things for you that you now take for granted. I can't go back :)

Miro 12/14/2007 20:16

To Anonymoose:

Objective-C does have destructor too. Read the manual.

bobert 12/16/2007 00:09

I've stuck primarily with C/C++ since the Jurassic when Andrew and Ken I were carving Trapeze into the Mac silicon while fending off velociraptors. We happily used Lightspeed C (later Think C), which was fast because Michael Kahl's idea was that programmers work best when the compile/link/test cycle is as rapid as possible.

When Symantec ate Think and turned it into mush, and Michael jumped ship to Metrowerks, I then switched to CodeWarrior, and used it cheerfully to write C/C++ for MacOS and Windows. In addition to an incredibly fast compile/link cycle, it had a very simple user interface. You had a small project window, and as many source file windows open as you wanted. The configuration for a project was very simple, too. The 20% of the settings you needed to fiddle with 80% of the time were easy to get to, and the rest weren't too hard, either. And the source-level debugger was simple but brilliant. In fact, on Windows, I would often write a UI in Visual Studio/MFC, and put all the non-UI functionality into DLLs that I built with CodeWarrior.

But now CodeWarrior is no more for either platform. Nowadays, I mostly use GCC on Linux, XCode/GCC on MacOS, and Visual Studio on Windows. And my productivity has dropped through the floor. Why?

  1. Slow, slow, slow. Inexcusably slow. CodeWarrior is at least an order of magnitude faster than Visual Studio, and maybe two orders faster than GCC, at compiling and linking the same files on the same hardware. So instead of zoning out for a few seconds after editing code while I wait to see the effects, it's often minutes, which leads me to do something else (like read a blog), and then I'm toast. (Apple's answer to CodeWarrior junkies is: buy a lot of Macs and network them into a private build farm. Yah.)

  2. Complicated. Take a look at the complete list of build settings for a target in XCode or Visual Studio. What the heck are all these things? And my experience with XCode has been that for any project beyond trivial (e.g. something that uses shared objects or frameworks you build yourself), you really have to know what they all are and have all of them set right or they'll bite you hard. Ditto with Visual Studio when it comes to things like which version of the standard C library to link with (multithreaded/single-threaded, DLL vs. static, yadda yadda).

  3. Inflexible, especially GCC. Say you have a piece of code that would normally generate a warning, but you know it's ok. In Visual Studio, and in CodeWarrior, you could turn an individual warning off for a section of code in a file, then turn it back on. Not in GCC/XCode. (And don't get me started on why GCC doesn't have fine-grained warning control.)

I still love what I can do with C/C++. There are days when I work on C/C++ code all the way from end-user apps, through middleware like modding the open-source GTK package, into farily low-level stuff like hacking my X server's attachment to the hardware frame buffer, and even dig around in the Linux kernel. But it sure would be a lot more fun if the tools didn't suck so much.

IT 12/25/2007 03:31

Actually, Homer said "Can't someone else do it?"

Mark Usher 06/13/2008 10:58

Dear Codist,

Would you have any objection to me using (and of course referencing you in the process) your EXCELLENT train wreck definition in my own blog on procurement (URL above)? I am putting together a top ten list for the "Top Ten Surefire Strategies for Producing a Procurement Project Train Wreck". I was planning to publish this post in my blog in the next week or so.

Thanks!

Mark Usher

codist 06/15/2008 14:46

be my guest :-)

Chelsius 07/13/2008 19:24

Unbelievable! Have you ever heard of planning your code in advance and THEN compiling? What are you doing? Writing a line of code, then hitting build so you can see whether or not it works, then writing another line of code? This is precisely how bade code is written. When I write code, mostly device drivers and embedded firmware, it's generally three compiles until it works and if there isn't a hardware issue, another 4-5 before it's shippable. That's because I have my code fully architected and planned out before I start writing anything. It's not one big experiment. Yikes!

codist 07/14/2008 23:00

You sure have a lot of comments for someone who writes firmware for a living. Ever written a commercial shrink wrapped application from scratch? I've written 3, totaling about 500,000 customers over all of them.

By the way I've been writing code since 1974. I think I know how by now...

John 07/26/2008 07:51

I love C, I used C a lot in the old days, I hated C++ it is a painful and horrible language and still sucks but now Im using Java, Python and Erlang and I feel great I will never go back, just to C and only C when i really need low level programming.

(C++ can burn in hell)

Marjan 08/26/2008 05:01

chelsius, writing a driver is incomparable against business application. Driver doesn't change, business apps do alot.

Marjan 08/26/2008 05:04

I am sorry for consequences java has done to software development. 15 years ago anyone could programme. Now it looks like only universe-people properly can. Fuck that!