My Blog List

Thursday, October 28, 2010

Time Standing Still: Scouting for Time Travel Methods




This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 60450]
Running…
Scouting out Time Travel methods
Encountered a Clock
Within a Building
Within a Time Portal

Debugger stopped.
Program exited with status value:0.


.....

#include <stdio.h>
#import <Foundation/Foundation.h>

//Based on, Using Multi-Level Inheritance QStart page 131

@interface Portal : NSObject

-(void) print;

@end

@implementation Portal
-(void) print
{
    printf("Within a Time Portal\n");   
}
@end

@interface Building : Portal

-(void) print2;

@end

@implementation Building
-(void) print2
{
    printf("Within a Building\n");   
}
@end

//
@interface Clock : Building

-(void) print3;

@end

@implementation Clock
-(void) print3
{
    printf("Encountered a Clock\n");   
}
@end






int main (void)
{
    Clock *c3 = [Clock new];
   
    printf("Scouting out Time Travel methods\n");
    [c3 print3];
    [c3 print2];
    [c3 print];
   

    return 0;
}

Tuesday, October 26, 2010

Reviewing Concepts: Portal Inheritance, Object Method

This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 45244]
Running…
Portal Pilots: Encountered a Time Portal
Portal Type is a Bridge

Debugger stopped.
Program exited with status value:0.

.....

#include <stdio.h>
#import <Foundation/Foundation.h>

// Portalinherit: Simple Portal Inheritance

//Based on: inheriting base-class methods QStart page 125

@interface Portal : NSObject

-(void) print;

@end

@implementation Portal
-(void) print
{
    printf("Portal Pilots: Encountered a Time Portal\n");  
}
@end

@interface Bridge : Portal

-(void) print2;

@end

@implementation Bridge
-(void) print2
{
    printf("Portal Type is a Bridge\n");  
}
@end

int main (void)
{
  
    // Instantiate the 'Bridge' class
    // create an object called 'bridge' that points to the Bridge instance
  
    Bridge *bridge = [Bridge new];
  
    // execute an object method (page 83)
    //  syntax is '[object object_method_name]'
  
    [bridge print];
    [bridge print2];
  
  
  
    return 0;
}

Reviewing Concepts:Portal Used Since - Back and Forth in the Book



One of the things that is helping me develop my skills with how oop works is the one-simple-concept-at-a-time, nature of the Quick Start book. Having taught math, I know that abundant practice is the key to problem solving and learning. Of course that's the reason that I  do a second pass on each book exercise (I don't put them all out here). That's a good start, because even simply renaming things to match my own stories gives me more ownership, and makes me think through the code more.

Also for each piece of code that I get to run, I try to work back though each of the lines of code and make sure I can explain to myself the reason for that line being there and what it does.

In the process of re-thinking each line of code from my working example based on page 123, I remembered that the author had me instantiating an object differently a chapter or so back. I found the difference on page 97. 

Why in one case, page 123 (when author happens to be talking about inheriting base-class data members) in the Quick Start book do we only instantiate an object with

Bridge *c2 = [Bridge new];
c2-> year = 1917;

But in another case we use ‘init’, and the author makes a big deal about using it on page 97, when he talks about “using constructors”

Container *object = [(Container new], init:2];

….
In the case of  the page 97 ‘Container’ example, the author wants to make the point that a constructor allows me to ‘initialize the data in an object when I (you) create the object.”

He also says, “the constructor returns a pointer to the object, and you get that pointer by calling the super class’s init method.” The pointer returned for the page 97 example would be ‘object'.

Thanks Mr. Holzner, for focusing on one thing at a time.

...... 

Loading program into debugger…
Program loaded.
run
[Switching to process 44577]
Running…
This particular BRIDGE portal has been in use since 1917

Debugger stopped.
Program exited with status value:0.

 ...
#include <stdio.h>
#import <Foundation/Foundation.h>

//inheriting base class data members QStart page 122

@interface Portal : NSObject

{
@public
    int year;
}

@end

@implementation Portal

@end

@interface Bridge : Portal

@end

@implementation Bridge


@end

