Saturday, April 28, 2007

Hard Disk Crash

...You know when people tell you to do backups ? Feeling guilty ? :-)

Well, most of my data is usually backed up, but... even so, there's still a lag usually, particularly for "not-so-important data", etc. Add to this usual mix some data put away "temporarily" from my main computer... and that's when my LaCie 250Gb external drive choose to die. Around 200Gb of data lost, among them some that I could get back with various difficulty somewhere else, eg on some dvd or other computers (the LaCie *was* the main/more used backup plan), and some truly lost (yes, this "temporarily moved" data, yes, it's you I'm talking about), or some data recently copied only on the LaCie... Of course this drive is around 3 years old, and I actually had some thoughts recently of doing a proper backup of everything there was on it, for convenience, and for fear of such an accident. Of course too, I ended up way too busy to actually do it...





Still, a bit of luck: there was no scratching noise, in fact, there wasn't any noise at all: the disk just didn't start, which meant that it was more likely an electronic fault than a mechanical one. Removing the hdd from the LaCie enclosure and plugging it directly on a computer didn't do anything either (so it sadly wasn't the LaCie controller board). So that left us with the actual hdd electronic board... I then looked on the web for an hdd from the same brand and the same model -- and found a cheap one from an online reseller. After receiving it, I checked it -- yes, it was the same model, yes, the same year, yes the same firmware... ah. No. not the same firmware ! well, still, only two months separated those drives, so I crossed my fingers and started removing the controlling board of the "new" drive to swap it with the one on my crashed drive. Never having done that, I wasn't quite sure what to expect :-) but it's in fact really straightforward (you just need the right kind of screwdrivers -- Torx). The only difficulty is in finding a control board that is compatible with your hdd!

To cut the story short, the "patched" drive started happily and worked fine, so I passed the day swapping and burning dvd of the drive's content ;-)

One thing for sure is that I will seriously think of building a proper backup solution (ie, automated/redundant) for hosting "home" data (photos, videos, music...) asap... I was lucky to save this drive ! these kind of content is annoying as they quickly take so much space, yet (for at least some of them) they are invaluable...

Saturday, March 24, 2007

NeXT videos & WebObjects



I found these two videos, the first one showing Steve Jobs demo NeXTstep 2.0, the NeXTCube 040 + Dimension, the slab, DBKit, in 1990.. it's always surprising to see how far ahead NeXT was, or reversely, how slowly did we progress on the software side, while the hardware we have now is insanely more powerful...



The second one shows again Steve Jobs, five years later. NeXT stations didn't sell, their state-of-the-art factory closed, they stopped producing hardware, and reconverted as a software only company. The tone of the talk seems to reflect those disappointment, with Steve trying to be excited about Distributed OLE and Portable Distributed Object (PDO), but you can feel it's not really anymore about changing the world... and yet, when analysing the state of the WWW and its future, Steve is absolutely dead on, and he then goes on to demo a beta version of WebObjects, which in the end will save the company (until it took over Apple). WebObjects was an absolutely amazing tech, and still is. The move to a J2EE implementation instead of the ObjC implementation, the availability of other solutions, and its curious downplay by Apple (while they use it for their store, they aren't exactly pushing it on the market, although they dramatically cut the price from hundred thousands of dollars to $500, to finally make it free). WebObjects had a huge impact on current "web application servers", many of them openly inspired by it. My preferred one is Seaside, a fantastic Smalltalk framework... for a great example of what you can do with Seaside, try dabbledb :-)

Note that there's two free software implementations of WebObjects in Objective-C, GNUstepWeb and NGObjWeb (part of SOPE, the web application framework used by Opengroupware.org).

Friday, March 16, 2007

GNUstep participates in Google Summer of Code 2007

The GNUstep project just announced that it was accepted in the Google Summer of Code 2007 :

GNUstep provides a cross-platform solution for Objective-C/OpenStep/Cocoa developers. This year, it offers various projects for SoC, such as adding new classes from Mac OSX 10.4, enhancing text system, porting WebKit to GNUstep, improve GNUstep on MS Windows platform, etc. It is a great chance for students to learn programming in many aspects.



read more | digg story


It's an excellent news ! we tried to be accepted first two years ago if I remember, and last year we were in but under the GNU umbrella... and no projects were accepted. Beeing accepted as a separate organisation should help us, hopefully !

Beside, any progresses on GNUstep will be immediately useful for Étoilé :-)

