Feeds:
Posts
Comments

Archive for February, 2008

Learn Cocoa

I just stumbled upon Learning Cocoa, an interesting post at Engineering Hints that provides advices for beginners wanting to learn Cocoa. As a first step, the author suggests starting with our Become an Xcoder booklet:

The first stage is to go through an excellent short PDF manual called Become an Xcoder. This really does require no prior knowledge of C, C++ or any other language that most manuals assume the reader has. It gives the reader sufficient knowledge to understand what is happening in all the different sections of a project as well as working with basic classes such as arrays or strings.

The book is free and is published under a Creative Commons Attribution license. You can download it (PDF) or read it online and comment on it in a dedicated Wiki at CocoaLab.

The project was started by Bert Altenburg and inspired by his famous AppleScript for Absolute Starters guide. Alex Clarke, of CocoaLab, joined us to write the book and also took on the duty of editing it.

By the time you read this, the book should have reached its 80,000th download.
The original version is in english and, thanks to the work of Mazen ArRammal, Maria Shinoto, Nobuatsu Sekine and Shiva Huang, we now have translations in the following languages:

We haven’t updated it yet for Leopard’s Xcode 3, but most material is still relevant. March 2008 update: the book has been updated for Leopard and Xcode 3 (see this post).

In addition to the resources reviewed in the Engineering Hints post I’d like to point out that F-Script proves to be a useful tool for learning Cocoa, in conjunction with the Xcode toolset. F-Script provides an interactive environment where one can type snippets of Cocoa code, have them executed immediately, and visualize results. All without having to create a complete program and generating output. This interpreted environment also includes a set of tools allowing inspecting and manipulating live objects graphically. This lets you explore Cocoa and quickly experiment with APIs or algorithms you are working on.

This is also an efficient and fun way to learn programming. Rob Abernathy wrote about this way of using F-Script:

Since I’ve downloaded and installed F-Script, my 7 year old son has been working through the tutorials for F-Script. Has been having a great time with it and is learning a great deal. F-Script is a great tool for teaching programming.

Finally, Cocoa programmers of every age will have a lot of fun and learn a lot by browsing the wonderful Cocoa Literature List created by HyperJeff.

This is the entry point for a world of articles, tutorials and books about Cocoa technologies contributed by the developer community over the years. Hundreds and hundreds of them. Not only that, but it also comes with a great content search system. Check it out, it is full of gems!

Advertisements

Read Full Post »

Tomorrow, I'll be giving a talk at the Microsoft TechDays 2008 conference. This is the main developer-related Microsoft event here in France. There will be about 280 technical sessions and I’ve heard the organizers expect 15,000 attendees! The subject of my talk is LINQ, a set of new technologies added by Microsoft to languages such as C# and Visual Basic. LINQ aims at radically simplifying the way object-oriented languages deal with objects and other information models such as relational databases or XML infosets.

I've been hooked on LINQ since the beginning, when its ideas started to be experimented in the context of the Cω research project. My buddy Fabrice Marguerie, with whom I'll be giving the talk, describes LINQ in his new book, LINQ in Action:

LINQ stands for Language Integrated Query. In a nutshell, it makes query operations like SQL statements into first-class citizens in .NET languages like C# and VB. LINQ offers built-in support for querying in-memory object collections such as arrays or lists, XML, DataSets, and relational databases. But LINQ is extensible and can be used to query various data sources […]

In addition to offering novel approaches to deal with data, LINQ represents a shift toward declarative and functional programming. When people ask me for reasons to learn LINQ, I tell them that they should learn it in order to be able to use it with XML, relational data, or in-memory collections, but above all to be able to start using declarative programming, deferred execution, and lambda expressions.

While LINQ and OOPAL (the array programming model adopted by F-Script) are based on very different principles, they share a common goal: providing a higher-level programming model that allows for more expressive and powerful language constructs. We can illustrate this with the following example, comparing some typical code in a classic object-oriented language (here, Java) with the code in C# with LINQ and F-Script with OOPAL.
In this example we deal with the object model of an airplane company:

Say we have a collection of flight objects named flights. Starting there, we want to get the names of the pilots in charge of a flight to Paris on a B747 airplane. And we want them sorted by salary in increasing order.

Java


TreeSet<Pilot> pilots = new TreeSet<Pilot>(new Comparator()
{
    public int compare(Object o1, Object o2)
    {
        if (((Pilot)o1).salary() < ((Pilot)o2).salary())
            return -1;
        else if (((Pilot)o1).salary() == ((Pilot)o2).salary())
            return 0;
        else
            return 1;
    }
});

for (flight : flights)
{
    if (flight.arrivalLocation().equals("PARIS") && flight.airplane().model.equals("B747"))
    {
        pilots.add(flight.pilot());
    }
}

ArrayList<String> result = new ArrayList<String>();

for (pilot : pilots)
{
    result.add(pilot.name());
} 

