About the Author
Mass Effect
Final Fantasy X
Batman:Arkham City
Borderlands Series
Weekly Column
Champions Online
World of Warcraft
DM of the Rings
Good Robot
Project Frontier
Forums
"Music"



Object-Disoriented Programming

By Shamus
on Monday Sep 27, 2010
Filed under:
Programming

 
 

I program in C++ for a living. I loved doing it in my late 20’s and early 30’s, but over the past few years I’ve gotten fed up with this language and its cryptic aggravating bullshit.

One of the strengths of the language is the way that you can use libraries written by someone else. The language is 31 years old at this point, and odds are good that if there’s something you need your program to do, someone else has already come across the problem, solved it, and put the thing out there for people to use. For example, if you need a really fast algorithm for sorting a big wad ‘o data, or generating high quality pseudo-random numbers, then you don’t need to knock yourself out. Just use what’s already been written. There’s no reason to do it yourself unless you see some flaw in the existing solution and you think you can do better.

Things get tricky when you have a solution that incorporates another solution which incorporates another, and so on. You go and grab a chunk of code for (say) calculating the shortest distance between any two wombats. You think you’re done, but when you try to use it you find out it depends on other files you don’t have. It turns out the shortest-distance stuff incorporated someone else’s code, which was a program designed to differentiate between wombats and hamsters, which in turn used some guy’s 1988 C code to rate things according to how furry they are. Suddenly you’re performing some sort of archaeological data mining, looking for fragments of code written by a teenage Bjarne Stroustrup in 1965 and trying to translate his comments from the original Danish.

When someone shares their solution with the world, they can do it in one of two ways: The first way is that they can compile their stuff into a library. This is a binary file that you can hand to just about anyone and it will (in theory) be fairly easy for them to plug it into their own program. The downside is that every platform will need its own library. Linux? PC? Mac? 64 bit? 32 bit? It will be frustrating if a Linux developer shows up and you only have the PC version of your library available. And you can’t compile for a platform unless you have access to it. So if you don’t own a Mac then Mac users can’t use your stuff, thus limiting the reach of your work.

The other solution is that you can throw the source files out there and let everyone compile it themselves, which requires little effort on your part and lots of effort on theirs. The directions to compile someone else’s project go something like this:

1) Download all the source code. Now go and download a program to open the archive because they’re not using the archive format native to your operating system. (Windows has .zip, Linux has .gzip, Macs have .iforget.)

2) Follow the directions in the readme.nfo, which is a text file with no line breaks. This will explain how to arrange your project directories so that it will be able to find the needed files. If you’d like to see the directions in English, you can get them at the following dead link.

3) If you’re compiling on an IBM z800 then the source should be fine. For all other platforms, go through all the files and replace all the double backslashes in the header file paths with single pairs of reverse-backslashes. You may need to precede this with a period. Consult with an older programmer who is like a mentor to you. He probably knows about this kind of stuff.

4) Don’t do the previous step if your filesystem is case-sensitive.

5) You’ll need the source for the RaymondSort algorithm. Yes, there are dozens of popular sorting systems out there but RaymondSort is proven to be 0.1% faster in single-threaded environments where the computer has less than 100MB of memory to work with.

6) Go to the back room of Uncle Raymonds Bar in Pineville, WV on a Wednesday night. (The password is “Bob-o sent me.” They only change the backroom password when a new version of Windows comes out, so this password will be good until Windows XP launches.)

7) Ask Uncle Raymond for the source to RaymondSort. Don’t be offended if he tries to goad you into a knife fight. He’s like that.

8) RaymondSort files are written in ANSI C and a profane variant of Esperanto. You may need to make a few hundred perfectly trivial edits to them to get a clean compile. In particular, Ray’s favorite variable names were bool, class, new, and delete.

9) That’s it! When it fails to compile feel free to email me at the address I haven’t used since the Clinton administration and I’ll be happy to send you back curt replies admonishing you to RTFM.

10) Do a Google search and discover a three year old forum thread where a half dozen people all had the exact same problem you’re having now, which nobody ever answered. The last post is someone saying, “Nevermind, I figured it out myself” without elaborating further.

This weekend I was looking for something that would let me “easily” create standard interface widgets (text boxes, buttons, scrollbars, and all the other doodads we’re used to seeing in a modern user interface) within an OpenGL window. Basically, put various controls over a 3D rendering window. Designing interface controls takes an enormous volume of code, and I was sure someone else had done all that legwork for me.

I did a search and found about a half dozen that seemed interesting. So then it was time to evaluate them according to various criteria:

1) Is it cross-platform? The rest of my project is (in theory) compatible with PC, Linux, and Mac. Will using this package exclude any of those?

2) Is it neat and easy to use? Or do I need to #include a dozen different files everywhere in my project and write ten lines of code every time I want to create a new button?

3) Is it well-documented? A feature-rich system is no good if I don’t know what the features are or how to use them.

