I'm reading the book "C++ Performance and Optimization" on Safari and it's a pretty good book, talking about how to make code smaller and faster. These two things have always been important to me.
These days, however, nobody cares if your code is small. Downloads are fast enough that it doesn't matter, and nobody distributes software on floppies anymore. Hard disks are big, and stuff that ships with your application (help files, data files, etc) is usually larger than the size of the code anyway.
The reason software keeps growing in size isn't because programmers aren't writing good code. If I write an algorithm with an eye to code size, I might be able to get it to be half the size of the same algorithm written by someone who just isn't paying attention.
What really bloats an app is reusing code.
With shared libraries that's not really how it's supposed to work, but I think a lot of programmers don't trust shared libraries, because of the versioning issues involved. I read somewhere recently that there were 26 different shipping, production versions of the Common Controls DLL that's part of Windows. Yikes.
So when it comes time to distribute my app, if I had to choose between putting SomeFeature.DLL in a shared directory or statically linking with it, well, I'd statically link with it. My app's less likely to be broken by some other app installing an older or incompatible version - but by statically linking with it, my app's gotten bigger.
If I'm a 100k program, and I decide that I want to let the user, say, rotate an image, then I could write some code to rotate a bitmap. That might be 20k, and my app's now 120k.
Or, I might find (or buy) a bitmap utilities library that supports image rotation, and link it in - which could easily drag in hundreds of kilobytes of code. At least if I statically link with it the linker will try to throw away code that doesn't get called; if I ship it as a DLL then I'm shipping all the functionality of the library I've decided to use, which could be megabytes.
So through a bad choice of what components to link with (or perhaps when to use an external library vs when to roll your own feature) I've made my app many times the size it was previously. An extreme example but you get the picture.
I think a solution to this would be to use DLLs, but to use many smaller DLLs instead of fewer large DLLs - and to use DLL names that are unique, similar to what .NET does, to ensure that updates to the DLL don't break anything.
4:53:38 PM
|