TweetFollow Us on Twitter

Pascal Man Submerges Self in MacApp 3

Pascal Man Submerges Self in MacApp 3

Jesse Feiler

Jesse Feiler knows that Elvis lives-in Michigan-and that he's busy writing MacApp software. Perhaps any Pascal programmer can reach this level of mental acuity just by writing a small application in MacApp 3. See for yourself-follow Feiler, prior Pascal programmer, as he is baptized by total immersion into a new life of C++.

This article relates the travails of a Pascal programmer who learned C++-the why, the how, and the wherefore. In spite of all the words that have been written and shouted in the language wars, perhaps this will add something to the conversation and help those who follow a similar path to MacApp 3.

Into the comfort zone

It took two weeks for me to feel comfortable with the C++ language. That meant being able to write code that compiled the first time (or the second time), and did what I expected it to do. That also meant knowing enough about the language's capabilities to know what constructs were appropriate in various places-even though I had to look up the syntax for those constructs in the manuals (as I still do in Pascal).

While I was learning C++, a colleague working on the same project was learning both MacApp and C++ (he knew Pascal). We both felt MacApp was much more important and difficult to learn. In terms of designing an application, knowing the MacApp classes and methods provides far more advantage than knowing C++ or Pascal.

Although I will return to these points below, it is important to note two things. First, I didn't need to learn C++ to program with MacApp 3. Second, I was able to read and understand MacApp 3 code from the beginning-but only with the assistance of MacsBug and my prior knowledge of MacApp. If you've ever cuddled up in bed with the MacApp source code on a cold winter night (yecch!), I'm sure you'll agree that you could probably understand DoMenuCommand even if it were written in an Urdu derivative of BASIC.

An assuaged concern

Along the way I learned that C++ is a more disciplined language than C, and many of my complaints about C are answered in C++. One indication is this section from the MPW C++ Appendix E: MPW C++ Style Guide:
    "It's possible to partially circumvent the strong type checking C++ imposes on function arguments. You should avoid doing this if at all possible. C++, like ANSI C, allows you to cling to C's past by declaring functions that take unspecified numbers and types of arguments, the classic being…"

Obviously, the sort of undisciplined code I associated with C is discouraged in C++.

Pride and prejudice

I've been programming in Pascal and in its direct antecedent, ALGOL, for over 20 years. I know the language very well. I've programmed, taught it, and designed systems based around the language and stack based machines.

As a manager, I've also formed a few opinions about languages. I don't present these as facts, merely as personal prejudices. Here are some of them:

  • People who are taught programming using Pascal tend to make better programmers than people who are taught with other languages. Not surprising, since Pascal was designed as a teaching language. Pascal-taught programmers can in general be relied upon to be better programmers no matter what their ultimate language is-even if it is COBOL.
  • C programmers can be sloppy and careless. This prejudice arose from noticing that C programmers learning Pascal seemed to rebel at Pascal's rigid type declarations and lack of automatic coercion.
  • Good programmers can write good programs in any language.
  • Bad programmers can write worse programs in BASIC and C than in other languages.
  • C seemed to have been designed for people who can't type, since strange symbols seem to substitute for words which I relate to better (like "begin" and "end").
  • As sort of a corollary, C is hard to read aloud.

As you may realize from this list, in my own work, I stuck to Pascal. When I subscribed to ETO, the one piece of the puzzle I had to buy was C++, so I did. I never installed it, and didn't even look at the documentation. And when it was announced that MacApp 3 would be written in C++, I didn't feel that the world was coming to an end, since everyone stressed that we'd still be able to use Pascal for our applications.

Then the language war broke out. As noted in the sidebar accompanying this article, our language war was a bush-league event. Still, as my kilobyte charges on AppleLink kept increasing, I began to get more curious.

On the sidelines

Despite the prejudices outlined above, I didn't feel qualified to participate in the language wars (and even had trouble understanding some of the terms), since I didn't know C++. I looked at the documentation I had on the shelf, and decided that the several hundred pages involved were too much of an investment to make at that time. I bought the two Addison Wesley books-Elements of C++ Macintosh Programming and C++ Programming with MacApp-and browsed through them. Eric Berdahl's articles in FrameWorks were also very interesting, but I didn't feel that I knew much yet.

Then a new project came up, and I decided to implement it not only with MacApp 3 but to use C++ as well. I used C++ on this project in order to find out enough about C++ to take a side in the language wars. You don't have to use C++ in order to use MacApp 3. I only learned C++ to find out what the fuss was about.