4) Does it actually do what I need? Will I get the thing running and discover that it (say) can only show a single control at a time or that the controls always look like Windows 98? Or that the controls actually float in a separate window and aren’t actually superimposed onto the 3D scene. Does it actually work at all?

5) Is it sufficiently humble? It’s a bit hard to describe this in non-programming terms, but different packages have different ideas about just how important they are. Some behave like small power tools. They’ll plug into the power strip next to all your other power tools and you can use them as much or as little as you need. Others act like they’re the whole workshop and expect you to plug everything else into them. In programmers terms, sometimes a package will insist on running the show. You instance a class and interact with everything else through that class. It calls member functions when it pleases, and you don’t get to control the program flow yourself. The package imposes a certain structure on your application. The fun begins when you have more than one of these jackass systems and you need to figure out how to make them work together. Also, it’s a bitch to debug applications that are built this way because trashing the heap will often cause the program to crash somewhere in the bowels of this overlord library and you can’t actually tell what the hell it was doing before things went pear-shaped. And asking for help will always get you helpful suggestion like “don’t trash the heap”.

It becomes a tremendous time-sink to try out a dozen different systems like this, because getting them to compile and integrating them with your project is such an enormous chore. I wouldn’t mind doing the work if I knew it was what I wanted, but this is like assembling a car before you can test-drive it. It’s entirely possible to blow a couple of hours on something and find out it’s not at all what you need. And when you’re working on it you have no idea how much more time it will take before you can see it work. You solve a problem to find another problem, on and on, never knowing if you’re anywhere near the finish line.

I lost a whole day to this over the weekend, and I have nothing to show for my effort. Everything I tried managed to fail multiple items on the list above. Most of them failed 3 out of 5. I don’t mind that I couldn’t find what I was looking for. (Well, I mind, but that’s not what’s really bugging me.) What bothers me is just how long it took me to run through the list. Every package I tried was a bundle of inscrutable errors. So much time is lost laboring over compile-time vagaries and linker misadventures. Nothing ever “just works” out of the box. Some of this is because this stuff is all thrown together by people who would rather waste your time than theirs. But some of it is because there are just so many things that can go wrong.

I didn’t used to have this much trouble. Maybe I’m just getting older and have less patience for it. Maybe the mass proliferation of homebrew libraries has flooded the world with wobbly projects made of tape and popsicle sticks. Maybe this is due to the chaos arising from the halting attempts at cross-platform development. (In the old days, almost everything I worked with was 100% Windows based. Now a lot of stuff is striving to be multi-platform. That’s good in the long run, but the resulting development anarchy is treacherous to navigate.)

Still, it’s really common these days. I can’t remember the last time I grabbed some code or a library and just had it work without needing to fix it first.


 
 
Comments (184)

