TweetFollow Us on Twitter

Nov 98 Factory Floor

Volume Number: 14 (1998)
Issue Number: 11
Column Tag: From The Factory Floor

A PowerPlant Update, Part 2

by John Daub and Dave Mark, ©1998 by Metrowerks, Inc., all rights reserved.

This month's column is the second installment in our series on PowerPlant. Last month we spoke with the godfather of PowerPlant, Greg Dow. This month, we'll hear from John Daub, another key member of the PowerPlant team.

Dave: What are your thoughts on getting started with PowerPlant?

John: I think what Greg Dow said in last month's Factory Floor provided a good starting point, from a coding perspective. I've found a few concepts that are not exactly coding related, but have helped me (and others) not only get started in PowerPlant, but also follow through. These still help me every day.

1. Lay a good foundation - Many people starting out with PowerPlant start knowing little and desiring to accomplish a lot. The enthusiasm is commendable, but do not let this enthusiasm turn into impatience. I've seen too many beginners desire to write the next great Killer App over a weekend, expect PowerPlant to do it all for them, then get frustrated and give up because of impatience, unrealistic expectations of PowerPlant, and/or unrealistic goals. That's a shame.

Make a good assessment of where your skills currently are and where they need to be to accomplish the goals you set for yourself. Then fill in the gaps along that route and set out.

To work with PowerPlant, you need to know the C++ programming language, and knowing how to get around the Mac OS Toolbox is certainly beneficial.

If you do not know C++, you should pick up a good book on the language and learn it first. There are many at your local bookstore, and there are some on the CodeWarrior CD as well.

Although PowerPlant does hide many of the details of the OS from the user, sooner or later you will find yourself needing to deal directly with the OS. That's not as scary as it might sound, and the more familiar you are with the Mac OS Toolbox, the less scary it will certainly seem. You should at least be familiar with basic concepts like event loops and dispatching; basic managers like Windows, Dialogs, Menus, Controls; basic memory management; etc. There are many good books on Mac programming at your local bookstore (and on the CodeWarrior CD).

After you've laid yourself a good foundation, then start to work with PowerPlant.

I know... that's a lot of background work and could take you some weeks or even months before you touch PowerPlant at all... and you want to start writing apps now! I do understand this excitement. I believe you should still take the time to lay a good foundation for yourself, but tinkering around and getting your hands dirty can be a lot of fun as well. Just remember that you tend to go further building a house upon rock than upon sand.

2. Be honest - Not only with others, but mostly with yourself. Learning PowerPlant isn't easy, but it's not difficult either.

One of the most difficult parts of learning PowerPlant is knowing when you've truly mastered some concept or technique. When will you know if you've mastered it? You'll know (don't you hate answers like that? :)

And if you aren't certain, if you doubt your understanding of a concept, perhaps you do not fully understand it. It's best to be honst with yourself and take the time to go back and see. Maybe you didn't know it and now you know better. Maybe you did and through reduncancy you've fostered some learning.

Or maybe you thought you did but corrected yourself, or picked up on a finer point that you missed the first time around.

Never let your ego get in the way of learning.

3. Read, Ask, Do - Read everything that you can. Books, documentation, magazines, websites, FAQs, newsgroup archives, and most importantly here, source code. You learn a lot. Just read, and reread, and reread again.

Ask questions whenever you are not certain of something. If someone is going to look down on you for asking a question, they've got a problem they need to get over. And keep asking until you fully understand. The only dumb question is the one never asked.

Do. Write code, write apps. So what if there are a zillon text editors on the market. Write the zillion-and-one editor. The more you write code, the more you'll learn. Experience teaches us a great deal that we cannot learn any other way.

4. Spend time in the debugger - The debugger is a great place for the beginner to learn. If you start out at main and then Step Into every single line of code watching what goes on, examining variables, monitoring flow, you will learn a great deal about how PowerPlant works. It can also help you see how the pieces of PowerPlant all fit together to form an application. And as well, it can help you learn how to debug, which is a necessary part of development.

5. Be patient and don't give up - I don't believe that anything worth having in life comes easy. Same holds true for PowerPlant. Like I said before, learning PowerPlant isn't easy, but it isn't difficult either. If you hit a frustating problem that you just can't solve, keep at it. Maybe leave it for a while to clear your head, but don't totally quit. Ask someone else for a fresh perspective. Try to find a different angle from which to approach the problem. Some of the biggest joys come from solving the worst problems.

Hang in there. If you don't know what I mean yet, you definitely will sooner or later.

6. There is no such thing as a mistake, so long as you learn from it - So the app crashed. So it totally trashed your machine and now it won't boot. So what! Have you learned something from this (aside from "Yea, don't do that!")? In the beginning, you will probably crash more than run. Take the time to understand why your code failed and what you (or someone else perhaps) did wrong. Learn from it, grow from it.

And last, but most of all, have fun.

Dave: What are some of the PowerPlant classes you've work on?