If you are a student, it's definitely worth a look -- GNUstep is one of the best OO api available here, and a fun place to hack.

update: Squeak is also in ! :-) great news too...

Thursday, March 01, 2007

Pink Floyd

Today I was in london for a job interview, and had a few hours to kill after it before going back to wales.. so I walked around a bit, and ended up reaching the Thames (duh! not surprising in london, is it ?). But I just ended up in front of the Battersea Power Station :






Of course, this power station is world famous because of Animals, the 1977 Pink Floyd album... ;-)

Sadly, I didn't have my camera with me, so the shots are from my mobile... here's some more:












ps: in the "cool for a geek dpt", I'm actually posting that from my laptop.. but through my 3G mobile cnx. With a cheap unlimited data plan, you basically get internet access everywhere -- as like here, in the train :D

Friday, January 19, 2007

Fun with Objective-C

Following a mail from david on étoilé dev about how it could be nice to try allocating ObjC objects on the stack, I played with a couple of things...

First I wrote a mini benchmark -- get a very basic object (a couple of ivars, one method "plop" assigning a value to an ivar), and then create an instance, initialize it (call the init method), call the one method the object has, then deallocate the object. 10000000 times. As far as micro benchark goes this one is pretty stupid but well, that'll give us some ideas of what's going on.

Without optimizations: ~4.10s (on a macbook pro 2.16Ghz, core duo)

Not that great -- doing the same thing in C++ with a similar object here is the timings I get:

Objects created on the stack: 0.24s (17 times faster !)
Objects created on the heap: 1.37s (3 times faster)

Ouch, the poor Objective-C... not a surprise when allocating objects on the stack, but even allocating them on the heap C++ is still 3 times faster.

One obvious reason is that Objective-C calls a lot of methods when creating an object; and a method call is more costly than a C++ function call. Still...

So the obvious idea here is to cache some method calls (ask their address then call the function directly -- as a C function). I restrained myself to alloc/init, the method the object had ("plop"), and the release method. Of course, there's other methods that are called by those, that won't be cached.

Caching method calls: 2.77s

It's still twice as slow as creating the C++ object on the heap, but it's anyway a nice performance increase.

Ok, then our only option left is to allocate the Objective-C object on the stack. Surprise:

ObjC objects created on the stack: 0.23s
ObjC objects created on the stack + cached imps: 0.13s

:-)

[note of course that it's a stupid micro-benchmark that doesn't prove much, but it's fun]


...


What ? how can you allocate objective-c objects on the stack ? ah well... you can:


#define STACKCLASS(class) typedef struct { @defs(class) } \
__CLASS_ON_STACK__ ## class;


#define STACKOBJECTISA(objectName,className,classIsa) \
__CLASS_ON_STACK__ ## className __INSTANCE_ON_STACK__ ## objectName; \
__INSTANCE_ON_STACK__ ## objectName.isa = classIsa; \
className* objectName = (className*)& __INSTANCE_ON_STACK__ ## objectName;


#define STACKOBJECT(objectName,className) \
STACKOBJECTISA(objectName,className,[className class]);

Here is an example:

STACKCLASS(Test);

int i;
for (i=0; i< 10000000; i++)
{
STACKOBJECT(test,Test);
[test init];
[test plop];
}

Basically, create the corresponding struct for the class and set the isa member (you can also cache the class isa to gain one message send). A bit of a hack, but that seem to work ok :)

Note of course that by doing that, you loose flexibility -- exit class clusters for instance (eg classes that actually returns another class instance, such as NSNumber), you can only work with concrete classes. And also, don't call directly -dealloc as it would try to deallocate the object, which is not needed as it was created on the stack (so if you need to do some cleanup you should do it in another method).