LEARNING C++

I used the total immersion principle, now commonly used for teaching natural languages, to learn C++. I didn't worry about the theory or the background. I put myself in a position where I had to use the language and-most important-where it was not unreasonable for me to be able to use the language.

While this technique (if you want to dignify it with that term) was an ad hoc, idiosyncratic approach, some of the things I did may be useful to others. The steps I took had the virtues of getting me up to speed in two weeks and getting an application that uses MacApp 3 and C++ into a basic shape in four weeks.

A small, new project

Having the right project to try this with was the most crucial requirement. We were lucky; a new project came along that was small, with a flexible deadline, so a bit of experimentation seemed reasonable. Still, I didn't know where to start. I designed my basic MacApp objects and their methods, then sat at the computer and wondered what to do next.

Implement the basic shell with familiar tools

While I was cogitating, I realized an important design meeting was coming up and I needed the shell of the application so we could talk about menu items and get the artists started on the graphics (of which there were to be many). In half a day, I put up the shell using Pascal and MacApp 2. At least I knew how to do that, and it gave us enough to discuss and get the artists started.

Automatically convert to "C++"

Using the MPW PascalToCPlus tool, I converted the Pascal files to whatever it was that came out the back end of the tool. I looked at it, but wasn't sure I could recognize it as any computer language at all. I also installed MacApp 3 and compiled the libraries and the Nothing sample. (For newcomers to MacApp, the compilation of Nothing is part of the normal routine. Compiling Nothing after installing MacApp confirms that your libraries are all in the right places and that MacApp itself is undamaged.) Then I turned to the "code" that was output by the PascalToCPlus tool.

The advantage of this approach was that I had the structure of my still tiny application visible to me, and I had at least pseudo-C++ code generated by the PascalToCPlus tool.

The PascalToCPlus tool is a good start, but the new P2CPlus tool distributed with MacApp 3.0b1 (on ETO 5) is far superior. Also of help is the "cheat sheet" located in the tools folder of MacApp 3.0b1. It contains samples of failure handling code, switch statements, and comparisons of Pascal and C++ common words and phrases.

Compile and laugh-or cry

I tried compiling. Boy, did I get errors! While I found my reference books to be of some help, the most powerful tool at this point was MacBrowse. If I had an error in DoSetupMenus, I looked at TApplication->DoSetupMenus. I tried to find similar code to what I needed, and just copied it in. I didn't try to figure out what every "->", "::", and "&" meant.

If I couldn't find clues from MacApp itself, the next easiest way to get rid of errors was to simply comment out the offending lines. Since the application at this point did little except put up its menu bar, removing code didn't decrease its functionality very much.

I found two MacApp 3 documents to be critical: "Release Notes" and "Conversion Notes." They are included in the MacApp 3 documentation on ETO, and have been updated with new releases of MacApp.

As I started to compile, I started learning very fast. Here is the fruit of my labors-may they help others to make fruit salad, to go with Eric Berdahl's soup.

The pascal programmer's guide to C++ compile errors

The C++ compiler (technically, the CFront tool), is a two-pass compiler. Those of us who are used to MPW's single-pass Pascal compiler need to get used to a two-pass compiler.

With a two-pass compiler, it's important to remember that errors are not necessarily emitted in the order they occur in the source file. Since compilers frequently generate errors on lines other than those where the actual errors occur (such as when quotes are mismatched), this can make debugging harder. Also, some syntax that is legal in Pascal is lethal in C++.

Herewith, a few of our more common errors. They are described along with the compile errors they generate and their most common cause-which is not necessarily related to what the compiler thinks is the problem!

These errors are the most common problems we've experienced that are not immediately caught and presented in an intuitive way by the C++ compiler. They're not to be interpreted as complaints about the C++ compiler, or about the Pascal compiler, or about the languages themselves. They are just the traps we hit most often. Some of them may hit any novice C++ programmer; others (like the absence of the word "case", below) are more likely to hit Pascal programmers because the two languages share similar syntax.

Switch and case statements

It's not too hard to adjust to C++'s case syntax:
switch (selection)
    {   
    case x:
            …
            break;
    case y:
            …
            break;
    default:
            …
            break;
    };