John: I've written some examples and sundry code for PowerPlant, like LTextEditView, LCMAttachment (Contextual Menu support for PowerPlant), and some Grayscale implementations ("GA Imps", part of the Appearance Classes). I've also worked on larger projects like the Cursor Classes (provides cursor support, including animated cursors. I'm hoping to revamp this for Pro 5) and Debugging Classes.

Dave: Cool, debugging classes. What do they do?

John: The Debugging Classes are a set of tools that hope to make your life a bit easier and your code more robust and stable. They help you stress test, sanity check, view information, and a host of other features.

One of the most visible features of the Debugging Classes is the Debug Menu, provided by LDebugMenuAttachment (see Figure 1).

Figure 1. The Debug menu, provided by the PowerPlant class LDebugMenuAttachment.

To gain this menu and its functionality within your own project is very simple: just add the attachment to your application object like this:

     void
     CMyApp::Initialize()
     {
          LApplication::Initialize();

          #if PP_DEBUG
               mDebugMenuAttachment =
                    new LDebugMenuAttachment(...);
               AddAttachment(mDebugMenuAttachment);
          #endif
     }

That's all! Using the Debugging Classes and the Debug Menu isn't just as simple as that, but it is fairly close.

The menu is generated on the fly (so it should be relatively painless to add to existing as well as new projects), and it allows you to perform actions such as breaking into a debugger; performing compactions, purges, and/or scrambles to your heap; validate your PPob's; modify the behavior of gDebugThrow and gDebugSignal at runtime (typically you'd have to recompile to do this); and consume memory to simulate low-memory conditions.

One of the very useful parts of the menu are the displays of pane and commander hierarchies on the fly. I know being able to display the commander chain has helped many people solve their commander problems already. A big thanx to Greg Bolsinga (our Class Wrangler Wrangler) for the original code to LCommanderTree.

One additional behavior of the menu is how it allows you to work with Metrowerks utilities, such as ZoneRanger and DebugNew, and third-party utilities, such as QC, at runtime. Turn QC tests on and off, generate a DebugNew log, clear all DebugNew leaks, whatever you'd like to do. Normally to change these behaviors you would have to recompile; but now they have an interface and can be accessed at runtime. Much handier.

The other portion of the Debugging Classes provides macros and utilities for use within your code. These build upon the core debugging functionality in PowerPlant (Assert_, ThrowIfOSErr_, ThrowIfMemFail_, etc.) to help you sanity check and ensure your code will be solid.

And just like the core macros, when you turn debugging off in PowerPlant, the Debugging Classes macros are redefined to minimal implementations.

For example, to find a pane by ID, you typically do this:

   CSomePane *thePane = dynamic_cast<CSomePane*>
                        (theWindow->FindPaneByID(kPaneID));
   ThrowIfNil_(thePane);

That's a lot of code to have to type. Plus, although the dynamic_cast is technically correct, it's not *really* necessary here: after your initial debugging run to ensure you set your code and PPob correctly, you are pretty much guarenteed that looking for kPaneID will return the proper object (unless someone fouls up your PPob). Furthermore, the nil check isn't needed since you should have no problem obtaining a proper and valid pointer.

With all of this in mind, you can reduce the typing, the code bloat, and runtime overhead (of the RTTI and the nil check) by using DebugFindPaneByID_.

   CSomePane *thePane = DebugFindPaneByID_( theWindow, 
                                    kPaneID, CSomePane);

That's all there is to it.

In debug builds, the macro will expand to ensure theWindow is not nil, then perform the FindPaneByID and dynamic_cast just the same as the original code. It will check for nil and signal if there is failure. So you have all of the original functionality, and a lot less typing.

In release builds, the macro reduces to a simple call to FindPaneByID, static_cast'ing the return result. A lot less overhead (no RTTI, no nil checks) and a lot less code for releases, but still the sanity and robustness needed for development.

Of course, if you do need to determine the proper object type on the fly, i.e. you need the dynamic_cast because the pane type is unknown at compile time and/or could vary at runtime, then by all means do use the previous method to FindPaneByID() so you do not lose the dynamic_cast when the macro is turned off.

Dave: What's going on with Constructor?

John: As of this writing, Constructor is in maintenance mode and I am the maintainer. We are not working on any major improvements. The forthcoming RAD tools (and some future PowerPlant developments) will supersede Constructor in form and function.

I am not adverse to fixing bugs or adding features; in fact I have a list for each category and would like to work to make the lists shorter. However, RAD at Metrowerks is now the top priority, so major changes to Constructor probably will not be happening.

We will continue to ship a Constructor with CodeWarrior for a good long while, as there are many legacy projects that will continue to need and utilize Constructor. We will ship Constructor until we have a complete and viable replacement.

Dave: What other programming things do you do?

John: Aside from my work at Metrowerks, I try to stay involved in the Mac OS development community. I've contributed to the WASTE project, do a little informal (non-profit) consulting work here and there, and write some classes for PowerPlant that I distribute on my own.

Some people ask me why I write PowerPlant classes outside of my regular PowerPlant work, or why my outside classes are not rolled into PowerPlant officially. Most of the things I write in my own time are experiments, tinkering, or just something that doesn't fit into the scope of "PowerPlant proper". They're still useful (many people love my CURLPushButton class), but not something that really fits within the core PowerPlant scope.

Currently (at the time of this writing) I'm looking at WT++, a new all C++ text engine from Timothy Paustian (author of CWASTEEdit and WebWarrior). It's pretty neat. And I'm also getting more serious with Linux.

Dave: Any parting comments?

John: I always welcome input and feedback from our users. If you have any comments or criticisms about any of the topics discussed here or about PowerPlant in general, do feel free to drop me a line.

I'm hoping to be able to find some time in the near future to write some more in-depth articles for MacTech, about getting started, the debugging classes, or some other topics. If readers have any input as to what they might like to see, in terms of some future articles on PowerPlant, drop a line to editor@mactech.com and CC me. I cannot promise anything (any of you with children know how life can be sometimes :-) but I'll certainly see what I can do.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.