Metrowerks' CodeWarrior is a significant new tool for any professional Macintosh programmer's toolbox
Raymond Ga Cote
The official release of Metrowerks' CodeWarrior (as version CW3) provides more than just a top-notch multiplatform development system. It also injects some excitement and competition into the moribund field of Mac software development tools.
Before the introduction of CodeWarrior, mainstream software developers had two options: Apple's MPW command-line tools or Symantec's Think Project Manager, an IDE (integrated development environment). When Symantec released its own MPW-based command-line C compiler, Apple abandoned its C/C++ compilers and officially sanctioned the Symantec product, reducing the minimally competitive market to a race with only one runner. CodeWarrior changes all tha
t. Now there is head-to-head competition, akin to Microsoft versus Borland, for the best C, C++, and Pascal development tools on the Mac and Power Mac.
Reviewing a product as wide-sweeping and feature-rich as CodeWarrior in just a few pages is always frustrating. Even though I've been using developer releases of CodeWarrior for over a year, there is still a lot of functionality I've only begun to explore. This review gives a high-level overview of the capabilities of CodeWarrior CW3 with the 3.5 upgrade. I tested the Gold version, which compiles for both 680x0 and PowerPC hardware. A Bronze version compiles just for 680x0 Macs.
Comfortable Environment
Central to CodeWarrior is its project-based IDE. The IDE is indicative of what you'll find with all CodeWarrior tools: It is small and fast and does what you expect. It fits comfortably and performs acceptably on my 8-MB PowerBook 145--not a state-of-the-art machine by any stretch, but one I frequently use while developing code. Although I'v
e been able to compile demo applications in as little as 2 MB, my PowerBook does become a bit crowded when I try to run the CodeWarrior IDE and the source-level debugger simultaneously.
A Project Manager window provides the focal point through which you load and compile all files and libraries (see the screen). You can add files to the project singly or in arbitrarily large groups. All projects start out with a single code segment. Dragging a loaded file to the bottom of the project list creates a new segment, into which you can then load other files.
CodeWarrior provides the added flexibility of allowing each source file to contain multiple code segments. This is particularly useful when writing C++ and MacApp applications where, for efficiency, you may want to have constructor, destructor, and method code in a single physical file but be able to load the method code in a separate code segment.
Without this ability, you have to always load all the method code--which may be substantial--i
nto memory just to instantiate or release an object. With CodeWarrior, you can control the application segmentation on a function-by-function level. The disadvantage is that the linker must have all the object and symbol files loaded into memory while performing the link. Linking even small MacApp programs can require 12 MB of memory.
The Project Manager window also provides a pop-up menu for each file. The menu serves two functions. You can mark a file as immediately requiring recompilation, and you can select any one of the include files referenced in the file and bring it up for editing and review.
A user-configurable toolbar provides a one-to-one mapping to all available menu commands. You add commands to the toolbar by simply holding down the Command-Control keys while selecting the menu item to add to the bar. You can also arrange toolbar icons in logical order. Although I'm usually not fond of toolbars, CodeWarrior's icons are, with few exceptions, fairly self-explanatory, and the immedia
te feedback provided by a single-line prompt provides instant recognition.
680x0 or PowerPC
The Gold version of CodeWarrior provides two versions of the IDE--one for generating 680x0 code and one for generating PowerPC code. Metrowerks provides both development environments, as well as the compilers running within them, as fat binaries able to run in native mode on any Mac platform. Thus, you can develop PowerPC applications on a 680x0 Mac, and 680x0 Mac applications on a Power Mac.
A Preferences setting lets you adjust your structure alignments to meet 680x0 or PowerPC requirements. The settings are unrelated to the platform your code will actually run on; for example, you can declare 680x0 Mac structure alignment in a PowerPC application. Although you should be careful to write platform-independent code that doesn't depend on structure alignment, these settings are useful when porting existing applications that may make use of native 680x0 structure alignments.
The CodeWarrior en
vironment provides a full, well-documented set of Apple Events for scripting. Typically, you use this Apple Event interface to connect a third-party text editor to the development environment. Other uses abound, how-ever, such as writing a script to automatically import large numbers of new files into a project, or automatically compiling a series of independent projects and then linking them into a final application.
One feature missing from the IDE is the ability to use a single project to generate both 680x0 and PowerPC applications. Although any project can be opened by either IDE, there is no programmatic way to set which system libraries and precompiled headers are required for each platform. Although an AppleScript could be used to create a copy of the project and then load the appropriate libraries, it would be much more convenient to have a single project with multiple views--thus ensuring that the same base project was used to generate both 680x0 and PowerPC applications.
One essential
feature of the IDE is the ability to import object files generated by MPW C/C++ compilers. In particular, CodeWarrior can import object and library files that use far code and far data segmentation. Missing from other Mac IDEs, this ability is vital when using large third-party libraries built for the MPW environment.
A complete CodeWarrior Gold installation consumes more than 100 MB of disk space. You can pare this down to less than 40 MB, depending on your requirements. For example, the 100-MB installation includes the C, C++, and Pascal compilers; on-line documentation; extensive examples; and a fully configured MPW 3.3.1. Metrowerks also provides an MPW version of the PowerPC C++ compiler.
The Compilers
CodeWarrior Gold provides two compilers on two platforms: an ANSI-standard C/C++ compiler and an ISO-standard Pascal compiler. Versions of these compilers are available for generating both 680x0 and PowerPC applications. Each compiler runs natively on the 680x0 Mac and the Power Mac.
These are the only Mac PowerPC cross-compilers available for the Macintosh platform that I know of. The linker can also produce fat binaries that contain native 680x0 and PowerPC code.
As with many C++ compilers, CodeWarrior currently lacks templates and exception handling (although Metrowerks supplies a macro implementation of exception handling). Like other compiler manufacturers, Metrowerks is targeting these capabilities, particularly exception handling, for release in the near future.
In building 680x0 applications, you can choose from three memory models: Small, Large, and Smart. The Small model uses 16-bit memory-address offsets within a code segment. This limits the maximum segment size to 32 KB. The Large model provides 32-bit memory-address offsets in a code segment, allowing individual code segments to be larger than 32 KB at the cost of slightly reduced speed. The Smart model analyzes the code results and uses 16- or 32-bit offsets, whichever is more appropriate, to balance speed wit
h the flexibility of large address spaces. CodeWarrior can also generate applications with data segments greater than 32 KB.
Although the C/C++ compiler typically receives the most attention, CodeWarrior also contains an ISO-standard Pascal compiler. This compiler does not have the Object-Pascal extensions needed for generating MacApp applications, so it isn't a potential MacApp porting tool. Although you can freely intermix C and C++ source files in a project, you must contain Pascal source files in their own project file. You can build Pascal files into libraries and then import them into C/C++ projects. To do so, you must move back and forth between the C/C++ and Pascal IDEs during development, which is awkward.
Class Libraries and Interfaces
CodeWarrior gives you interfaces both plain and fancy. The SIOUX interface library provides a quick-and-dirty interface for porting command-line applications to the Mac. SIOUX routes ANSI-standard printf and getc commands to the user through a scr
ollable text window. The output in this window can be cut, copied, pasted, and printed. Although you won't want to ship products built around SIOUX, it's excellent for test routines or for making first-pass ports of existing command-line applications to ensure functionality.
At the other end of the spectrum is PowerPlant and Constructor. PowerPlant is an extensive class library with some features unique for the Mac. Constructor is a view editor that lets you build user-interface components based on the PowerPlant class library. To use PowerPlant, you first build a set of user-interface views using Constructor. Constructor is a user-interface builder; it is not yet able to generate code automatically, although the documentation refers to this ability in several places.
There are two fundamentally different ways to build class libraries. You can create a single base or root class (typically called class Object) from which all other classes are derived, or you can create a set of class structures,
each of which has its own root. One advantage to an object structure with multiple roots is that naming conflicts are much less likely when you interface to third-party class libraries.
Another advantage is the ability to design class hierarchies that are logically independent of each other. Metrowerks describes this type of class structure as mix-in and claims that the majority of its class hierarchies are independent of each other. As there is less interaction among classes, the resulting system is easier to understand. Applications are also much smaller, since using a method in one class doesn't automatically load five other classes.
Metrowerks provides an impressive level of Mac system support within the PowerPlant framework. To start, there is a class to support the Macintosh Threads Manager. This class allows you to start cooperative (and limited preemptive) multitasking threads within a single application. Semaphores and shared queues allow threads to coordinate and communicate.
Po
werPlant also supports Apple Events. Just building an application automatically provides the required Apple Events, like Open and Print. Hooks in the class library let you attach your interfaces in a reasonable and consistent way. The 3.5 upgrade includes classes (still in development) for supporting the Drag and Drop manager.
One of the continual problems facing developers using object-oriented languages such as C++ is how to quickly and efficiently track and store objects once they have been created. PowerPlant solves this problem by including a product called NeoPersist by NeoLogic. NeoPersist is not an object-oriented database. Rather, it is a library that provides object persistence. It allows you to store the state of a limited number of objects and then restore it at a later time--typically when an application is restarted. NeoPersist is a subset of a more full-function product called NeoAccess, which is an object-oriented database.
Another NeoPersist feature is the ability to maintain o
bjects once they are created in memory. Since objects are dynamic, they can be destroyed when you least expect it. This is a particular problem in a multithreaded environment, where one thread can be creating objects and another thread using and destroying them. NeoPersist lets you verify that an object to which you are about to refer is valid. It can also provide automatic garbage collection by tracking all the references to a specific object and releasing that object once all the references have released it.
Documentation
All CodeWarrior documentation, ranging from an introductory Principles of Programming to technical reference guides, comes electronically. The information is extensive, but not excessive. Except for the introductory Principles book, most of the documentation is terse and technical but well written. It was easy to find such in-depth information as register usage within the 680x0 and PowerPC compilers, calling conventions, and a list of pragmas. Although terse, the documentatio
n still finds space to provide excellent code samples for each of the ANSI library functions. In addition to documentation for CodeWarrior subsystems, Metrowerks also provides documentation for version 3.1.1 of MPW and the latest Threads Manager.
CodeWarrior ships with Apple Extensions for 680x0 and PowerPC platforms. Among them are AOCE (Apple Open Collaborative Environment), QuickTime, Speech, Drag and Drop, and the Threads Manager, which allows cooperative multitasking within a single application.
Coming into Its Own
CodeWarrior is a powerful, exciting, and quality development environment for the 680x0 Mac and PowerPC. It has been well received by the developer community, and many software development houses use it.
Metrowerks has improved CodeWarrior dramatically in the 3.0 release and 3.5 upgrade. Internet discussions indicate that, sparked by the rush to move projects to the PowerPC, most developers have been using Metrowerks with third-party frameworks and libraries. Now tha
t the PowerBuilder class library has matured, it should get as much exercise as the base compilers.
The Facts
CodeWarrior CW4 Gold $399
Bronze version for 680x0 code only $99
Prices include three free upgrades.
Metrowerks, Inc.
(U.S.:)
8920 Business Park Dr., Suite 315
Austin, TX 78759
(Canada and International:)
1500 du College, Suite 300
St-Laurent, Quebec, Canada H4L 5G6
(800) 377-5416
(512) 346-1935
fax: (512) 346-3329
Illustration: CodeWarrior's IDE (integrated development environment) showing the Program Manager window (upper right), an edit window (upper left), and some disassembled PowerPC code (bottom).
Raymond GA Cote is a BYTE consulting editor and vice president of product development for Appropriate Solutions, Inc. (Peterborough, NH). You can reach him on the Internet at rgacote@ world.std.com or on BIX as ``rgacote.''