giovedì 28 giugno 2007

Pastell - an XPath-like library for Squeak

I've just released on SqueakSource a small package called Pastell. Pastell is an add-on for YAXO (Squeak's built-in XML parser) which adds some methods that make navigation of an XML DOM tree much easier. Basically, it's a Smalltalk-based version of XPath.

Pastell may be found in its own repository.
Extensive documentation is included in the package (look at the class comment of the PastellInfo class) and has also been replicated on the Swiki.

RESTful Web Services Example 2.1 - Yahoo! Web Search

Example 2.1 of the RESTful Web Services book shows a simple REST Web Service client, for the Yahoo! Web Search service.

Since the book has a detailed description of the client, I'll just show the code:
Chapter2 class>>yahooWebSearch: aString
| baseURI document term xml |
"Code taken from RESTful Web Services. Copyright © 2007 O'Reilly Media, Inc.
All rights reserved. Used with permission."
baseURI := 'http://api.search.yahoo.com/WebSearchService/V1/webSearch'.
term := aString encodeForHTTP.
xml := HTTPSocket httpGet: baseURI , '?appid=restbook&query=', term .
document := XMLDOMParser parseDocumentFrom: xml.
document ResultSet Result Title
do: [:element |
Transcript
show: (element contentString);
cr]

The code may be found on the RWS repository on SqueakSource and is included in the RWS-gc.2 package.

If you confront the Squeak code with the original Ruby code from the book, you'll notice a couple of differences. First of all, this method takes a single String argument, which can have either one search key or more than one, separated by spaces. So the #yahooWebSearch: method actually corresponds to the #print_page_titles method in the Ruby source.

Another difference may be seen on lines 5-6 of this code snippet. Where the Ruby example uses open-uri and #open():
require 'open-uri'
#...
xml = open(BASE_URI + "?appid=restbook&query=#{term}").read

# Parse the XML document into a data structure.
document = REXML::Document.new(xml)

I use the HTTPSocket class and its #httpGet: message. This message returns a stream that may be passed to XMLDOMParser>>parseDocumentFrom:. But the most glaring difference is on line 7: instead of the XPath expression used in the Ruby code, I use
document ResultSet Result Title do: [...]

that's because Squeak's XPath library, being just a 0.1.1 release, has some problems with all but the most simple XPath expressions. For this reason I concocted a small hack that allows me to navigate a DOM structure by sending messages whose selectors are the same as the XML nodes I'm interested into. In the future, either I'll build a plugin to connect to Libxml2, or I'll build a full-blown, pure-Squeak, higher-order-messaging-based system.

For the next post in this series, I'll show a Squeak version of the del.icio.us client described in chapter 2.

Converting RESTful Web Services' examples to Squeak

I've started reading Richardson & Ruby's RESTful Web Services book. Since most of the examples are in Ruby, I though it would be a good exercise to convert them to Squeak. For this reason, I have asked and obtained from O'Reilly a permission to publish my Squeak code on this blog.

This first post has all the instructions needed to set up your development environment.

In order to use the code I'll be posting and to play with it, you'll have to install a Squeak image. If don't have one installed, I suggest using one of Damien Cassou's Squeak-dev images. These are custom images, based on the standard 3.9 and 3.10a Squeak images, that come with all sorts of development tools already installed. The image I'll be using for these examples is squeak-dev-07.6, based on Squeak 3.9.

Once you have installed the image, open it and then open the Monticello Browser tool. Add this HTTP repository by clicking on the +Repository button:
MCHttpRepository
location: 'http://www.squeaksource.com/RWS'
user: ''
password: ''

Open the repository and load the latest RWS package and you're done. The package contains the code for the examples and some support code I've added to streamline the whole experience.

In the next post, I'll start showing the examples.

mercoledì 27 giugno 2007

Un paio di articoli su Smalltalk

Approfitto della citazione di Gabriele Renzi per segnalare un paio di blog su Smalltalk.

Il primo è il nuovo blog di Gilad Bracha, aperto dopo il suo passaggio da Sun (dove lavorava su Java e JVM) a Cadence (dove sta lavorando a un progetto basato su Squeak ma di cui ancora si sa molto poco). Gilad Bracha pubblica poco, ma quello che pubblica è in genere molto interessante.

Consiglio in particolare gli ultimi due articoli, il primo sul Message Based Programming e il secondo sui problemi legati ai costruttori in linguaggi OOP.

Il secondo blog che volevo segnalare è quello di Vassili Bykov. Anche lui al momento lavora in Cadence, sullo stesso progetto di Gilad Bracha.
Mi sono piaciuti particolarmente i due articoli sul currying in Smalltalk (uno e due).

sabato 23 giugno 2007

Squeak RPM Packages for Fedora 7

I have prepared a new batch of Squeak RPM packages:

Squeak VM 3.9.8 - i386 (Debuginfo package, Source package)

Squeak 3.9-7067 image (Source package)

Squeak 3.10alpha-7105 image
(Source package)

The Squeak VM package comes with the .source files already included, you'll need only that and an image package to start hacking.

This packages are experimental, so they lack proper requirements control, etc. The long term goal is to get them included in the main Fedora repository.

martedì 19 giugno 2007

Seminari su Ruby e Rails

Come già accennato, tra la fine di Maggio e i primi giorni di Giugno ho tenuto due seminari da tre ore ciascuno su Ruby e su Rails per il corso di Linguaggi di Programmazione ad Oggetti II.

I PDF delle slides sono disponibili qui e qui .I file .ZIP contengono anche delle tracce di soluzione delle esercitazioni proposte.
Tutto il contenuto è disponibile sotto licenza Creative Commons Attribution-NonCommercial-ShareAlike.

Nuovi Libri

Con solo 10 giorni di ritardo sulla data di consegna (grazie, Poste Italiane), oggi mi sono arrivati i libri che stavo aspettando da Amazon. Ho dovuto pagare quasi una decina di Euro per IVA, “spese postali” e “presentazione in dogana”, ma ne è comunque valsa la pena, anche perché il postino mi ha lasciato anche il sacco postale, che è comodo e resistente :-)

Tra i volumi che mi sono arrivati, ne segnalo due:
Agile Web Development with Rails
Agile Web Development with Rails, ovvero la seconda edizione del volume su Rails scritto da DHH e PragDave;
RESTful Web Services
RESTful Web Services, di Leonard Richardson e Sam Ruby.
Il primo volume ho avuto modo di leggerlo abbastanza a fondo prendendolo in prestito dalla biblioteca dell’Agile Group per preparare un piccolo seminario su Rails nell’ambito del corso di Linguaggi di Programmazione ad Oggetti II. Visto che avevo già la prima edizione, ho preferito comprarmene una mia copia.
Il secondo volume è invece quello che aspettavo con più impazienza, e vedrò di farne una recensione al più presto.

lunedì 18 giugno 2007

Ok, proviamoci

Dopo solo un paio di anni in cui stavo considerando di aprire un blog mi sono finalmente deciso a agire. Per cui eccoci qua: first post, etc etc.

Sarebbe utile, per non dire tradizionale, spiegare in questo primo post chi sono e di cosa parlerò qui dentro. Però io sono pigro, quindi vi toccherà arrangiarvi e andarvi a frugare gli archivi e i tags, non appena avrò scritto qualcosa per riempirli.