Digging for code

October 8, 2006

Temp

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: , , , ,

Advertisements

Thanks for that

October 6, 2006

I came across this WordPress blog post today. The author breaks down some fundamental guidelines for coding. To summarize: You should take as much care formating code as you would with an essay. This is good advice. I’m still a beginner when it comes to heavy lifting with Objective C, but I have already learned this lesson the hard way. It is much easier to find mistakes when you have the proper punctuation. Just imagine writing an essay without carriage returns, indentation, page breaks or punctuation. It would be pretty tough finding where you forgot to put that closing quote.

Technorati Tags: , , ,


Objective C #3 – Structures

September 27, 2006

ObjectiveC

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: , , ,


Quick shot Automator

September 23, 2006

I use a lot of Applescript when I use my Mac. I’ve learned quite a bit about the language over the years. Needless to say that it makes me a little snobby about using Automator. For the most part, I hate automator because it is so limited. What it has is pretty much all you get to do. However, once in awhile I gain an added appreciation for its simplicity. Here is an Automator “script” that takes a screenshot and then places the screen shot in my blog photos library within iPhoto. I’m sure if I worked long enough I could have come up with an Applescript to do it, but Automator allowed me to do it in about 10 seconds of work. Here it is (and yes, I used this automator “script” to take the screenshot)

Automator

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: , , ,