This post originated from an RSS feed registered with Python Buzz
by Ben Last.
Original Post: I Counted Them All Back In...
Feed Title: The Law Of Unintended Consequences
Feed URL: http://benlast.livejournal.com/data/rss
Feed Description: The Law Of Unintended Consequences
A while ago I mused on programming languages (as programmers are wont to do), and concluded that the best thing about languages like Python (and, I now admit, Java) is the freedom from all the hideous memory management that Some Other Languages have to do.
Raymond Chen's blog has an interesting example of querying information from an Explorer window. Interesting not for the way in which it introspects down through the multiple-interface objectery[1] of Windows to get at the data, but because it exemplifies, for me, the reasons I dislike C++, and Windows C++, so much.
Take a look (should you feel like it) at his final example (at the end of that page). He excuses the ugliness by saying "because I put everything into one huge function instead of breaking them out into subfunctions", and indeed, this is partly an excuse. But look at the actual code; that ever-deepening cascase of nested ifs matched by the sudden flurry of CoTaskMemFree and Release calls. I have to wonder how much simpler this would be in a dynamic language, with grown-up memory management. But, as Raymond often points out, that's legacy for ya.
The syntax of C++ also grates, after a good couple of years now with the simpler, more streamlined Python; stuff like if (SUCCEEDED(pwba->QueryInterface(IID_IServiceProvider, (void**)&psp))) just... looks ugly (though I can still read it perfectly well), but I think it's the sheer effort required to do anything via COM and the Windows API that I remember - the slow trudge through looking up IIDs, playing with QueryInterface and trying to work out who owned what. It was a lot of work for what was often very little effect and I don't miss it at all.
But then I'm a curmudgeonly old Hector at the best of times...
[1] I don't know if this is a real word, but it should be, shouldn't it? Like an orangery is to oranges.