Developer Books

Anything not about Mac emulation.

Moderators: Cat_7, Ronald P. Regensburg

Post Reply
User avatar
sentient06
Apple Corer
Posts: 222
Joined: Tue Mar 29, 2011 8:57 pm
Location: London, UK

Developer Books

Post by sentient06 »

Do you guys know any books you'd recommend to look into C++ coding with the Macintosh Toolbox?

I've already gone through 'Learn C on the Macintosh - 2nd Edition', from 1995 by Dave Mark, which was a nice refresher on C, but doesn't include much of the Toolbox.

Then I've been through 'Mac Programming for Dummies - 3rd Edition' from 1999 by Dan Parks Sydow, which is the most recent I found but it's reeeeeeally for dummies. It's seriously slow-paced and repetitive, and it only scratches the surface on the Toolbox. If one ignores most of the extremely simplistic explanations, one can finish that book in a few days.

Now I'm reading 'PowerPC Programmers Toolkit', from 1996 by Tom Thompson, which is fairly good, but it often gets super technical and when it comes to coding, it sticks to pure C. So I can implement some C++ tricks at my own risk, but as I'm not used to C++98 and I'm a bit rusty, it takes me a while to do things right.

I know that Dave Mark made another book focusing on C++, and yet another one focusing on Toolbox, but that predates the first one I got about C (I think Mark's book on the Toolbox is from 1992), which is annoying because I'm trying to focus on PowerPC and his books seem chiefly concerned with 68000 (I didn't read it though, I just looked quickly).

Thompson's book is very good and I plan to go to the very end of it. It didn't age very well though, it's littered with boxes talking about Copland and how awesome it will be, which I suppose reflects the expectations of the time. While it's an interesting insight into the hopes and dreams about Copland, it's not seriously useful for development.

The codes by Thompson are also very clunky and massive. (And I know there are gaps in the code, as I had to debug a few missing lines since I don't have the CD.) I suppose that could be a side-effect of the mentality put into classic C programming. But it's a lot of typing! I spend days on each file and typing directly into Mac OS 9 is a chore. (I've been typing on modern mac now, and copying the files over into QEMU). The menu logic alone is a huge nest of switch blocks and every Toolbox call is a forest of OSErr checks. After a few tutorials from the book, I figured that C++ could be slightly more concise and easy to work with. I optimised a few chunks of code, and while it's fun to mess with it, it made me think that perhaps a book that deals with C++ directly could be more to the point. I can't find anything as modern as Sydow's book though, in the same vein as Thompson's. Any suggestions?
User avatar
adespoton
Forum All-Star
Posts: 4444
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: Developer Books

Post by adespoton »

I have to admit -- I totally skipped C++ for the Toolbox. When I was coding for Mac, it was all C or Pascal (or Python or Perl or LISP or Scheme or Squeak or RealBASIC or HyperTalk). When I dealt with C++ codebases, pretty much everything toolbox-related stayed ANSI C, and C++ was just used as a wrapper and for the internal program logic. I made heavy use of ResEdit and Resourcerer to build my resource structures which I then referenced from the source code, instead of building all the structures in-line.

Are you working within MPW or CodeWarrior?
User avatar
sentient06
Apple Corer
Posts: 222
Joined: Tue Mar 29, 2011 8:57 pm
Location: London, UK

Re: Developer Books

Post by sentient06 »

I'm using CodeWarrior. I'm a bit confused about the versioning system used by Metrowerks, but the about box says this is CodeWarrior 5. I got from a CodeWarrior Pro 8's CD. So it's 8. But it's 5. Go figure.

Thompson's code for the menu management goes like..

Code: Select all

theMenu = HiWord(mResult);
theItem = LoWord(mResult);
switch(theMenu) {
  case APPLE_MENU:
    // Do lots of stuff
    break;

  case FILE_MENU:
    switch(theItem) {
      case OPEN_FILE:
        // open file
        break;
      case FOO:
        // do foo
        break;
      case BAR:
        // do bar
        break;
      // etc
    }
    break;

  case EDIT_MENU:
    SystemEdit(theItem - 1);
    break;

  case BAZ:
    // another switch here
    // etc
    break;

  default:
    break;
}
It's okay.. it's a sane code, it's fast, but I thought using maps would be so much easier..

Code: Select all

typedef void (*FuncPtr)(void);
map<short, map<short, FuncPtr> > menuActions;

void InitMenuHandlers() {
  short i = 0;
  menuActions[FILE_MENU][++i] = OpenFileAction;
  menuActions[FILE_MENU][++i] = FooAction;
  
  i = 0;
  menuActions[EDIT_MENU][++i] = BarAction;
  menuActions[EDIT_MENU][++i] = BazAction;
}

// Then...

theMenu = HiWord(mResult);
theItem = LoWord(mResult);
menuActions[theMenu][theItem]();
But I haven't seen anything similar in any books yet. It compiles, it's C++98, so there's a bunch of niceties missing, but it's still damn powerful. I can use namespaces and vectors and stuff that on C are just very laborious. I wonder why it seems C++ was so uncommon.

So now I'm following this C & Toolbox book and referring to a C++98 reference doc page I've found. I think that the Toolbox has some strangely complicated routines that could benefit from being nested, as you said, in come C++ wrapper.

I spent a lot of time figuring out how to present a "select folder" window, and Inside Macintosh has one example in Pascal that actually draws a button in the open file dialogue and adds some filtering logic and things like that. I managed to write the same code in C, and it takes 200 lines to show the window. I thought about nesting that into a C++ class and invoking a single function, but then it occurred to me that maybe I'm reinventing the wheel and someone already did that. But this kind of code is so specific and old-school that I will probably spend less time implementing it than looking for an implementation of it. Still, if a book could approach C++ and Toolbox, maybe I could save time browsing Inside Macintosh for bits of information I will probably forget anyway.

Oh well, if I find something I'll drop here. Thanks!
joevt
Inquisitive Elf
Posts: 33
Joined: Mon Feb 01, 2010 3:08 am

Re: Developer Books

Post by joevt »

Code Warrior Pro 8 has Code Warrior IDE 5.0 (v5.1.1). Using the IDE version can distinguish between CodeWarrior 8 and CodeWarrior Pro 8.
Code Warrior IDE 1.7.4 (from Code Warrior 11) is an important version because it can convert projects from older versions into a project that can be converted by later versions.

If you want C++ wrappers, then maybe you're looking for Metrowerks PowerPlant or Apple's MacApp. MacApp is used by XPostFacto.
https://en.wikipedia.org/wiki/MacApp
User avatar
sentient06
Apple Corer
Posts: 222
Joined: Tue Mar 29, 2011 8:57 pm
Location: London, UK

Re: Developer Books

Post by sentient06 »

joevt wrote: Sun Oct 27, 2024 10:27 pm If you want C++ wrappers, then maybe you're looking for Metrowerks PowerPlant or Apple's MacApp. MacApp is used by XPostFacto.
https://en.wikipedia.org/wiki/MacApp
That's interesting, thanks! Do you know any books or similar documentation on these toolkits?
joevt
Inquisitive Elf
Posts: 33
Joined: Mon Feb 01, 2010 3:08 am

Re: Developer Books

Post by joevt »

sentient06 wrote: Tue Oct 29, 2024 1:58 pm That's interesting, thanks! Do you know any books or similar documentation on these toolkits?
I think they come with documentation and examples.

For MacApp, you can find html documentation in the Developer DVD April 2004 Inside Macintosh: Programmer's Guide to MacApp

Dev.DVD Apr 04/Technical Documentation/Technical_Publications/mac/MacAppProgGuide/MacAppProgGuide-2.html
There's a pdf "Programmer’s Guide to MacApp" with the same contents I think. Both are from 1996 so they should be available on Dev CDs (Tool Chest edition). You can find sites for the developer CDs and DVDs.

Dev.DVD Apr 04/Technical Documentation/Technical_Publications/macos8/mac8.html
includes documentation on all the Mac OS 8 / 9 technologies. Some of the links lead to the external Apple website instead of the files on the DVD.

PowerPlant has PDFs:
PowerPlant_Advanced_Topics.pdf
PowerPlant_Book.pdf
PowerPlant_Reference.pdf
PowerPlant_X_API_Reference.pdf
PowerPlant_X_Developers_Guide.pdf
PowerPlant_X_Migration_Guide.pdf
PowerPlant.pdf - Tutorial
User avatar
adespoton
Forum All-Star
Posts: 4444
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: Developer Books

Post by adespoton »

sentient06 wrote: Sun Oct 27, 2024 12:32 pm I can use namespaces and vectors and stuff that on C are just very laborious. I wonder why it seems C++ was so uncommon.
I can kinda-sorta answer that. It's due to the timing. C++ was just becoming popular in the late 1998/1999 timeframe. At that point, Apple was working hard to deprecate most of the toolbox and working hard on Carbon and Rhapsody, with the view to get OS X, based on Objective C, out the door in 2000. So the transition was already happening, meaning that most developers were maintaining existing code bases based on Pascal and C code, doing quick one-off projects using something like REALBasic, or focusing on the "new shiny" Objective C, and figuring out how to carbonize their apps so they'd run on OS 8.6, OS 8.7 and OS X.

Then OS 8.7 became OS 9 and was officially the end of the line for classic Mac OS, and most people stopped developing new projects for the platform. While Metrowerks supported C++, it was already looking towards Objective C, and saw Carbon as a legacy maintenance task -- so no reason to dump time and money into building out C++.
Post Reply