More on link-time backwards compatibility
I want to address the problem with not understanding linker behavior as I mentioned a couple entries ago.
If one doesn’t understand linker behavior and link-time compatibility issues, seemingly harmless edits can lead to incompatibilities with existing libraries and dll’s. This is a particular concern with externally accessible public headers or functions existing in shared libraries, etc.
For example, take the following function:
int fooFunc(char* fooStr, int barNum)
Let’s say another parameter is needed in order to perform some new functionality, so you change the function definition to this:
int fooFunc(char* fooStr, int barNum, int newNum=0)
Cleverly, you add the new parameter with a default value so that calls to the previous format of the function will work! Excellent! Let’s commit this sucker and hit up YouTube!
Not so fast…
Sure, this code will compile just fine because it is compile time compatible with existing code, but if this function is part of a shared library, it will break compatibility with code deployed from that library. This is because the C++ mangled name for this function will change to match the new function profile.
Aside from having anyone using this shared library recompiling & linking against this change, there is a simple way to include this kind of change while maintaining backwards, link-time compatibility.
All you do is create a new function and implement the old function in terms of the new one.
Here’s what I mean:
Definitions:
int fooFunc(char* fooStr, int barNum);
int fooFunc(char* fooStr, int barNum, int newNum);
Note that there is no default value on the new parameter anymore. That is because you have to specify every value to use it anyway. Observe:
Implementations:
int fooFunc(char* fooStr, int barNum, int newNum)
{
...
}
int fooFunc(char* fooStr, int barNum)
{
fooFunc(fooStr, barNum, 0);
}
Now, we have both the original definition which will avoid link-time errors with existing shared libraries while also including the change for anyone requiring it.
The Study of Sorting
I was directed to this page the other day (www.sorting-algorithms.com) and I’d recommend it to anyone who is interested in the design, various implementations and benefits/detrements of several major sorting algorithms.
There are excellent visual representations of the algorithms actively sorting data from various states (i.e. random data, reversed, etc.). Also, for each algorithm, you can view it’s pseudocode and efficiency properties - if that’s even a real term =).
If you have a couple minutes, check it out and learn about how we sort our data!
Back to the “Basics”
I find that there are many programmers (myself included) who use certain tools daily without really knowing how they work. In this specific case, I’m referring to linkers. As someone use uses C/C++ and several different compilers & linkers almost every day, I was recently struck with an error that was related to the way linkers function. Initially, I had somewhat of a hard time fixing the problem because I was never taught in my college classes about the way a linker performed its functions. I mean, we were told about the linker and understood its part in the overall build process, but we were never taught how they play that part.
I don’t blame my school necessarily. From talking with several coworkers who have been in the industry for several years now, I’ve come to learn that this is a trend in computer science education recently. It’s unfortunate, too… these basic priciples help provide a much deeper understanding and comprehension of lower-level computer functionality which, in my opinion, make a better developer.
In an effort to understand linkers better, I did some Googling (sp?) and found a string of several excellent blog entries by Ian Lance Taylor - a developer who wrote at least three linkers.
The entries start here. And continue through his entry archives to mid September 2007. I highly reccommend giving at least the first few entries a quick read-through if you are like me, and want a better understanding of the development tools we use every day.
Google Chrome
I’ve been using Google’s new browser, Chrome, for about a month now and I’m really enjoying it. From the way it handles tabs to the streamlined interface, it’s really been a joy to use.
Now, that’s not to say it is without its little quirks. One thing that drives me nuts is that Yahoo! mail always seems to kill Chrome’s web access on my system. Meaning, once I go to my Yahoo! mail account and attempt to browse away, my connection is essentially dead - but only in Chrome. All my other browsers work fine. I don’t know what would cause this, but hey, it is a beta. I know what you’re thinking: “What?! Google has a product in beta?! It can’t be!”… ok, I’m joking, but that is a valid reason for buggy software.
Anyway, I recently read a good article regarding Chrome and, more importantly, the use of a browser as hosts for applications. You can read it here.
Another useful Windows Trick
Have you ever had an application that somehow corrupted during install, update or removal? Would you get that stupid “Windows Installer” dialog box popping up every time you booted up your machine or attempted to complete a certain task? What makes it worse is that it fails each time and there’s seemingly no way to stop it… until now (Well, more like, until I Googled it a bit ^_^ )
Anyway, the fine folks over at Microsoft made a utility specifically to remedy this problem. It’s called the “Windows Install Clean Up” utility. It will detect which applications were installed (or otherwise modified) with Windows Installer. Using the tool, you can choose the one that’s giving you a headache, click the magic “Remove” button, and all your pesky installer problems will disappear! Hooray!
Note though, that this does not remove the application or anything… the best thing to do after using the clean up utility is to reinstall the application in the same location you had before. This will create new copies of previous files and prevents duplicates.
You can read more about the utility and download it from Microsoft here.
RSS