www.derf.net / thoughts / 20050417_c_plus_plus /
<< prev in "random thoughts" random thoughts next in "random thoughts" >>

c plus plus   ...   random thoughts , programming
sun 2005-apr-17 15:54:39 pdt   ...   permalink

So one not-really-anticipated side-effect of being back in school now (as I have been the last six months) after seven years in industry is that I have to write C++ code again.

The last time I actually wrote any C++ was in my first job out of college, at Apple, where I worked very briefly on handwriting recognition for the Newton. Since then I've written mostly Java, a fair bit of Python, some Lisp and other languages, and a surprising amount of Bourne shell -- you'd be surprised just how large and complex a system can be built entirely in /bin/sh. Well, okay, actually, the surprising part is not how large and complex a system can be built entirely in /bin/sh, it's more how large and complex a system someone (mostly me) has actually gone ahead and built entirely in /bin/sh. But that's a blog entry for another day, perhaps.

Anyway, so now I'm having to use C++ again after all these years. I've noticed a few things about it, and they're not really the same things that a few months ago I would have cited as my reasons for preferring Java or Python over C++. I mean, sure, the memory management thing is kind of annoying, but the biggest pain, I've discovered, is keeping track of pointers, and references, and when you're implicitly calling constructors and whatnot...

So for example, the other day I needed to pass an array to a function and have that function move around the elements within the array. The elements themselves were pointers. So I've got this const Foo *myArray[], right? My first thought was to pass it by reference, but, well, a reference to an array of pointers seemed silly, so I thought I'd go with a pointer to an array of pointers, by having the function argument be const Foo ***myArrayPtr. But then when I called the function (passing it &myArray), I couldn't get that to compile. After talking about it with some friends who've written way more C++ than me in the last five years, I realized that I didn't need a pointer to an array of pointers, I could just pass the array of pointers itself (since that's really just a pointer), and be done with it. That fixed it, of course, but man, what a pain, having to think about these things.

Another thought I had was that it was nice to have operator overloading back. I totally understand why the Java folks made the decision to leave it out, and I would even go so far as to say that they were right to do so. But nevertheless, it sure is a nice feature to have! When I was first learning Java, I remember thinking that gaining inner classes somehow made up for losing operator overloading -- not that the one would take the place of the other for accomplishing any particular task, but just, as language features go, it felt like they'd taken one thing away and given me something else.

At the time, I think it seemed about an even trade, but now I don't really want to trade back -- I think maybe I'd rather have inner classes. I mean, on the one hand, the C++ stuff I've done lately hasn't really needed them, while it has made use of operator overloading. But on the other hand, it does feel like inner classes fundamentally provide something new, whereas operator overloading, nice as it is, is really just syntactic sugar.

But hey, sugar's better than no sugar.

mail me

reader comments on this entry:

sun 2005-apr-17 19:44:14 pdt
posted by

This reminded me of an entry in the C list of infrequently asked questions:


wed 2005-may-11 07:20:23 pdt
posted by josh frederick

you have to be one of the most pathetic losers that has their own web page. Just thought id let you know incase you haven't noticed.

wed 2005-may-11 11:59:37 pdt
posted by Joseph

Well, this sorta reminds of a pain in the ass problem im having right about now >< I have an array of pointers and i want them to be used by reference in a called function. That works, i pass them but for some strange reason they dont get changed :S when i print the array, theyre back to old values... :(

nice site tho ;)

wed 2005-may-11 12:04:18 pdt
posted by fling93

Well heck, I've spent most of my career coding in C for embedded systems. Pointers and globals all over the place and no overloading. So you get no sympathy from me! :)

(found your RSS feed, by the way, but you really oughtta put it on your sidebar)

wed 2005-may-11 12:06:26 pdt
posted by fling93

(Oh, nevermind! I'm the least observant person on the planet.)

post a comment on this entry

NeilFred Picciotto drawing of neilfred
  • derf content, blog-style
  • derf's comics
  • elsewhere on the web
  • 100% true stories
  • what i learned today
  • random thoughts
  • wristwatch requirements
  • What color hat am I wearing?
  • c plus plus
  • good writing
  • non-mountain unicycle
  • mountain unicycle
  • NetFlix
  • . . . more . . .
  • movie reviews
  • phone photos
  • blog-on-blog action
  • tags
  • RSS feed
  • XFN links
  • recent comments
  • 2008-sep-22
  • Britt Lyons on food handler
  • Conrad Pate on singing nuns
  • Suzy on people live in West Virginia?
  • Quinn Rutledge on chickens
  • Jacquline Gamble on garlic rabbit
  • 2008-sep-21
  • Lenora Gomez on garlic rabbit
  • 2008-sep-20
  • Jonas Bailey on food handler
  • Lenny Ayers on chickens
  • random phone photo random phone photo
  • non-bloggy content
  • the derf himself
  • the derf FAQ
  • other derfs
  • what's new?
  • the derfnet portal
  • derf's comics
    blogs and such
  • Q
  • entropy
  • girlhacker
  • ambiguous
  • oblomovka
  • sem101
  • badgerbag
  • zephoria
  • pith, jcn
  • jvg
  • unlikely words
  • mjr
  • jessajune
  • heaneyland
  • dommah
  • unwellness
  • livejournalers
  • ...  all derf.net blog content and underlying code owned by NeilFred Picciotto  ...
    mail me