Digging for code

October 8, 2006


Recently, Google labs introduced their new “Code Search” tool. This got me to start looking for similar search engines on the web. One of the nice one’s I’ve used is “Programming is hard” which has some nice formating, but limited languages. While many of the examples are way over my head as a new coder, these snippets have a lot to teach. I’t is mind blowing just how efficient an experienced programmer can make a routine.

As I said though, there are few good sources for Objective C, Cocoa, or Applescript. ALthough Google found over 200 examples for Cocoa related code. Of course there are plenty of publicly available sources for learning Objective C, but they are sparse with code examples.

Technorati Tags: , , , ,


Objective C #3 – Structures

September 27, 2006


It’s been awhile since I posted about my journey into Objective C and Cocoa programming. It’s going a lot slower than I had hoped, but I up to page 260 in “Programming in Objective C” so at least I’m not a complete slacker. It doesn’t help that most of the really basic material is as exciting as a wet shoelace. But today on my commute to work I read about Functions and Structures. This is pretty darn cool stuff. Functions are really just quick and easy methods, but Structures are where it really gets interesting. A structure is a way to group related variables together and then assign or recall values really quickly. Here is an example from the book:

struct date


int month;

int day;

int year;


This bit of code intializes a set of variables named month, day and year which comprise the variable called date.

struct date today;

Now we have declared a new date named “today.” Here’s the cool part. It’s really easy to set the day and year of your date as follows:

today.day= 21

today.year = 2003

That’s it. Now your date variable contains a day and year that can be recalled and reasigned as needed. The period simply says to access the sub variable “day”

You can even set the entire date like this

struct date today = { 7, 2, 2004 };

I’ll try to add some more later this week. The other thing I found pretty interesting is the use of Definitions (#define).

Technorati Tags: , , ,

Objective C #2 – Method Arguments

August 25, 2006

I’m still working through “Programming in Objective-C” (Stephen Kochan). Since I commute on the train, I have plenty of time during the day to read. I’m about a third done. I hope to finish in a couple of weeks. So keep in mind this is all still really new to me. I’m not trying to create a tutorial, but rather share my experience learning the language.
This one is very closely related to the previous post. This is about methods that accept arguments. If you break down this line:

– (void) setNumber: (int) n

We already know that the beginning declares that the method will not be returning any values (i.e. void). But the colon says that this method will be accepting an argument. The next bracket indicates that the method setNumber will read in an integer. The integer is named “n.” Just as a side note, the minus sign in front of (void) indicates that this is an instance method. The other option is the plus sign to indicate a class method.
Here’s a more complex one:

– (void) bounceBack: (Height *) b;

This one is a method that accepts something that is of the type class Height which had been previously declared. The asterisk is what tells us that Height is already a class. The learning curve is getting steeper now.

Technorati Tags: , , ,

Objective C #1 – Return Values

August 23, 2006

Recently I began to teach myself Objective C. My final goal is to program in Cocoa for the Mac. The process is slow going, but really interesting. I’m adding a regular section to highlight some of my thoughts about learning a programming language. The first post is about “Return Values”

-(void) setNumerator;

This expression declares a new method that is not expected to return anything (i.e. void)

-(double) myNumber;

declares a method that should be returning a double precision number

-(int) getNumber;

should return an integer.

All this is very cool. It makes it pretty easy to see what kind of result should come back when the method is put into action. While it’s not as direct as Ruby, I’m getting it. I’m even more green with Ruby, but I’ve heard such great things about it, that I had to check it out. I highly recommend this quirky but entertaining guide.

Technorati Tags: , , ,