Monday, September 29, 2008

CoreData and RAD tools under OS X

I've never been a RAD tool enthusiast. However, I recognize they have their utility. Especially when the "rapid" part comes from a well done library and not from drag and drop mumbo jumbo. Besides, I'm a big fan of drag and drop: I just don't think software should be built with drag and drop. About the "rapid" as in library part, I love Django. I was quite fond of Rails as well, but since Django reached the metaphorical age of consent I just dropped the whole Ruby thing.

Back to Cocoa... I'm mostly an OS X user and I'm quite into OS X development as well. Not that I often write desktop software, but when I do, it's often Cocoa stuff (possibly with Python bindings). And when I received Hillegass book (Cocoa(R) Programming for Mac(R) OS X (3rd Edition) ) I knew it was time to tackle Core Data.

Core Data is a nice technology. There is plenty of examples when you create not-completely-trivial applications only with drag and drop. Which looks good (though I never understood what kind of programming language/framework benchmark is writing a hello world program as most software is not constituted of hello world applications -- and you don't get paid to write hello worlds). Well... the drag and drop thing works as expected: even if you don't know about programming more than what I know about Votic literature, you may surprise your suspenders wearing hacker friends (at least until they ask you how the damn thing works).

Unfortunately enough, everything that is not that trivial (which accounts for most software projects, indeed) needs a bit more attention. The first thing you learn is that you must know the underlying technologies. This seems reasonable enough (after all if you want to work in the IT world you must learn a lot of things -- votic excluded). And when we talk about "learning", we are talking about long term investments. You learn Core Data, KV-coding and Cocoa Bindings and you use them for good. Or at least until Apple screws the whole thing up.

Even though when things become complicated you need to write real code, there is a lot of drag and drop/checkbox checking development done in Interface Builder. Of course you could write that code programmatically, but then you don't qualify for the RAD buzzword thing. The point is that bugs in code are usually signaled with tests, code lints or lawyer dispatches about that blown up nuclear plant you wrote the software for. If you don't write a function, the compiler or the interpreter will complain. If you forget to write part of a function, the software will crash (or the tests will fail, if you are a savvy programmer).

Unfortunately, it is dramatically easy to forget to check checkbox (how many checkboxes would a woodchuck check?) or to fill some textbox in Interface Builder, especially if you have a rather complicated UI with lots of elements (and this accounts for most software you want to sell). Error messages are as cryptic as the Delphi oracle (with no known reference to a nice RAD tool and to the most popular commercial DBMS in the world). Cryptic means that most of the time you have no way to understand which UI element wasn't properly connected and generated the error message, you have to browse the bindings of all the widgets. You probably have to set some debugging option (if so I missed the paragraph where this was explained).

Key Value Validation transcends my understanding. As far as I can see it's dramatically easy to do things wrong and put the system in an inconsistent state. Probably I just did not get the rationale behind it. But... Django seems far easier. Sigh.

Monday, September 1, 2008

I'm Back (Back in Black)

I'm kind afraid the few who read this blog kind of regularly (for pretty wide values of regularly) stopped this despicable practice in the last year, as apparently I stopped writing as well.

This is indeed the bare naked truth. In september I graduated and in the last period I was astonishingly busy (and worried for the results). The results were excellent, but my schedule perseverated in being crowded. I also was thrown out from Google indexing since some nice guy proved that no PHP website can be left unattended for months (and did so filling my articles with invisible links to the worse sites of the web -- or the best ones, depending on your point of view --).

Out of the blue, I decided I could start writing again. And I decided to try the nice MacJournal application whose license I got among the ones in the last MacUpdate Bundle.

The bundle itself was quite unsatisfactory. I don't use most of the applications. I don't like Mellel (and in fact I'm a quite satisfied Nisus Pro user) and I find DEVONagent wonderful and mysterious as well (that implies that I was unsuccessful in making something of it). Some of the other applications are great, though I don't really need them.

For example I'm using 1% of Contactizer Pro capabilities and I think I scribbled somewhere I was to learn to use the program, since it seems extremely useful. I'm also very satisfied by LightZone, since I recently bought a nice reflex and plan to use it a lot. Unfortunately enough, I don't seem to have time to spend sightseeing (and consequently taking pictures) and this is how the story ends. Moreover, I really need two things in an image editing program: something to straighten the horizon and Photoshop ‘patch' tool. Appearently even Gimp has it, but not Pixelmator (nor LightZone, but this is because LZ is a totally different kind of program).

DSC_0351-2008-09-1-05-24.JPG

Moreover, I've got no time to learn LightZone and I'm afraid I'll stick with iPhoto even though it can only save edited images as JPEGs. Which kind of sucks, but it's my fault: I paid for more professional and I don't want to learn how to use them. Besides, the meaning of "more professional software" is still under theological scrutiny.

As a pleasant side effect of the MacUpdate Bundle, I got an enormous discount on software from Koingo Software. This particular discount gives me access to all the applications they created or will create and their updates as well. Librarian Pro is among them.

I love Librarian Pro. I love books and LP seems a great way to keep a catalog. And one day or another, I will put it online. But this is another story.

Going back to MacJournal, it seems an extremely good application. Maybe I will write this blog regularly, after all.

What else? We did Pycon Italy 2008, which was great. And since the blog was not actively maintained, I did not write about it then.

And for those of you curious about my yellow dog... it seems a Leopard ate it. Poor dog! :P

Monday, August 6, 2007

My Yellow Dog ate my Red Hat.

I've always been one of the (not so) few geeks who run Linux on PowerPC.
Sometime ago, Linus himself was one of us, however, it appears that now
he uses a different machine.
Since Apple dropped PPC, the Linux PPC world is quite in turmoil. The architecture is perceived as almost dead. However, new interest comes from the Linux on PS3 projects.
In any case Ubuntu dropped official support for PPC. That was a sad piece of new, since I was quite satisfied with it. I had to recompile the kernel in order to fully support my machine (but this would have been solved in successive releases).
I got back to Debian. I've been a Debian user since Woody, and I liked it ever since. I was a Debian unstable user, and I have always been satisfied with it. However, this time it was different. I've had many more troubles: each upgrade broke something I needed.
I don't know if it's a matter of developers paying more attention to Ubuntu or whatever: the point is that using Debian unstable as a 'reliable' desktop system on power pc seemed quite hard. I don't want to blame Debian developers: it's unstable. No warranties. I used it at my own risk.
Since Debian is unsuitable for my present needs (no hassle, no config, no time), I considered switching Yellow Dog. I know that these days a PPC community mantained version of Ubuntu has been released.
ydl5-2007-08-6-10-27.jpg
I bought a Yellow Dog Enhanced account, since I did want to support their work and I was interested in support, if something was not perferct in the first place. Remember, no time.
I installed the distribution from the DVD. My hardware was entirely recognized correctly. From the soundcard to the backlit keyboard. My video card should also work with dual head, though I haven't tried it yet. YD comes with a nice GUI to do this.
The only thing that was not working was the airport card. I just had to get the fwcutter and extract the firmware. Then it worked. Moreover, the network applet that stays in the notification area works great. I don't know why, but in Debian and Ubuntu for some reasons it did not work properly (in Ubuntu from a certain moment the whole network-manager stopped working). I did not investigate as I needed less time to write a couple of shell scripts to configure the network interfaces when I needed to switch.
I have always been skeptical about rpm-based distros. Once I used SuSE, but after using Debian I got somewhat convinced of the superiority of the Debian packages. More accurate studies on rpm done recently seem to go in another direction: it was not that deb is better than rpm. It is just that deb repositories were maintained more carefully.
YellowDog repositories are maintained quite carefully. However, there is not a lot of software. I suppose something like 1000 packages (Debian has got ten times that). So I had to learn how to cook my own rpms or simply build software from sources and install it with make install. This is probably the major drawback. However, I'm pretty satisfied with Yellow Dog.

Sunday, July 29, 2007

About autotools, YellowDog, Prolog and Xpm

A few days ago, I switched to Yellow Dog for my powerbook.

I'm very satisfied with the hardware support. It's the first distro that supported my backlit keyboard from the beginning. However, it lacks a lot of software packages. Most of them can be taken from Fedora PPC (it's advised to use those of Fedora Core 5 or). However, other must be compiled.

For example, I had to compile swi-prolog, since the software I'm working on at the moment is written in Prolog. Swi Prolog itself was easy to install. I compiled it and I had it working in a few minutes. However, I was unable to compile XPCE. While I do not use the library itself, I find it useful sometimes to use gtrace or the 'graphic' help.

The problem reported was that Xpm was not found. However, I installed both libxpm and its development files. The ./configure script reported that it was not able to link against libXpm.

I first tried manually linking and it worked, so I had a look at the log. In fact it wasn't libxpm fault. The test program tried to link both libxpm and libxt, and the latter failed. Amazingly, the configure script did not check for errors in linking libxt, so the erroro reported was totally misleading.

The problem was that there was no libXt.so, but only libXt.so.6. I had to manually create the symbolic link.

Eventually, I bumped into another error (this time during 'make'). The culprit was once again Xt: it seemed that some of its 'standard' header files were missing. I found a fedora 5 devel package that fixed that and I was able to compile xpce.

Quite unfortunately, I can't use it now. Another bug in the installation of xorg conjures against me. This bug can be seen using a Tkinter canvas too. The problem is that 'names' of colors are not found (probably because rgb.txt is in the wrong place). Xpce fails and so does many stuff with Tkinter. I don't know where rgb.txt should be. I tried to put it in standard places, but up to now the server does not find it. The problem is that I have to restart the server each time (and since sometimes this hangs the whole system, I have to reboot, and Red Hat derived distros have slow boots.)

Sunday, July 1, 2007

FAQ it.comp.lang.c++

Queste sono le FAQ del newsgroup italiano dedicato a C++.Mi sono reso conto che in effetti non è facilissimo trovarle,ache se contengono molte informazioni che risparmierebberodomande banali sul newsgroup.

Per cui, nel caso, le linko.Link.

Wednesday, April 25, 2007

Illuminated keyboard on PowerBook G4 and Linux.

An image is worth a thousand words.

It was a matter of mod-probing i2c-dev.

It is a custom Linux 2.6.20 Kernel on Debian Unstable. Cool!

Thursday, March 22, 2007

Execute saved Synaptic markings

It happens quite often that I use synaptic to manage packages on my debian.However, sometime I save the markings in order to perform the installations another time.For example I need to apt-get something quickly without waiting for the whole thing to be downloaded and installed.

The standard procedure would be running synaptic again and then loading the markings.However, in this cases I don't feel like I need to start the whole synaptic thing. I'd prefer a small command line utility that processes the saved markings.

I wrote one. It is very simple. It uses sudo, so every now and then it asks the password.Of course one could do a better job, but I had not time to do something better.

#!/usr/bin/env ruby

args = $*
if args.size == 0
    puts "You should provide a file to process"
    exit 0
end

dict = Hash.new
File.open(args[0]) do |f|
    f.each_line do |line|
        key, action = *line.split
        dict[key] = action
    end
end

# sudo apt-get #{v} #{k}

dict.each do |k, v|
    exec("sudo apt-get -y #{v} #{k}") if fork.nil?
    Process.wait
end

Wednesday, March 21, 2007

Scripting languages

What is a scripting language?

From Wikipedia we read that:

Scripting languages (commonly called scripting programming languages or script languages) are computer programming languages that are typically interpreted and can be typed directly from a keyboard. Thus, scripts are often distinguished from programs, because programs are converted permanently into binary executable files (i.e., zeros and ones) before they are run. Scripts remain in their original form and are interpreted command-by-command each time they are run. Scripts were created to shorten the traditional edit-compile-link-run process.

Of course any self respecting computer scientist knows that definition is meaningless, because a language is a mathematical constructand is not tied to its implementation. You can write a C interpreter, for example (and there are some). You can also write a compiler for any 'interpreted language' (of course the term 'interpreted language is also meaningless). And there are theoretical constructs (Futamura projections) that given any interpreter are able to build a compiler from it (you could implement them even in practice, though it would be terribly inefficient).

However, any other definition would be misleading as well: if you define a scripting language as a language you can use to "script" (as in "bash script"), then you've got definition that's even more stupid. bash is a scripting language, and so it is Python. However, if someone writes an application that is scripted in C, C becomes a 'scripting language').

Both definitions have an additional problem: scripting languages are considered somewhat inferior to 'non-scripting languages'. Some even use the term 'true programming languages' (and this 'true programming languages' are usually considered to be C and C++, for example).

Lisp, Haskell, OCaml, Prolog

In this dissertation on 'scripting languages', Lisp is quite emblematic. Lisp can be compiled (there are some Lisp compilers around). But Lisp can also be interpreted. This is one of the most widespread Lisp environments (and it is an interpreter). Moreover, in Emacs you can just run some Lisp snippets. And Emacs itself is scripted in Lisp (thus Lisp would be a scripting language according to the second definition). However, no one can assert that it is not a 'true' programming language. Emacs itself is a beautiful (and complex) piece of software, and a lot of 'real' (and extremely difficult) stuff in the AI field has been written in Lisp.

Haskell can be another example. Hugs is an interpreter, ghc is both an interpreter and a compiler. And Haskell is even statically typed (so you see, being dynamic is not necessary ). The very same applies for OCaml or Prolog. And all thislanguages have been used by the most theory-oriented computer scientist toimplement real programs.

I suppose nobody would say that Lisp or Haskell are 'scripting languages' (even if according to the definitions they are -- Haskell is used in many configuration tools by Linspire programmers).

Bash, Perl, Python, Ruby.

All this languages have been labeled as 'scripting languages'. And in fact according to definitions, they are. However, they are very different languages.

Bash is a very simple language designed to do simple things. Unix system administrators used it intensively (along with awk and sed and other utilities) to automate many repetitive tasks. Although this is surely 'programming', in some sense it's different from programming an application from scratch. Some even consider it a 'lower level' kind of programming (and surely we must recognize that skills involved in writing a boot script are different from skills used to write a compiler)

Perl was born in this environment: its goal was textual manipulations and interactions between processes in a system. It is a nicer alternative to bash + awk in many situations. Later it has been added a fully fledged object model, but in the while it has been used to write very complex applications that go outside the 'lower level programming domain' that is usually associated with 'scripting'. Even though I don't like Perl anymore, it is a general purpose language, with the same dignity of C or C++.

The 'scripting language' monicker is not fitting anymore. And it is even less fitting for Python. Python has been an object oriented programming language from the beginning. Good software engineering practices have always been employed. However, many consider it just another scripting language. And of course Python makes a great scripting language.

The domains in which Python excels are the same in which Java is used, for example. However, Python can be used for scripting, too. That is to say... some (and I'd be tempted to say 'most' ) 'scripting languages' can be used both as general purpose languages and automation/scripting.

The reason why they can be used for automation/scripting and that they are easier to use and we can write programs faster. The development cycle is faster, too. And to me, they all seem good properties.

I think that the very same features that make Python (or Ruby) great for scripting, make it even greater for general purpose programming. That is to say we should consider a 'scripting language' not a poorer language, but a better one (yeah, of course this is exaggerated, since there are languages suited for scripting that are not suited for general purpose programming -- AppleScript and bash, for example).

Emacs and emacsclient (Ruby script to call them both)

I usually call one single emacs server (I've got (server-start) at the very beginning of my .emacs), then connect to it with some emacsclient.

Unfortunately enough emacsclient just quits if there is no active emacs server.

I need a process that tries to run emacsclient: if there is no active server, it runs emacs.Moreover, emacsclient has a -n switch that makes it return ASAP, so the terminal is available for more commands.emacs has not such a switch, but that behaviour is the one I want.

So I decided to write a small ruby script that does just this:
  1. Tries to run emacsclient with the -n option.
  2. If it succeeds, we are done. Otherwise we run Emacs doing some standard posix process manipulation in order to return to the shell as soon as possible.

This is the script:

#!/usr/bin/env ruby

fork do
    exec('emacsclient', '-n', *$*)
end

Process.wait
    if $?.exitstatus != 0
        fork do
        Process.setsid
        Signal.trap('HUP', 'SIG_IGN')
        exec('emacs', *$*) if fork.nil?
        exit!(0)
    end
    
    Process.wait
end