1 2

  1. Peter da Silva says:

    This is why when I want to try out a new package, the first thing I do is look for a FreeBSD port of it. Even if I’m not planning on running it on FreeBSD. If there is, I “cd /usr/ports/foo/bar” and “make install”… and now I’ve got all the dependencies for the program squirreled away in /usr/ports/distfiles, along with documentation on where they came from.

    If there isn’t a port for it, I look for the solution with no dependencies. If there isn’t one, THEN I start panicking.

  2. dinosaur says:

    I’m so old I was already programming when there weren’t any languages yet.

  3. I admit I don’t code MUCH in CPP, however, I’ve programmed in several languages (some 10+, but of course, I only excel in a few).

    The thing is, the frustration I got from CPP is something out of this world. Really.

    For example, I don’t recall EVER building SUCCESSFULLY any CPP program which is not mine. Ok, I’m talking about Big programs, spanning thousands of lines (not counting empty ones ;)).

    Not to boast or anything, but I DID try compilation over a dozen MSVCPP versions, MinGW and of course BorlandC++, with various degrees of FAILURE.

    For instance, I tried several times to build PHP, but I never got it done ONCE. And that IS a Big program with Lots of developers. What gives??!!

  4. allan says:

    I suspect that this may be one of the OpenGL libraries you were complaining about in your post, but just in case it isn’t, have you tried PUI? It’s C++.

    http://plib.sourceforge.net/pui/

    I haven’t tried it, as I do not work in OpenGL that much, but when your mention of needing OpenGL user interface widgets tickled my memory about something on the Omniverous Biped FAQ.

    Hope that helps, or at least does not seriously annoy.

  5. MaxDZ8 says:

    The state of C++ libs is absolutely ugly.
    It is better to say that the state of C++ libs isn’t at all.
    GUI and internationalization is unbelievably BROKEN in a big way.

  6. Aybe says:

    I think you are right, sometimes (if not most of the time) it takes a ridiculously amount of time to try some library for your software and most of the time, it turns out to be a compromise.

    I dreamt of C++ but never used it, it’s so complicate and I did read that it’s very easy to make bad C++, so I decided to not use it. Even simple things like making a managed wrapper needs quite some knowledge. I started with VB and now it’s a few years I’m doing exclusively C#, I am certain I wouldn’t have learn that much in that time frame with C++.

  7. Henry XXXVI says:

    This is old, but it’s funny that you refer to the five things you want in a library you use; if you look at the language of C++ as a project itself, it definitely fails on several counts: it’s only as cross-platform as your compiler suite, C and C++ headers/libraries compete with each other, documentation of the idiosyncrasies of a given compiler suite tends to be spotty, although it does manage to get the job done.

    Unquestionably, C++ is not humble. It tries to be and do everything: an object-oriented, C-compatible, high-level language with low-level functionality, that retains the flexibility of run-time systems without taking a performance hit. The end result is a language that, to some extent, achieves nearly all of these goals, but at the cost of byzantine syntax and a hellish development environment.

  8. […] Sounds pretty easy huh? Well it should, however for me it was not (it never is, disagree? read this). […]

  9. […] Sounds pretty easy huh? Well it should, however for me it was not (it never is, disagree? read this). […]

  10. ricedilla says:

    Scroll scroll scroll for the answer to only find “Nevermind, I figured it out myself”. A troll’s masterpiece! How I hate it!

    or even better

    When you google for “something”, find a forum thread about “something”, but the only reply given is “GOOGLE it you moron!!1”. IJUSTDIDITZOMGinfiniteloopzFUUUUUUU!

  11. […] thing.  Shamus Young, over on his fantastic, educational, and inspirational blog, has a couple of posts dealing with code and library portability and modularity.  The gist is that you want your library […]

  12. Andrew_C says:

    After reading this post, I like to think that you have actually gotten into knife fights with Eric S Raymond and Richard Stallman over the quality of their code.

    Also I know how you feel about “never mind, I figured it out” posts. When I see them and the thread is still fresh I usually make a point of asking them to tell us how they did it for posterity. unfortunately the sort of person who does that usually never bothers to revisit the thread.

  13. WJS says:

    It kind of sounds like you’re saying that the ability to use libraries is a good point of C++, which is a little weird; are there any languages that don’t have the ability to use some form of library or another?
    (I’m pretty sure you’re talking about the sheer volume of C libraries, rather than their existence)

  14. WJS says:

    Coming back to this, I’m a bit confused by

    You can't compile for a platform unless you have access to it. So if you don't own a Mac then Mac users can't use your stuff.

    Um… isn’t that what cross-compilation is for? A decent compiler should be able to compile for all the common platforms, not just the one it’s running on. Ahh, wait… you use MSVS, don’t you? Never mind, then. That explains it.

  15. Alarion says:

    Sorry for reviving the post, but I’ve stumbled upon it from the front page and re-read it, and found the character encoding to the e-mail at “9) When it fails to compile feel free to email me at the address” broken. It probably should be a “You fool!”.
    Character encoding absolutely sucks. It can break in thousand places, and seems to propagate everywhere. It’s annoying whack-a-mole, is what it is. It would figure I have to deal with it in German, the language of the Umlaut. Vorzüglicher Spaß!

    Edit: Huh, and it also seems I just now broke the comment above me and the featured posts below me. Sorry about that. -.-
    Screen: https://imgur.com/a/TlZPb

  16. Olivier FAURE says:

    Looking at this a few years later: OH MY GOD YES on the “humble” part.

    This is the reason I can’t stand tools like Ogre3d or Qt. They expect your entire workflow to revolve around them, which makes it a pain in the ass to set up small test applications with them.

1 2

3 Trackbacks

  1. By How Hard Can it Be? « Proper Dev on Tuesday Oct 19, 2010 at 5:47 am

    […] Sounds pretty easy huh? Well it should, however for me it was not (it never is, disagree? read this). […]

  2. By How Hard Can it Be? « The Blinking Caret on Tuesday Nov 29, 2011 at 7:55 pm

    […] Sounds pretty easy huh? Well it should, however for me it was not (it never is, disagree? read this). […]

  3. By Fun With Procedural Images | Candy-Coated Bacon on Saturday Sep 28, 2013 at 9:43 pm

    […] thing.  Shamus Young, over on his fantastic, educational, and inspirational blog, has a couple of posts dealing with code and library portability and modularity.  The gist is that you want your library […]

Leave a Reply

Comments are moderated and may not be posted immediately. Required fields are marked *

*
*

Thanks for joining the discussion. Be nice, don't post angry, and enjoy yourself. This is supposed to be fun.

You can enclose spoilers in <strike> tags like so:
<strike>Darth Vader is Luke's father!</strike>

You can make things italics like this:
Can you imagine having Darth Vader as your <i>father</i>?

You can make things bold like this:
I'm <b>very</b> glad Darth Vader isn't my father.

You can make links like this:
I'm reading about <a href="http://en.wikipedia.org/wiki/Darth_Vader">Darth Vader</a> on Wikipedia!

You can quote someone like this:
Darth Vader said <blockquote>Luke, I am your father.</blockquote>