int main (void)
{
    // *bridge is a pointer
    //        a pointer holds the address in memory of a data item
    // "Bridge *bridge" means that this pointer is a variable of type 'Bridge'
   
    // Instantiate the Bridge class
   
    Bridge *bridge = [Bridge new];
   
    // Next the pointer, bridge, picks up the address in memory for the ivar/class variable 'year'
    //    year is an ivar that the Bridge class inherits from the Portal class
    // At the same time I set the value of 'year' to be 1917
   
    bridge-> year = 1917;
   
    //Am really looking forward to the day when I'm not hard-coding in information like the type of portal but am able to pick it up
    // from a class variable!
   
    printf("This particular BRIDGE portal has been in use since %i\n", bridge->year );
   
   
    return 0;
}
 

 

Saturday, October 23, 2010

Reviewing Concepts: Our Kind of Portal?




This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 28127]

Running…
The SLO Portal is a TimePortal


Debugger stopped.
Program exited with status value:0.






#import <stdio.h>
#import <Foundation/NSObject.h>


// 
// Based on ideas from Page 116 of Virtual Quickstart Guide Objective-C (Holzner)
// Verify that an object belongs to a class
// TIME TRAVEL IMPLEMENTATION
//    Verify that an object is a Time Travel Portal
//     Note: Travellers are into Slow Travel these days and Period Pilots likes to stay abreast of trends
//            so portals in SLO are particularly interesting
// It looks like 'isKindOfClass is a METHOD inherited from the NSObject superclass/baseclass

// isKindOfClass tells me wether an object is
//     a) a member of a class (like isMemberOfClass does)
// AND b) is a a member of any class derivedfrom that class
//

@interface TimePortal:NSObject
-(void) print;
@end

//METHODS  for TimePortal

@implementation TimePortal
-(void) print
{
    printf("This is TimePortal.\n");
}

@end

@interface SLOPortal:TimePortal
-(void) print;
@end

//METHODS  for SLOPortal

@implementation SLOPortal
-(void) print
{
    printf("This is SLOPortal.\n");
}

@end

int main (void) {
    TimePortal *c1 = [TimePortal new];
   
    // Find syntax for this method
    //
   
    if ([c1 isKindOfClass: [TimePortal class]]  ==YES)
    {
        printf("The SLO Portal is a TimePortal\n");
    }
   
     return 0;
}

Friday, October 22, 2010

Reviewing Concepts: Identify Time Portals

Las Pilitas Time Portal
I’m finding it really useful to have worked my way down to this book, which lays out one simple concept after another. It helps me to focus on one thought at a time and how oop is different than being a structured programmer. I wonder what it will be like to go back to those other two books I used during the summer, with their much more complex examples, when I’m done with this one. It sure is tempting to jump ahead in time and find out! 

One thing I’ve found challenging learning Objective-C is knowing that I’m doing things that I’ll be unlearning later on. In this example, I know that naming each class as a particular Time Portal isn’t as cleanly object oriented as I’ll be later on. I wouldn’t setup a record in a database schema like this. Or even in an old-fashioned file-management system. These are really instances of the same class.

Now, when I say ‘instances of the same class’ am I thinking right? There’s where a background using database methodology sometimes trips me up. Like when I catch myself thinking than an object is a variable or a class is a record. They aren’t.

Come back to this later and see if I had this ‘instance’ business right or not.


……..
[Session started at 2010-10-20 09:27:32 -0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May  5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 333]
Running…
Located Portal at LasPilitasSLO.
Located Portal at MillbraeBARTStation.

Debugger stopped.
Program exited with status value:0.
 ...

#import <stdio.h>
#import <Foundation/NSObject.h>

// GUI NOTE It's SHIFT Command/Apple F to do a find & replace in XCode
//       Been trying to find global find & replace for awhile now!
//       Regular appleF just highlights all the occurances in the piece of code

// Locate and Identify Time Portals for Portal Pilots Service

// Based on ideas from Page 112 of Virtual Quickstart Guide Objective-C (Holzner)
// Multiple Object Types and use of 'id'type
//
// Create objects of two different class types
//    Place them in the same variable of type id

// NOTE ORDER of *multiple* INTERFACE & METHOD sections
//        I write the interface for one class then it's methods
//      I repeat this structure for the other class
//  

@interface LasPilitasSLO:NSObject
-(void) print;
@end

//METHODS for LasPilitasSLO

@implementation LasPilitasSLO
-(void) print
{
    printf("Located Portal at LasPilitasSLO.\n");
}

@end


@interface MillbraeBARTStation:NSObject
-(void) print;
@end

//METHODS for MillbraeBARTStation
@implementation MillbraeBARTStation
-(void) print
{
    printf("Located Portal at MillbraeBARTStation.\n");
}

@end

int main (void) {
    LasPilitasSLO *c1 = [LasPilitasSLO new];
    MillbraeBARTStation *c2 = [MillbraeBARTStation new];
    // Remember
    // Here I am declaring 'container' to be of type id
    id container;
   
    container = c1;
    [container print];
   
    container = c2;
    [container print];
   
     return 0;
}

Tuesday, October 19, 2010

Reviewing Concepts: Sussin' Out Time Portals



Program loaded.
run
[Switching to process 1280]
Running…
Portal Pilot: Engineering Log for Common Era 99.921 
TimePortal count is 1
TimePortal count is 2
....
 Portal Pilots has identified 2 new Time Portals in the Common Era

Debugger stopped.
Program exited with status value:0.



------------------
#import <stdio.h>
#import <Foundation/NSObject.h>


// Based on Page 110 ClassVariables2 and use of 'self'keyword

//  
// Portal Pilots are always searching for new Time Portals
//
// 
@interface TimePortal:NSObject
static int count;

+(int) getCount;
@end

//METHODS
@implementation TimePortal
-(TimePortal*) init

{
// (p 136) The 'super' keyword alows me to access the base class
// super = superclass = base class .... the class from which my
//     class TimePortal inherits or derives functionality
//     (p 119) This inheritance can include methods from the superclass
//  QUESTION I thought that a class could make use of ivars in the
//     super class too. But am not finding that this minute. CHECK BACK
// Here I'm using a constructor from the superclass to initialize the
//      data in an object when I create it (p 97)
//    Contructors are very typically called 'init'
//    The superclass for 'TimePortal' is 'NSObject'
self = [super init];
count++;
// A constructor returns a pointer to the object. 
// I get the pointer by calling the super class's init method. (p 97)
return self;
}

+(int) getCount
{
return count;
}
@end



int main (void) {
// Would LOVe to know how to display the SYSTEM DATE here
// It must be a keyword
// Look in the C++ Book
printf("Portal Pilot: Engineering Log for Common Era 99.921 \n");
    TimePortal *tp1 = [TimePortal new];
printf("TimePortal count is %i\n", [TimePortal getCount]);
TimePortal *tp2 = [TimePortal new];
printf("TimePortal count is %i\n", [TimePortal getCount]);
printf("\t....\n Portal Pilots has identified %i new Time Portals in the Common Era\n ", [TimePortal getCount]);

return 0;
}

Friday, October 8, 2010

Reviewing Concepts: Keeping our Time Travel Customers from getting Stranded

 Please CLICK ON THE PICTURE to enjoy the details 
of this Time Travel Portal 
and you probably thought it was just the Millbrae BART station


Sometimes I just skim through my review adding all kinds of useful features to my Time Traveler app. Other days, I have to start over a square 0.

I never did figure out what was hanging up my code. I just had to go back to the most basic working model and recreate it one element at at time.

There's days when it's just like that.

 .......
Version:1.0 StartHTML:0000000193 EndHTML:0000045221 StartFragment:0000002859 EndFragment:0000045185 SourceURL:file://localhost/Users/Laurel/Apps%20Learning/Journal%20Portal%20Counter.doc
  GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 3410]
Running…
We at PORTAL PILOTS, know that NOBODY wants to get trapped Before the Common Era!

                  We care about your safety.

Todays entrance count for this portal,  is 5

Debugger stopped.
Program exited with status value:0.

//  REbuilding TimeTravelSecurit Counter from a working model up
//   to find why it just hangs
//  classVariables.m page 109
//   used final choice in NewProject

//
// Time Travel Security Counter (bugs in version 1 I'm not finding)
// TTravSecurityCounter2

// Based on review of ideas page 108 Quick Start Objective C
// Every object in a class shares the same variable
//      AND if one object changes a class variable, that variable is changed for all objects
// I can create a class variable with the 'static' keyword
// 
// In this case, I'm using a class variable to keep track of the number of objects of a particular class my code creates
//     PORTAL PILOTS needs to keep track of the number of time travellers that ENTER their portals
//       to make sure that the proper number of travellers eventually EXIT those portals
//     so this seems like the perfect opportunity to practice using a class variable



// Class

#import <stdio.h>

#import <Foundation/Foundation.h>

@interface ThePortal: NSObject 

static int PortalEntranceCount;
+(int) getCount;

// Remember that when I use '+' for a method it's a 'class method'
//    class methods are methods I can execute using just the class name - no object is required
//       (page 84 of the Quick Start Book)

@end

// Methods

@implementation ThePortal
-(ThePortal*) init
// Here 'self' returns a pointer to the current object
//   on page 97 the book does this same thing
//  using a constructor to initialze the data in an object when you create an object

// Don't do what I did and confuse this with the OTHER class method (getCount)
// which we can execute using just the class name no object

{
    self = [super init];
    PortalEntranceCount++;
    return self;
   
}

+(int) getCount
{
    return PortalEntranceCount;
}

@end


int main(void)
{
    ThePortal *tc1 =[ThePortal new];

    ThePortal *tc2 =[ThePortal new];
    ThePortal *tc3 =[ThePortal new];
    ThePortal *tc4 =[ThePortal new];
    ThePortal *tc5 =[ThePortal new];

   
    printf("We at PORTAL PILOTS, know that NOBODY wants to get trapped Before the Common Era!\n \n");
    printf("\t \t We care about your safety. \n \n");
    //printf("\r \r We care about your safety. \n \n");
    //printf("\f \f We care about your safety. \n \n");

    printf("Todays entrance count for this portal,  is %i\n",[
                                                    ThePortal getCount]);
   
    return 0;
}

Tuesday, October 5, 2010

Reviewing Concepts: Time Travel for the Masses

 Please click on the picture above, to see the beautiful details.

Loading program into debugger…
Program loaded.
run
[Switching to process 3340]
The Time Portal at the Las Pilitas Creek Bridge  has been available for public use since 1917
Running…

Debugger stopped.
Program exited with status value:0.

It's been hard not trying to jump ahead and do things I want to do. Whenever I do that I get tangled up in fighting with the documentation and trying out concepts I'm not ready for. Finally I've set some ground rules for myself. Only create my own play-with-it code that works around concepts and code examples I've got working so far. It's really hard not breaking that rule.

I enjoy playing with Time Travel in my daily art-journal, so I've been using ideas from those illustrations and story segments with this work. It makes reviewing book exercises (which I've already done but for which, I don't feel real ownership) much less frustrating. I concentrate on repeating book ideas, but with a little more zing than the typical checkbook balancing code.

I can still read about NSSTring and other concepts I haven't gotten to in the books I'm using, but I don't have to fret about knowing everything I want to know to use them yet.

The following sample is based around an earlier art-journal piece at my Simple Romantic blog. You can read that piece (and see other art-journal entries) by visiting The Simple Romantic.


GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 3340]
The Time Portal at the Las Pilitas Creek Bridge  has been available for public use since 1917
Running…

Debugger stopped.
Program exited with status value:0.

// TTrav4Masses

// Time Travel for the Masses
// Based on review of ideas page 102 Quick Start Objective C
// These object members are public access
// Though public access is the default, we like to state our
// societal norms
// You never know when ideas about access and egress might change!



#include <stdio.h>

#import <Foundation/Foundation.h>


// Class
@interface PortalAccess : NSObject
{
@public
       
    int publicAccessSince;
     
}

@end

// Methods

@implementation PortalAccess

@end

//Main

int main (void) {
   
    PortalAccess *portalAccess = [PortalAccess new];
    portalAccess -> publicAccessSince = 1917;
   
    printf("The Time Portal at the Las Pilitas Creek Bridge  has been available for public use since %i\n", portalAccess -> publicAccessSince);
   
     
    return 0;
}