Archive

Archive for May, 2011

Smalltalk Simple Image-based Persistence

May 30th, 2011 5 comments

In an enlightening blog post, Ramon Leon explains that most applications are designed for small businesses with small amounts of data. Therefore most applications will never have to scale (i.e. become the next Twitter), so a relational database is overkill. However, persisting by simply saving the image is slow and error-prone.

Based on these ideas, he suggests a simple (one class) framework which saves only your model. The idea is to use it as long as you can get away with, which may be forever.

I packaged the code from the post, added a few tests, and put it on SqueakSource as SimplePersistence.

It’s really easy to give your application persistence (see SPFileDatabase’s class comment). The three steps are:

  1. Subclass SPFileDatabase
  2. On the class-sode of the subclass, implement
    • #repositories – returns a collection of objects to be saved
    • #restoreRepositories: – gets passed back the collection.

That’s it! Now, whenever you want to save, call class>>saveRepository or class>>takeSnapshot (background save).

Categories: Programming, Smalltalk, Web Development Tags:

Objective-C in Smalltalk

May 2nd, 2011 6 comments

I’ve been playing with an Objective-C Bridge in Squeak and Pharo. Now I can do cool Cocoa things in-image! For example, sometimes I need a Mac app’s bundle identifier. I previously used a Ruby script. There are a few options, but the easiest is MacRuby:

#!/usr/local/bin/macruby
 
p NSBundle.bundleWithPath('/Applications/Mail.app').bundleIdentifier

Now, I can do it in Smalltalk, although it’s a little wordy:

bundle := ObjectiveCObject findClassName: 'NSBundle'.
aBundle := bundle bundleWithPath: '/Applications/Mail.app' asNSStringUTF8.

There were two things annoying me about the above code:

  1. Object create – wow, a lot more complicated than MacRuby!
  2. #asNSStringUTF8 – I was certain that this could be done automatically by the bridge, and in fact, the above code has a memory leak, because the NSString must be released.

The first one, I did something about. I wrote a simple little class called ObjC to use like a namespace for ObjC classes. The above Smalltalk code becomes:

ObjC NSBundle bundleWithPath: '/Applications/Mail.app' asNSStringUTF8.

Okay, we’re getting better… Currently not a part of the bridge, the changeset for the class is available here. I’m still working on the NSString issue, so standby…

Categories: Mac, Pharo, Smalltalk, Squeak Tags:

windows 7 product key

windows 7 product key

windows 7 key generator

windows 7 key generator

free winrar download

free winrar download

winzip activation code

winzip activation code

free winrar

free winrar

winzip free download

winzip free download

winrar free download

winrar free download

winrar download free

winrar download free

winzip free download full version

winzip free download full version

windows 7 activation crack

windows7 activation crack

windows 7 crack

windows 7 crack

free winzip

free winzip
\n