If you revert to Pascal case syntax, you'll get compile errors and know to fix them. But two important things may confuse the compiler. If the word "case" is missing, then "x" and "y" above are interpreted as labels. An error is generated-usually at the beginning of the function, that says:

# warning: label cAddSequenceComponent not used

Since we rarely use labels and often use case and switch statements, we've found this message almost always means a missing "case" in a switch statement.

A more dangerous trap is that "break" is required to get out of the switch statement. Without it, the subsequent lines of code are executed. While this allows some neat programming, it's not something we're used to, and it doesn't generate a warning or error message.

Headers are sensitive

It's important to remember that CFront is a much younger product than the Pascal compiler. Not only is the Pascal compiler more stable; many of us know it very well. (This doesn't mean one is better than the other. If I had found CFront so unstable as to be unusable, we would have completed the project in Pascal, and that would have been the end of that.)

All compilers are prone to conniption fits in their headers or interfaces. (Try leaving "USES" out of a Pascal interface file!) CFront is particularly unhappy with misspellings. In order to declare a constant, you can type:

const short i = 2;

Try typing:

cosnt short i = 2; //s-n reversed

…and you'll get:

line 35 # error: syntax error
line 36 # error: syntax error
line 36 # error: argument type expected for AddDependent()
line 37 # error: syntax error
line 37 # error: syntax error
line 37 # error: syntax error
line 37 # error: argument type expected for Insert()

Needless to say, line 35 is several lines beyond the const declaration. When the C++ compiler gives up the ghost and gives you the plain unvarnished "syntax error," we've gotten used to poring over code before the line in question, hoping to find a typo.

"If" statements may change a variable's value!

This is a double-whammy. First of all, the expression of an if statement must be enclosed in parenthesis. This isn't really a problem for most programmers. More tricky is the fact that in both Pascal and C++, the equality operator and replacement operator are different symbols- and they don't match up!

OPERATOR C++ PASCAL

replacement    =   :=
equality       ==  =

Thus, the phrase:

a=b

is a boolean expression in Pascal and a replacement operation in C++. The fun arrives when you code the following in C++:

if (a=b)

To a Pascal programmer, the code looks perfectly correct, and hours (trust me!) can be spent tracking down why the program executes strangely. As a result, Pascal programmers have to spend extra attention to if statements until they get them under their skin.

Missing "()" may generate an error

Another common Pascal programmer's error is forgetting that C++ functions always take some parameters (unless void is specifically meant). Since we're not used to this, we're quite capable of writing something like:
aSummaryView = aComponent->CreateSummaryView;

To a Pascal programmer, this looks pretty decent. Unfortunately, you will not call the CreateSummaryView(void) function and, in this case, you'll get the error:

 line 75 # error: bad assignment type:
                 TView * = pascal TView *TComponent:: ()

…or missing "()" may generate a warning

More insidious is the case where a function is called and doesn't return a result which the compiler could check:
aWindow->Open

instead of:

aWindow->Open();

will produce:

line 86 # warning: result of -> expression not used

This is a warning, not a compile error, so you'll be able to link, and run, and tear your hair out as a result of making the error and ignoring the warning. By now we know: this message means missing "()".

Missing "*" will generate an error

Types must be declared as pointers-that is, with a "*" following their name. Declaring:
TView aView

instead of:

TView* aView

gives these errors:

line 61 # error: can't declare a handle/pascal object: aSummaryView
line 75 # error: bad argument list for TView::TView() 
                     (no match against any TView::TView())
line 81 # error: non pointer -> Locate

Again, this is a fairly common mistake for Pascal programmers, because the "*" isn't something we usually worry about. So, translate "can't declare a handle/pascal object" to "missing *" and don't worry about what the message means. [1]

Missing ";" will generate an error

Both the Pascal and C++ compilers have quirks with respect to their header or interface files and implementation or definition files. In Pascal, the word "override" is optional in the implementation file, but the semicolon following the word "override" is optional in the interface file. This is of little import to most programmers, since we tend to use cut and paste to duplicate the interface and implementation code for a procedure heading.

In C++, however, cut and paste can't be used, since the semicolon at the end of the function definition (i.e., interface) is required, and a semicolon at the end of the function declaration (i.e., implementation) is forbidden.

As with most header or interface errors in all compilers, errors in this area can cause nasty results. Omitting the semicolon after the definition in the header file will generate a small novel of the following sort:

line 70 # error: syntax error: unexpected pascal
                                        (did you forget a `;'?)
line 70 # error: function declared as both pascal and non-pascal
line 41 # error: function declared as both pascal and non-pascal

In our experience, the first (and most welcome) message, suggesting the missing semicolon, is not reliably produced. The giveaway to the missing semicolon is more often the error "function declared as both pascal and non-pascal." Note the non-sequential error messages, with line 41's message following the messages for line 70. This is typical of two-pass compilers. Also of interest is the fact that this group of error messages was generated by one missing semicolon-and that was on line 70. Line 41 is the beginning of the class definition.

Extra ";" will generate an error

The companion error, that of including a semicolon after the first line of the function definition, generates a similar bevy of error messages:
line 229 # error: qualified name THEComponent::
GetControlParms() in function declaration
line 230 # error: syntax error
line 237 # error: syntax error
line 237 # error: function declared as both pascal and non-pascal
line 237 # error: two different return value types for TickCount():
unsigned long and int 
line 239 # error: syntax error
line 239 # error: syntax error
line 239 # error: syntax error
line 240 # error: syntax error
line 241 # error: syntax error
line 241 # error: anachronism `.' used for qualification; 
please use `::'
line 241 # error: bad qualifier fi for Try()
line 310 # error: syntax error
line 311 # error: syntax error

As in all cases where a compiler has gone off the deep end, errors multiply, generating more and more esoteric (and incorrect) messages. In our experience, the words "qualified name <> in function declaration" are the tip-off to the extra semicolon.

Hide and seek

C++ lets you overload its functions, allowing alternate arguments to be used to the same function. Most often, Pascal programmers overload functions by accident. The compiler is nice enough to warn you when this happens:
warning: TCommComponent::HandleMouseUp() hides virtual 
TView::HandleMouseUp()

Unless you really meant to overload the function, check the definition of your function and its ancestor's for differences in spelling, type, and number of arguments. Of course, if you meant to overload the function, ignore the warning.

Heed my warning!

One final note: read both the warnings and the error messages! While any compiler will sometimes throw up its hands and simply tell you "syntax error" and a line number, more often it will give you a specific message and a line number. Too many programmers go to the line given, but ignore the message.

Warnings are easy to ignore, since they don't stop the compilation process. But compilers rarely emit warnings that should go unheeded. As noted above, some of the errors Pascal programmers are likely to make in C++ will only generate warnings. So it's a good idea, one way or another, to eliminate warnings from your compilation.

YOU'VE GOT TO HAVE IT

MacBrowse (formerly Mouser) in an essential tool for learning C++. It is a fast way to analyze the body of C++ source code that every MacApp programmer has access to-the MacApp source code itself.

SourceBug provides line-by-line tracing of program execution. This is crucial for debugging- particularly in cases where control of execution goes in places where it's not expected to.

MAMake deserves to be mentioned because the dependencies in your MAMake file have to be absolutely correct (as indeed they should be with Pascal). Unfortunately, since C++ assumes that you may want to overload functions and change their parameters, some of the typos that the Pascal compiler would catch are treated by C++ as conscious, deliberate choices. So, in a back-handed way, the Pascal compiler catches some MAMake errors that the C++ compiler won't.

Hard copy? Hundreds of pages have been written about C++ and MacApp. The most useful, in my opinion, is Appendix E of the MPW C++ reference, entitled "MPW C++ Style Guide." In 35 pages, the essentials of C++ programming are set forth. It's not a tutorial; it's the sort of thing that's helpful in this kind of total immersion learning. It isn't theoretical and analytic; if you want to know why things work the way they do, consult the other (excellent) reference materials, including those mentioned above.

A surprising comfort level

It surprised me a great deal, but I felt comfortable with C++ after only two weeks. I found that the choice of object oriented programming in general and MacApp in particular is far more critical than the choice between Pascal and C++. And I'm pleasantly surprised at some of the rigor that C++ can enforce. Private members, for instance, are definitely a good thing.

C++'s flexibility does allow typos to pass into compiled code a little more easily than in Pascal. But on the whole, while I realize there are critical differences between Pascal and C++- particularly when you examine how the languages actually run-from a user's point of view, both seem to serve well for implementing MacApp applications.

While my "total immersion" method may not work for everyone, I do think it's worth a try. Its prime advantage, at least to one who is as untheoretical as I am, is that it causes you to spend your time developing software rather than discussing it or reading about it.

 

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.