![](/file/12652/www.mactech.com.tar/www.mactech.com/sites/all/themes/custom_front/images/you_are_here_red.gif)
![](/file/12652/www.mactech.com.tar/www.mactech.com/sites/default/files/beta-site.gif)
|
Volume Number: 13 (1997)
Issue Number: 12
Column Tag: Getting Started
Getting Started With Macintosh Programming: Circa 1998
by Dave Mark , Copyright 1997, All Rights Reserved
A long, long time ago, I wrote an article for MacTech Magazine (called MacTutor, at the time) answering the question, "How do I get started with Macintosh Programming?" About once a year, I update the article and do my best to pass it around to the community. This is the 1998 version. Learning to program the Macintosh can be incredibly rewarding and enjoyable. I've been doing it for about 13 years, and I still get a charge out of seeing my thoughts and ideas come to life on my Mac's screen. If the idea of being able to build your own Mac applications sounds like fun to you, read on. Don't let the turmoil at Apple discourage you. I think Apple will be around for a good long time. I mean, think about it. Would you rather use a Mac or a Windows machine? To me there is no comparison. I want my Macintosh.
A quick caveat: Just so you know, I work for Metrowerks and write Mac programming books and both are recommended in the following pages. If you have any doubts about the contents below, find a friend with Mac programming experience (or find a newsgroup or on-line forum) and ask for yourself. I don't mind! ; ) Want to get in touch with me? Check out my web site http://www.spiderworks.com or send me email at dmark@metrowerks.com.
The Three Basic Steps
Start Off by Learning
So how do you learn to program the Macintosh? For starters, you'll need to decide on a programming language. In my opinion, there is no better way to start your programming education than with C. The C programming language is the most popular programming language in the world. Once you know C, you've got a language you can use on just about any computer in the world. More importantly, C++, Objective-C, and Java are all supersets of C. In other words, learning C will give you a leg up on learning any or all three of these important languages.
To be fair, there are other opinions on the best language to start with. For example, there are quite a few people who think that Pascal is the easiest language to assimilate. Though I agree that Pascal is a great programming language, and is less cryptic than C, there are several reasons I'd go with C as your first language. For starters, C is much more popular than Pascal. To convince yourself of this, go into a well-stocked computer bookstore and count the Pascal, C, C++, and Java books. Chances are, you'll find lots of C, C++, and Java books and perhaps one or two Pascal books (if any). The point here is, though some might say Pascal is the better language, C is clearly more popular and, therefore, better supported. Because it forms the basis for both C++ and Java syntax, learning C is a better investment in the long haul.
Still other people argue that novice programmers should start off by learning either C++ or Java as a first language. I don't like this approach. Don't be fooled. C++ and Java are both object-oriented languages and require that you master two sets of concepts: the procedural techniques and syntax of C, as well as the complexities of programming with objects. Learn to crawl, then learn to walk. That way you'll have mastered two skills and each phase of the learning process is simpler. By learning C first, you'll master the basics of procedural programming. You'll know the C language. You'll also have a much easier time learning Objective C, C++, or Java. In fact, you'll find it much easier to master all three languages. You'll be able to program in straight C if the situation calls for it.
Then Learn the Mac Toolbox
The C programming language, by itself, won't allow you to add Mac-specific features like windows, menus, icons, and dialog boxes to your programs. Your C programming environment (more on that in a bit) most likely comes with something called the C Standard Library which lets you do some very basic, text-oriented input and output. You can ask the user for input from the keyboard, process that input, and spit out results, all in a scrolling text window known as the console. Console-based programs have the smell of DOS and old technology. While they may get the job done, they are no substitute for the real thing -- a true Macintosh program.
To add all the cool Macintosh gadgets to your C programs, you'll need to learn how to use the Macintosh Toolbox, a set of functions built into each and every Macintosh computer. The universal availability of the Toolbox ensures that a window on your Macintosh looks and behaves exactly the same as on my Mac. There are Toolbox functions to create a new window, to implement a pull-down or popup menu, to draw in a window, drag the window around on the screen... in short, anything you want to implement in the way of Macintosh user interface, chances are there is already a Toolbox function to do exactly what you want.
Then Learn an Object Programming Language and Framework
Once you master the basics of programming using the Toolbox and C, you'll probably want to move up to the next level -- programming using objects. Just as the Mac Toolbox takes much of the work out of programming (by implementing the Macintosh look and feel so you don't have to), an object framework implements much of the structure of your program and wraps it in reusable chunks called objects. Objective-C, Java, and C++ are all object-oriented programming languages (programming languages that support objects). There are a variety of frameworks written in each of these languages. Once you decide on an object programming language, you'll also decide on a framework to work within. When you get on board with your programming language of choice, check out the work Metrowerks is doing with the PowerPlant framework. PowerPlant is currently the framework for Macintosh C++ programming. As Apple moves forward with Rhapsody (their new operating system), my guess is PowerPlant will also change to stay synchronized with Rhapsody and to accommodate Objective-C and Java, the official languages of Rhapsody.Resources to Help You Get Started
Books to Help You Learn C and the Toolbox
If you are brand new to programming, you may want to check out Learn C on the Macintosh by Dave Mark (that's me). Normally, I try to avoid recommending my own books to people, but if you are new to programming or to the C programming language, I do believe Learn C is the best place to start. Learn C assumes no previous programming experience and takes you through the process of programming using C. The book comes with everything you need to get started including a copy of CodeWarrior Lite, a non-saving version of the leading Macintosh programming environment.
Most of the books, tools and products mentioned in this article can be ordered from DevDepot. Their phone number is 800.622-3381. Outside the US and Canada, the number is (805) 494-9797. Their web site is http://www.devdepot.com and email orders are orders@devdepot.com.
Once you learn C (or if you are already a C programmer), you'll want a book that teaches you how to make your programs take advantage of the Macintosh Toolbox. Fortunately, there are a great number of Mac Toolbox books. If you like the style of Learn C on the Macintosh, check out the Macintosh C Programming Primer, 2nd Edition.
But the Primer is just the tip of the iceberg. Take the time to go to a technical bookstore well-stocked in Macintosh programming books. Some other books to look for are Programming Starter Kit for Macintosh by Jim Trudeau, Power Macintosh Programming Starter Kit by Tom Thompson, and Foundations of Mac Programming by Dan Sydow. You might also take a look at How to Write Macintosh Software, 3rd Edition by Scott Knaster. This last book is pretty old, but it still remains one of my favorites. Of course, there are new Mac Toolbox books being written all the time and you should also be on the lookout for any Rhapsody-specific books as Apple's new OS release looms closer to reality.
Get CodeWarrior
As you make your way through your first few programming titles, you'll definitely want to start practicing your new found programming skills. By far, the most recommended and most widely used programming environment on the Mac is CodeWarrior. CodeWarrior is made by a company in Austin, Texas named Metrowerks. Remember, I do work at Metrowerks, so ask your Mac programming buddies about CodeWarrior.
To be fair, there are other tools you can use to create Macintosh applications, including the Macintosh Programmer's Workshop (MPW) from Apple, and a variety of visual programming tools as well. Go to the DevDepot web site http://www.devdepot.com and spend some time looking around. Get to know the alternatives. Even if you do choose CodeWarrior, you'll benefit from knowing what else is out there.
CodeWarrior is based on a front-end/back-end architecture. The front end translates your source code (your C, C++, Java, Pascal, or Objective C statements) into an internal representation. The back end translates the internal representation into machine code targeted at a specific processor type. For example, for Macintosh development CodeWarrior features back-ends for both the 680x0 series of processors as well as for the PowerPC.
More importantly, CodeWarrior also has back-ends for the x86 and Pentium series of processors, as well as for a variety of other processors. That means you can write a Windows 95 or WinNT application completely on your Macintosh. Really!
If your ultimate goal is cross platform wizardry, Metrowerks also ships versions of CodeWarrior that run under Windows 95, Windows NT, as well as under BeOS. (BeOS is a cool new operating system from Be, Inc.) If games are your thing, Metrowerks also makes the official development environment for Sony PlayStation (cool!) and the PalmPilot PDA.
CodeWarrior comes in two basic Mac flavors: a professional package called CodeWarrior, Professional Edition and a series designed for beginners called CodeWarrior, Discover Programming Edition. CodeWarrior Pro is a professional development environment and comes with everything you could ask for in a programming tool. It ships with C, C++, Java, and Pascal front-ends, as well as with PowerPC, 680x0, and x86 backends. CodeWarrior Pro includes the latest beta Rhapsody development tools as well, including an Objective-C front end. You also get a series of electronic (non-printable) programming books, including Learn C on the Macintosh, Learn C++ on the Macintosh, Programming Starter Kit for Macintosh, and CodeWarrior Software Development Using PowerPlant, as well as a series of Apple Guide files to help you get started, and a boatload of sample code, extra tools and demos.
When you buy CodeWarrior Pro, Metrowerks throws in one year's worth of updates for free. Typically, Metrowerks releases new versions of CodeWarrior in May (in time for Apple's World Wide Developer's Conference, or WWDC) and October. Prior to the May 1997 release, CodeWarrior Pro was called CodeWarrior Gold and was released three times a year. The version number was reset to 1 with the May CWPro release. At the same time, Metrowerks moved to two releases a year. For example, in January '97, Metrowerks released CW11. CodeWarrior Pro 1 was released in May. CodeWarrior Pro 2 was released in October. You get the idea.
If you plan to do any commercial software development for the Mac, CodeWarrior Pro is a must. A one year subscription is US$499. Once you are registered, a 1 year upgrade is US$299.
If that price seems a bit steep, check out CodeWarrior, Discover Programming Edition. Discover Programming is a non-commercial, Mac-only version of CodeWarrior Pro. Though you get C, C++, Pascal, and Java front ends, you only get the 680x0 and Java byte code backends. The 680x0 back-end means that all the programs you build will be in 680x0 native format. They'll run just fine on a PowerMac, but in emulation mode (a bit slower than PowerPC native mode). If you are just learning how to program, you likely won't even notice the difference. As you'd expect from a learning edition, you also get all the electronic books and sample code.
CodeWarrior, Discover Programming Edition is only $79. If you upgrade to CodeWarrior Pro directly through Metrowerks, they'll take $79 off the upgrade price. If you are just getting started, Discover Programming for Macintosh is a great deal!
By the way, there are versions of CodeWarrior Discover Programming Edition for both Macintosh and Windows. They each list for $79.
Getting Started with CodeWarrior
Once you have CodeWarrior installed, you'll want to learn how to use it. Start off by running the Apple Guide tutorials. You'll find them under the Help menu. There are tutorials that show you how to create C and Pascal console projects, and C and Pascal Mac Toolbox projects. There are also a series of Java-specific tutorials. Take the time to go through all the tutorials that apply. An important part of learning how to program is mastering your development environment. The CodeWarrior Integrated Development Environment (IDE) is a sophisticated and powerful application that will take some time to learn. The tutorials will help you get started.
Once you've created some simple applications, dig into the documentation. You'll find answers to many of your early questions in the IDE User's Guide. Once you feel comfortable with the IDE, go back and take the CodeWarrior Debugger tutorial. You'll then want to spend some time with the Debugger manual.
More Books and Tools
Once you have your development environment installed and have the basics of Macintosh C programming under your belt, you'll want to add a few more items to your programming arsenal. For starters, you'll need a copy of Inside Macintosh, the bible of the Macintosh Toolbox. Inside Macintosh consists of a series of more than 25 books, each of which completely describes some portion of the Macintosh Toolbox. These books are indispensable. These books are also expensive, especially if you intend to buy the entire series.
Though it is certainly nice to have the printed copies of the Inside Macintosh books, consider buying the electronic version instead. The Inside Macintosh CD-ROM sells for US$89.95 and includes the complete text of most every Inside Macintosh volume in a cross referenced and hyper-linked form. Get this CD-ROM.
Of particular interest is the volume called Inside Macintosh: Macintosh Human Interface Guidelines. This book covers Apple's human interface standards in great detail. They will teach you how a Macintosh application is supposed to behave, from the proper location of OK and Cancel buttons in a dialog box to the proper way to position multiple windows on the user's display. Though the interface standards might seem excessive, it's that strict attention to detail that makes a Macintosh application so recognizable. Read this book.
Another important tool that you'll want at your disposal is a resource editor. Macintosh programs store program-related data such as icons, cursors, window descriptions, and text in a special portion of your application file called a resource fork. A resource editor is essential for you to be able to edit your application's resources. Apple created a widely distributed resource editor called ResEdit. Though ResEdit does a relatively adequate job of editing most resources, once you get into some serious Macintosh programming, you'll quickly discover ResEdit's limits.
A company called Mathemaesthetics created a program called Resorcerer that goes well beyond what ResEdit can do. Mathemaesthetics charges US$256 for Resorcerer, though students can get it for half price (you'll need a student ID or educational mailing address to qualify).
You can write to Mathemaesthetics at sales@mathemaesthetics.com. Their web site is www.mathemaesthetics.com (big surprise there) and their phone number is (303) 440-0707. You should definitely check out their web site, both for their explanation of what Resorcerer can do as well as for new versions, patches, and possible price changes.
Of course, the net is also a critical resource. In addition to the myriad of programming related sites, you might want to check out this tutorial for CodeWarrior users in both Pascal and C at http://www.AmbrosiaSW.com/alt.sources.mac/macintosh-c/.
You should also check out this group of Mac programmers that help with online self study, MOST at http://www.aimed.org/most/.
And Apple offers courses and certifications at Developer University at http://www.devworld.apple.com/dev/du.shtml.
The Metrowerks site, as you might expect is http://www.metrowerks.com.
Finally, check out WarriorWorld, a site for all CodeWarriors http://www.codewarrior.org/.
Your next step should be a visit to a hard-core technical bookstore. At the very least, pick up a copy of C, A Reference Manual by Harbison and Steele. This book, affectionately known as H&S, is a terrific C programming reference that will get a lot of use as you gain experience writing C code. There are also a number of books that describe data structures, searching and sorting algorithms, as well as techniques to help avoid common programming errors. Some of these books are language independent, while others are specific to C, Pascal, Objective-C, or Java. Find a writing style that you feel comfortable with. If you find any that you found particularly useful, please do drop me a line and let me know.
Here's a list of books the folks at Metrowerks recommended:
Language Reference
- Advanced C++ by Coplien.
- The Annotated C++ Reference Manual by Ellis and Stroustrup.
- STL Tutorial and Reference Guide by Musser and Saini, Addison Wesley.
- C, A Reference Manual by Harbison & Steele.
- C++ Primer Plus by Stephen Prata.
- C++ The Complete Reference by Herbert Schildt.
- The Evolution of C++ Programming by Stroustrup.
- The Standard C Library by P.J. Plauger.
- The Java Class Libraries: An Annotated Reference by Patrick Chan and Rosanna Lee.
- The Java Language Specification by James Gosling, Bill Joy, and Guy Steele.
- The Java Programming Language by Arnold and Gosling (the guy who invented JAVA).
- Java Programming for the Internet by Thomas, Patel, Hudson, and Ball.
Avoiding Language Pitfalls
- Effective C++ and More Effective C++ by Scott Meyers.
- Code Complete and Rapid Development by Steve McConnell.
- C Programming and Dynamic Memory Management by Daconta, QED publishing.
- C++ FAQs by Cline & Lomow.
- C Pointers and Dynamic Memory Management by Michael C. Daconta.
- C++ Pointers and Dynamic Memory Management by Michael C. Daconta.
Algorithms
- Algorithms in C by Sedgewick.
- Data Structures and C Programs by Van Wyk.
- The Knuth Computer Science series.
- Introduction to Algorithms by Thomas Cormen, Charles Lieserson, and Ronald Rivest, McGraw Hill/The MIT Press.
- Introducing Algorithms in Pascal by Thomas W. Parsons.
Software Design
- Code Complete by Steve McConnell.
- Debugging Macintosh Software by Othmer and Straus.
- Debugging the Development Process by Steve Maguire.
- Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides.
- Developing Object-Oriented Software for the Macintosh by Goldstein and Alger.
- Large-scale C++ Software Design by John Lakos.
- No Bugs by Thielen.
- Object-Oriented Analysis and Design With Application- by Booch.
- Object Oriented Programming by Peter Coad & Jill Nicola.
- Rapid Development by Steve McConnell.
- Software Implementation by Michael Marcotty.
- Software Tools by Kernighan and Plauger.
- Taligent's Guide to Designing Programs. Well-mannered Object-Oriented Design in C++. Taligent Press/Addison Wesley.
- Writing Solid Code by Steve Maguire.
![](/file/12652/www.mactech.com.tar/www.mactech.com/sites/all/themes/custom_front/img/search_text.gif)
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine