[comp.sys.next] NextStep programming problem: /NextDeveloper/Examples/Lines

pts@mendel.acc.Virginia.EDU (Paul T. Shannon) (11/11/90)

I'm trying to do three things at the same time:

   - learn NextStep and PostScript programming
   - understand the Interface Builder
   - create a simple, 2d graphics program for a perceptual psychology experiment

Looking around through NextDeveloper/Examples, I found the directory 'Lines',
and guessed that it would be a good program to study.  Sure enough, I've
learned a few things.  But I've stumbled upon what seems to me to be a very
unusual use of an outlet variable in this program.  You may wonder why
this leads me to post a message to comp.sys.next...well, it's because either

   a.  I'm totally confused, and someone might set me straight, or
   b.  this really is a bizarre usage of an outlet, which suggests that
       Lines is not a good example to learn from, and therefore 
   c.  I may get somebody to suggest a better PostScript/NextStep program
       for me to study.
    
The outlet variable is declared in LinesView.h, as

    int numCorners;

which suggests it's used (and it is) as a place to store the current number
of corners in the geometric figure that bounces around the screen.  But
it also is used as an outlet: it appears under the heading 'Outlets of Source'
under the CustomView Inspector, Connections.  Then, in the file LinesView.m,
in comments for the  setNumCorners instance method:

// setNumCorners gets called everytime we move the slider. Note that 
// it also gets called at start to initialize the numCorners variable ---
// this we accomplish by treating the numCorners instance variable
// as an outlet and connecting it to the slider. But, instead of setting
// numCorners from the slider, we set it to its value.

- setNumCorners:sender
{
    numCorners = MIN (MAXNUMCORNERS, MAX ([sender intValue], MINNUMCORNERS));
    [self createOpsArray];
    [self resetBoundingBox];
    [self display];  // Redisplay the whole thing to avoid inconsistency

    return self;
}

In the Interface Builder Reference, 8-106, it says
   'Outlets are instance variables of type id that store (by reference) the
    identity of another object in your application.'

If the type "id" is typdef'ed to int (32 bits), then this might explain why
this works.  And it *does* work. Perhaps it really is good programming style,
and I'm just confused.   But if it's an example of tricky programming, then
perhaps I could find (that is, perhaps someone will suggest) a program that 
uses a more conventional approach, better suited to a novice NextStep 
programmer.

One more question:  Is there a better forum for me to bring up questions like
these?  Is there a next programmers' mailing list?

 - Paul Shannon
   pts@virginia.edu