Completing the vector class

August 01, 2007

JackCrens-August 01, 2007

Jack adds more functions to the vector class and either admits high treason or finally sees the light, depending on your point of view.

Since we met last, I've added quite a number of member functions to the vector class--more than I can tell you about in this month's column. Instead, I'll just hit the high spots, talk a little philosophy, and post the full listing at

For those just joining us, we've been developing a C++ class suitable for doing math with vectors. The operative words are "vector" and "math." We're talking about vectors in the math/physics sense, not just abstract arrays of numbers.

To IDE or not to IDE?
First, I want to discuss a more philosophical manner. I may cause some controversy here, but I can't keep silent any longer.

There seem to be two kinds of programmers in the world: those who like to use an integrated development environment (IDE) and those who don't. IDE lovers like to think that their productivity is improved by using one. Many IDE shunners--talented people whose work I admire--claim that they have the edge on productivity. I'm sure they have their reasons, but there's also a certain macho mystique associated with doing things the old-fashioned way.

In the "good old days" when men didn't eat quiche, there were no IDEs. There was only one way to develop code: write the source code using some standalone editor, then submit it to a batch compiler system. In the very old, good old days, the "editor" was me, sitting in front of an IBM 026 card punch. The "librarian" was also me, selecting object-file card decks from my desk drawer and stacking them in order.

Even then, the macho mystique was firmly on scene. Some prided themselves on their ability to get things done without the aid of "crutches" like compilers. One fellow told me, in all seriousness, "Assembly language is for wimps. Real programmers code in absolute binary." That's a verbatim quote, except for the "wimp" term. He would have used the 1960 equivalent, which I've forgotten.

Being basically lazy, I'm very much an IDE lover. My first exposure came with the original Borland Turbo Pascal. From inside the screen editor, I could compile and run the program with a single keypress. A compile error would bop me back to the editor, with the cursor sitting there blinking at the point of the error. I embraced the IDE concept with vigor and have never looked back.

I know excellent software people who still shun the use of an IDE. This is especially true in the case of embedded systems programming, where IDEs are relatively new. But then, I also know Unix/Linux wizards who are still using the editor, vi, convinced that they're on the bleeding edge of technology.

If you prefer non-IDE, command-line tools, you're probably very familiar with the Unix-heritage makefile system, which lets you explain the relationships between all the files in a project. I've had to write makefiles. I didn't like it.

An IDE manages the project for you, building its own makefile behind the curtain. In the end, the question is, do you want to write your own makefile or let the IDE do it for you. For me at least, it's not a hard decision.

Most embedded systems components--hardware, chips, operating systems, and so forth--need some supporting software. Hardware and software vendors supply any support software that's needed. A few years ago, at an Embedded Systems Conference, I noted that virtually all the vendors provided C-based development systems--almost always using the GNU toolset. Only a couple of years later, it seemed that everyone had an IDE, usually based on Microsoft's Visual Studio. To me, the difference was both dramatic, and noteworthy. It's my strong belief that the IDE leads to much higher productivity, especially in the embedded systems arena. I'm glad to see the trend in that direction.

At my day job, I use an IDE--Microsoft's venerable Visual C++ 6.0. Until recently, I've been using Borland's C++ Builder to develop software for this column. Recently, I ran into problems with it--problems that made the job harder than it needed to be. Installing Microsoft 6.0 here at home didn't seem to help much. It was time for an upgrade.

As most of you know by now, both Borland and Microsoft currently offer free versions of their compilers. Borland began the trend by offering only their command-line compiler free; you still had to pay for the IDE. More recently, they've made available the IDEs as well. Microsoft followed suit.

Microsoft's offerings are all based on Visual Studio and are fully functional IDEs. I downloaded the products for C++, C#, and a few others.

What I'm going to tell you next may surprise you. Old-time readers know that I'm no fan of Microsoft. So when I tell you that this new, Visual Studio-based IDE is the best I've ever used, bar none, you can take that to the bank. It has every feature I've ever wanted in an IDE, plus many I hadn't thought of yet.

I just thought you should know.

Now I must make a correction and confession. In my last column, I showed you a number of constructors for class Vector and pointed out that you can have as many as you like, with any number of arguments, as long as the compiler can sort out which one you intended to invoke. That's true enough. Then I said the assignment statement is sort of parallel to the constructor. A constructor creates new objects of the class; an assignment statement copies data to already-existing objects. Also true. But then I took the parallel one step too far, showing you both constructors and assignment statements with multiple arguments.

That, of course, is rubbish. An assignment statement expects only a single argument on the right of the "=" sign, and will complain mightily, otherwise. You can write as many functions as you like with names like CopyTo or AssignTo, but operator = expects one and only one parameter. I'd have retracted that statement if I'd thought about it for more than a nanosecond. I guess I didn't. Sorry.

< Previous
Page 1 of 4
Next >

Loading comments...

Parts Search