12.12.2012 Views

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

Teach Yourself Borland C++ in 14 Days - portal

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C++</strong> Class Frameworks and the Visual Component Model<br />

The primary trade-off is that W<strong>in</strong>dows programs written <strong>in</strong> <strong>C++</strong> tend to be larger than their<br />

straight C counterparts. For example, let’s say you had a simple W<strong>in</strong>dows program written<br />

<strong>in</strong> C that was 75KB <strong>in</strong> size. The equivalent program written with one of the framework<br />

libraries might end up be<strong>in</strong>g 200KB <strong>in</strong> size. That’s a significant difference, yet this example<br />

demonstrates the worst-case scenario. The difference <strong>in</strong> f<strong>in</strong>al program size between a C<br />

application and a <strong>C++</strong> application written with a framework is go<strong>in</strong>g to be most noticeable<br />

<strong>in</strong> very small programs. As your programs <strong>in</strong>crease <strong>in</strong> size and become more sophisticated,<br />

the difference <strong>in</strong> size is much less noticeable.<br />

One of the differences is simply the difference between C and <strong>C++</strong>. <strong>C++</strong> carries additional<br />

overhead for features such as exception handl<strong>in</strong>g, runtime type <strong>in</strong>formation (RTTI), and<br />

other <strong>C++</strong> goodies. In my op<strong>in</strong>ion, the difference <strong>in</strong> code size is an acceptable trade-off for<br />

the features that <strong>C++</strong> provides. Now, before you label me as a code-bloat proponent, let me<br />

say that I am as conscientious as the next guy when it comes to code bloat. I believe that we<br />

should all write the tightest code we can, given the tools we use. I am also a realist, and I<br />

understand that time-to-market is a driv<strong>in</strong>g force <strong>in</strong> the software <strong>in</strong>dustry today. I am will<strong>in</strong>g<br />

to trade some code size for the power that <strong>C++</strong> and an application framework give me.<br />

Frameworks <strong>Teach</strong> Object-Oriented Programm<strong>in</strong>g<br />

and Design<br />

NOTE<br />

If you end up gett<strong>in</strong>g serious about this crazy game we call W<strong>in</strong>dows programm<strong>in</strong>g, you will<br />

eventually end up peek<strong>in</strong>g <strong>in</strong>to the source code of your favorite framework. Sooner or later<br />

you’ll want to know how the big boys do th<strong>in</strong>gs. The OWL or VCL source code is a great<br />

place to go for that k<strong>in</strong>d of <strong>in</strong>formation.<br />

The MFC source code is probably not the best place to go to see good<br />

object-oriented design <strong>in</strong> action. MFC lacks the elegance, abstraction,<br />

and overall design that makes a top-notch framework. In addition, it<br />

tends to break OOP rules from time to time. MFC may well be the<br />

most popular framework, but that doesn’t mean it is the best framework<br />

from an OOP standpo<strong>in</strong>t.<br />

Some weekend when the leaves are all raked, the house trim has been pa<strong>in</strong>ted, the laundry<br />

is all done, the kids are shipped off for a weekend at grandma’s, and you th<strong>in</strong>k you have a<br />

pretty good handle on <strong>C++</strong>, you should spend some time brows<strong>in</strong>g your favorite framework’s<br />

source code. It can be <strong>in</strong>timidat<strong>in</strong>g at first, but after a while you start to see what the designers<br />

were up to. Don’t stra<strong>in</strong> yourself. Attempt to understand the th<strong>in</strong>gs that bump up aga<strong>in</strong>st<br />

135<br />

5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!