Here's the macros I used for imp caching (fairly straightforward):

#define CALLIMP(imp,object,sel,args...) \
(*imp)(object, @selector(sel) , ##args)
#define GETIMP(class,sel) [class methodForSelector: @selector(sel)];

You use them like that:

IMP imp1 = GETIMP(Test,alloc);
id p = [Test new];
IMP imp2 = GETIMP(p,init);
IMP imp3 = GETIMP(p,plop);
IMP imp4 = GETIMP(p,release);
[p release];

int i;
for (i=0; i< 10000000; i++)
{
id test = CALLIMP (imp1, c, alloc);
CALLIMP (imp2, test, init);
CALLIMP (imp4, test, plop);
CALLIMP (imp3, test, release);
}

Monday, December 04, 2006

Pointillist

What is it ? well, Pointillism is a style of painting I quite like, but Pointillist is simply the (working) name of a small graph library I'm working on. The previous post was discussing about the simulation software I wrote, which uses a simple graph view. I decided to clean up a bit that view, put it in a framework and commit it somewhere (likely on the étoilé repository). Not quite done yet, but it's shaping well, and it's now quite a bit more generic:




One of my "I will do it one day" project is a simple graph calculator... So in order to properly test the graph framework, I created a class using the StepTalk scripting framework to express functions (written in Smalltalk), which actually makes me rather close to have such a program :-P

for the curious, the code of the functions is:

Red function:

|y|
y := -0.5.
((x < 0.5) and: (x > -0.5)) ifTrue: [y := 1].
(x < -1) ifTrue: [ y := 0.25].
( x < -1.5) ifTrue: [ y := -2 ].
(x > 1.5) ifTrue: [ y := 2].
y := y + 1.5.
^y


Green function:
x sin - 1 / x


Blue function:

|y mod|
y := -1.
mod := x mod: 2.
(mod = 0) ifTrue: [ y := 1 ].
y := y - 2.
^ y


StepTalk is really cool btw -- Easy to integrate, and works both on OSX and GNUstep. Here is the code I use here:

id environment = [STEnvironment environmentWithDefaultDescription];
id conversation = [STConversation conversationWithEnvironment: environment
language: @"Smalltalk"];

(...)

id number = [NSNumber numberWithFloat: x];
[environment setObject: number forName: @"x"];
[conversation interpretScript: @"^ (x tan) / (x atan)"];
id result = [conversation result];

[values addObject: result];



values beeing a NSMutableArray containing the numbers returned by the steptalk function (the ^ in smalltalk is equivalent to a "return" statement in C). As you can see, difficult to have a scripting framework simpler than that to work with!

You can see that in the environment object I put an "external" (to the script) object, number, and this object can be accessed from the script using the given name (here, x). You could, instead of getting the script result, get the value of specific objects you put in the environment.

Anyway, it's very simple to add StepTalk support to your program, and recent versions even add nifty UI widgets to play with scripts.. also, StepTalk is not "just" a Smalltalk scripting framework : it can actually use other languages. On GNUstep for instance there's an Io bundle, so you could use Io instead of Smalltalk, etc. (it's actually fairly easy to add languages to StepTalk).

Note also that StepTalk automatically bridge the numbers in the script to actual NSNumber instances... which is how I decided to implement the math functions, and this actually demonstrate a very cool Objective-C feature; NSNumber doesn't have thoses sin,cos,mod.. math functions; so in another programming language we'd be stuck. A "normal" solution could be to modify StepTalk so that it would use something else than NSNumber (say, a custom class of ours), or reversely, to add those functions to NSNumber and recompile -- wait! you could do that with GNUstep (because we have the source), but certainly not with Cocoa on OSX. So how comes it works ?

Well, Objective-C has this great feature: categories. A Category lets you add new code to an existing class, at runtime. So that's simply what I did here -- I created a category on NSNumber with my specific math functions. Without needing to have access to the NSNumber source, or to recompile Foundation. Isn't it great ?