Trying to teach myself some programming again, I thought I’d give Apple’s XCode a whirl. After all, last week I found myself bemoaning the fact that when I were a lad all computers came with a programming language built-in or bundled for free, and generations of youngsters grew up capable of writing simple but useful software. Nowadays, I grumbled, you don’t get that nowadays, you have to spend shed loads of cash on programming environments.
Not true, of course. Apple bundle XCode with their OS. Trouble is, it’s not exactly Sinclair Basic. Or even RealBasic.
Take the usual first step – get your program to say “Hello World!” on the screen. In RealBasic this would go something like:
MsgBox"Hello World!"
In XCode’s Cocoa (Objective C) environment, however, it looks a bit like this:
- (void)drawRect:(NSRect)rect { NSString* hws = @"Hello World!"; NSPoint p; NSMutableDictionary* attribs; NSColor* c; NSFont* fnt; p = NSMakePoint( 10, 100 ); attribs = [[[NSMutableDictionary alloc] init] autorelease]; c = [NSColor redColor]; fnt = [NSFont fontWithName:@"Times Roman" size:48]; [attribs setObject:c forKey:NSForegroundColorAttributeName]; [attribs setObject:fnt forKey:NSFontAttributeName]; [hws drawAtPoint:p withAttributes:attribs]; }
Yikes. Not quite a fair comparison, I admit. And it is free, and although it won’t compile Windows or Linux apps like RealBasic will, I’m guessing it’ll generally make leaner, faster code.
The example of code above comes from a rather good tutorial for beginners:
http://en.wikibooks.org/
wiki/Programming_Mac_OS_X_with_Cocoa_for_beginners
Oh well, they say brain-stretching work is good for you. Beats Sudoku.
you also get Ruby, Python and Perl on a Mac, hello world in Python is:
print “hello world”
Very interesting – will investigate those…