C# (with LINQ)


var pilots = (from flight in flights 
              where flight.arrivalLocation == "Paris" && flight.airplane.model == "B747" 
              select flight.pilot).Distinct();

var result = from pilot in pilots 
             orderby pilot.salary
             select pilot.name;

F-Script (with OOPAL)


pilots := (flights at:flights arrivalLocation = 'PARIS' & (flights airplane model = 'B747')) pilot distinct.

result := pilots name at:pilots salary sort.

The three programs manipulate plain old standard objects (respectively Java, .NET and Cocoa objects). However, the programming models on which they are based differ and, as you can see, the C# and F-Script versions are shorter and more expressive.

If you are around and want to know more about LINQ, you can come to my session!

Read Full Post »

F-Script can be used on its own or as a sub-language in Objective-C. This allows using F-Script’s object manipulation capacities (e.g., array programming) from Objective-C code without being forced to extend Objective-C itself.

The sub-language term refers to the situation where some code in a given language is embedded in the source code of another program written in another language. For example, Java programmers can use SQL as a sub-language via the JDBC API. A sub-language may be used by a host language without requiring that the host language be extended or modified: the sub-language is integrated using a simple library.

This requires a way of exchanging data between the Objective-C and F-Script, i.e., we must be able to exchange any type of object. Sharing objects between different languages is not a simple matter. There are basically two solutions:

  1. Providing a run-time that bridges the object models of the two languages
  2. Using the same object model in the two languages

F-Script adopts the second, straightforward, approach. This allows any object to be exchanged between the two languages with no limitations. Both F-Script and Objective-C can freely share and manipulate the objects, because they are native to both languages.

For example, suppose we have an array of NSWindow objects in our Objective-C program. We want to put in front of the screen the windows in this array that contain an edited document. Moreover, we want the windows to be “front-sorted” according to the alphabetical order of their titles. Finally, we want to know how many of such “edited” windows are present in our array. We decide to write that little algorithm in F-Script, given how easy this is, and to put it right inside our Objective-C source code.

In F-Script, the parametrized block for performing the specified task would be:

[ :w | w := w at:w isDocumentEdited. (w at:w title sort) reverse orderFront:nil; count]

This defines a block (aka closure or lambda) with a parameter named w that is used to pass the array of windows. The block uses the standard isDocumentEdited method provided by the AppKit to determine if a window is associated with an edited document. Such windows are selected, sorted and brought to front. Finally, their number is returned.

Using this code in Objective-C is easy. All we have to do is:

  1. Add FScript.framework to our project and add the following import directive in our Objective-C source file: #import <FScript/FScript.h>
  2. Put our F-Script code into an NSString
  3. Turn it into a block by sending the asBlock message to the string
  4. Execute this block in the same way we would have done in F-Script: by sending it a value:message, passing our array of windows as argument (in the Objective-C example below, we pass an array that contains all the windows of the application).

NSArray *windows = [[NSApplication sharedApplication] windows];

NSNumber *count = [[@"[ :w | w := w at:w isDocumentEdited. (w at:w title sort) reverse orderFront:nil; count]" asBlock] value:windows];

That’s all for today. Enjoy!

Read Full Post »

Core Animation Book

The Pragmatic Programmers have just published a Beta version of Bill Dudney‘s forthcoming Core Animation book.

Mac OS X Leopard introduces a fantastic new technology that makes writing applications with animated and cinematic user interfaces much easier. We’ll explore this new technology by starting with the familiar concepts you already know from the pre-Leopard development kits.

Then we’ll see how they apply to the new frameworks and APIs. We’ll build on your existing knowledge of Cocoa and bring you efficiently up to speed on what Core Animation is all about.

With this book in hand, you can add Core Animation to your Cocoa applications, and make stunning user interfaces that your user’s will be showing off to their friends.

The Beta book program let us access the book as it is written and provides the option to also get the paper book when released (planned for july 2008). I’ve just brought the combo, and downloaded the PDF. It’s about 70 pages long for now, about a third of the planned 220 pages, and it looks like 70 pages of pleasure if, like me, you enjoy computer animations and the possibility of using them in your programs.

The author recount how, back in the NeXTStep days, he used to create files just so he could delete them and see the nice recycling animation in the dock. I vaguely remember doing the same… Now, could someone tell us if the black hole, which was the ancestor of the recycler, was also animated?

Read Full Post »

C4[1] Conference Videos

The videos of the latest C4 conference are starting to appear online.

C4, set up by Jonathan “Wolf” Rentzsch, is a conference for Mac developers that departs from the usual big, ultra-controled, corporate events. From what I’ve been told, this one definitely has the “indie” touch.

The first video is Indie Ethos.

Jonathan speaks about “an indie conference for indie developers” and explores aspects of the industrial dynamic currently at work in our field. It’s an interesting and very entertaining session.

Read Full Post »