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

The best scanner app on mobile
People always say that the best camera is the one you have with you. Well, the same is true with scanners, and your phone can be a pretty great tool for scanning receipts and other documents while you're on the go. [Read more] | Read more »
MARVEL Avengers Academy guide - How to g...
MARVEL Avengers Academy lets you build your own superhero school and fill it with heroes from the Marvel universe. It can be a little slow going to get your school's attendance up though, so we've gathered together somesome tips to help you do this... | Read more »
Shadow Blade: Reload guide - How to hack...
Shadow Blade: Reload is the kind of action-platformer that would have happily sucked up hours of your time on a console a few years back.Now, you can take it with you wherever you go, and its mobile conversion is not too shabby at all. To help you... | Read more »
Tomb of the Mask guide - How to increase...
Tomb of the Mask is a great endless arcade game from Happymagenta in which quick reflexes and a persistent attitude can go a long way toward earning a top score. Check out these tips to see if you can give yourself an edge on the leaderboards. [... | Read more »
Smooth Operator! (Games)
Smooth Operator! 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Smooth Operator is a weird, weird two-player kissing game. Squeeze in for 2 player fun on a single iPad, creating awkward... | Read more »
Sinless: Remastered (Games)
Sinless: Remastered 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: | Read more »
_PRISM Guide - How to solve those puzzle...
_PRISM is a rather delightful puzzle game that’s been tailor made for touch screens. While part of the fun is figuring things out as you go along, we thought we’d offer you a helping hand at getting in the right mindset. Don’t worry about messing... | Read more »
Fractal Space (Games)
Fractal Space 1.3.1 Device: iOS Universal Category: Games Price: $.99, Version: 1.3.1 (iTunes) Description: Live the memorable experience of Fractal Space, a unique first person adventure & puzzle game by Haze Games! Will you... | Read more »
Set off on an adventure through the Cand...
Like match three puzzlers? If so, Jelly Blast, the innovative iOS and Android game which launched last year, is worth a look. Jelly Blast sees you head off on an epic adventure through the Candy Kingdom with your friends Lily, Mr. Hare, and Mr.... | Read more »
Ellipsis - Touch. Explore. Survive. (...
Ellipsis - Touch. Explore. Survive. 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: | Read more »

Price Scanner via MacPrices.net

13-inch 1.6GHz/128GB MacBook Air on sale for...
B&H Photo has the 13″ 1.6GHz/128GB MacBook Air (sku MJVE2LL/A) on sale for $899.99 including free shipping plus NY tax only. Their price is $100 off MSRP, and it’s the lowest price available for... Read more
Sale! 27-inch 3.2GHz 5K iMac for $1799, save...
B&H Photo has the 27″ 3.2GHz/1TB Fusion 5K iMac (MK472LL/A) on sale for $1799.99 including free shipping plus NY tax only. Their price is $200 off MSRP, and it’s the lowest price available for... Read more
cb Hardcase – Handmade and Premium Protective...
Baden-Baden, Germany based company cb innovations has introduced the new cb Hardcase for iPhone. Featuring fine Italian Premium leather that makes for a unique look and feel, the cb Hardcase... Read more
Free Quartz News Aggregation App Puts News Yo...
Quartz have released their new iPhone app. via the Apple App Store. The app, exclusive to iPhone (also compatible with iPad and iPod touch.), provides a whole new way to experience Quartz, which set... Read more
Apple Watch on sale for $100 off MSRP, free s...
B&H Photo has the Apple Watch on sale for $100 off MSRP. Shipping is free, and B&H charges NY sales tax only: - Apple Watch Sport: $100 off - Apple Watch: $100 off Read more
Sale! B&H Photo offers 12-inch Retina Mac...
B&H Photo has 12″ Retina MacBooks on sale for $300 off MSRP for a limited time. Shipping is free, and B&H charges NY tax only: - 12″ 1.1GHz Gray Retina MacBook: $999 $300 off MSRP - 12″ 1.... Read more
Save up to $470 with previous generation 27-i...
B&H Photo has previous-generation 27″ iMacs available for up to $470 off original MSRP, with prices starting at $1329. Each iMac includes free shipping, and B&H charges NY sales tax only: -... Read more
12-inch 1.1GHz Gray Retina MacBook on sale fo...
Musician’s Friend has the 12″ 1.1GHz Gray Retina MacBook on sale for $1199.99 including free shipping. Their price is $100 off MSRP, and it’s the lowest price available for this model. Read more
11-inch 256GB MacBook Air on sale for $999, $...
B&H Photo has the 11″ 1.6GHz/256GB MacBook Air on sale for $999.99 including free shipping plus NY sales tax only. That’s $100 off MSRP. MacMall has the 11″ 1.6GHz/256GB MacBook Air on sale for $... Read more
Free Reverso Context 3.1 For iOS Offers Conte...
Montreal, Canada based online and mobile translation and dictionary company Reverso has just released its Reverso Context 3.1 mobile app. The app provides its users with contextual translations of... Read more

Jobs Board

*Apple* Solution Specialist - Healthcare - C...
*Job Description* The Apple Solution Specialist - Healthcare proactively drives revenue and profit in the assigned sales segment, Healthcare, specific to Apple . This Read more
Infrastructure Engineer - *Apple* /Mac - Rem...
…part of a team Requires proven problem solving skills Preferred Additional: Apple Certified System Administrator (ACSA) Apple Certified Technical Coordinator (ACTC) Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Simply Mac *Apple* Specialist- Service Repa...
Simply Mac is the largest premier retailer of Apple products in the nation. In order to support our growing customer base, we are currently looking for a driven Read more
*Apple* Reporter - Business Insider, Inc. (U...
Business Insider is looking for a reporter to cover Apple , the biggest and arguably most important company in tech. As our primary Apple reporter, you will: * Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.