Programmer's Toolbox
Reusing code and inverting matrices
Jack Crenshaw
7/30/2008 12:40 PM EDT
This month, as promised, I'm continuing to flesh out the C++ matrix class. But first, I want to talk about the value of reusable code and how it's supported by the Microsoft compiler called Visual C++ Express. Regular readers may remember how highly I praised this compiler, because of its ease of use and all its neat features.
Since then, I've had a few problems. This is by no means to suggest that I'm reverting back to my former, anti-Microsoft stance. Although I've been doing C++ for a long time, I'm a total newbie to this compiler and perfectly willing to accept that my problems are results of pilot error. However, having loaded up with books on the order of Microsoft Visual C++ for Dummies and having contacted folks in the developers' community and Internet forums, without much success, I'm still having the problems. In the future, I hope to establish a dialog with folks at Microsoft who can set me straight. In the meantime, I'd like to share my experiences with you. See what you think.
One of the big selling points of object-oriented design and development has always been that it encourages software reuse. If we design our C++ classes carefully, we should be able to generate software packages that can be used again and again, in new projects, without modifications. I stress that last phrase, because you're not really reusing software if you have to modify it for the next application. My incentive to develop classes for vector and matrix operations comes directly from this notion of reuse.
I can't resist reporting that I had my own version of software reuse, going on in the 1960s and 1970s. The "libraries" for my software were two sections of my desk drawer; one containing the source code (on IBM punched cards) for reusable functions, the other, object decks. Reusing those functions was as easy as lifting the object decks out of the drawer. The incentive to not recode was strong.
I should also note in passing that none of the software methodologies, from top-down design to the latest UML-based methods, are very effective in defining candidates for reuse. The reason is simple: you don't get those candidates from any single project-development effort. What you get from such an effort is the specifications for software needed for that particular project. As a ridiculous example, you might find several places in a given project that a vector addition is needed, but none with vector subtraction. A strict application of formal methods would never lead to a vector subtraction function.
By definition, reusable software is software that's used on multiple projects. You identify candidates for reuse by asking "will I ever need to use this function again?" In the end, the answer comes much more from the experience and foresight of the human designer than from any formal method.



JackCrens
8/6/2008 9:42 AM EDT
That's sort of what I thought. Microsoft C++ has been around a lot of years, and I gather that the folks in MSDN have adopted their own paradigm. Use of LIB or DLL files was one suggestion I got a lot. Some even talked about registry changes.
Personally, I would _NEVER_ contemplate a DLL until the project was nearing its ship date. If the compiler is incapable of linking files from different directories, it is, IMO, broken.
Guess I'd better get a good source control system. Thanks for your comments.
Sign in to Reply
Telechi
8/7/2008 3:15 PM EDT
I submit that allowing Microsoft to decide how your project should be set up by using their IDE is not a very productive way of working. You have to keep learning how to use their software (like you said in the article) as they must change it in order to get you to buy the new version. Additionaly as I am sure that you know, their help sucks as their help agenda centers around propaganda relating to the direction they wish to push you instead of helping you with your current problem.
Sign in to Reply
JackCrens
8/8/2008 6:25 PM EDT
You make an excellent point, which is that I should build an environment that works the way _I_ want it to work, as opposed to how some other dude thinks it should. Many of my colleagues eschew IDEs completely, opting for a command-line interface or an IDE based on a favorite editor such as Visual Slick-Edit. I've used such an environment in the past, and I must admit it worked very nicely.
How do I want it to work? I've thought about this, and the answer is ridiculously simple. Say I start a new project named Foobar. As I build it, I add source files from my library folder.
When I tell VC++ to compile, it compiles the files in the library folder, and adds their OBJ files to the project folder. Then it builds the EXE file from those.
That way, the library source files are safe. They can even be made read-only. The OBJ files are also safe, being visible only to that project.
Why can't VC++ work like _THAT_?
Jack
Sign in to Reply