Sunday, November 28, 2010

Revenge of Smalltalk

(Joke inside)

In Paul Graham's essay Revenge of the Nerds (Read it, good ideas there):

Appendix: Power

As an illustration of what I mean about the relative power of programming languages, consider the following problem. We want to write a function that generates accumulators-- a function that takes a number n, and returns a function that takes another number i and returns n incremented by i.

(That's incremented by, not plus. An accumulator has to accumulate.)

In Common Lisp this would be


(defun foo (n)
  (lambda (i) (incf n i)))


In Smalltalk the code is slightly longer than in Lisp:


foo: n                              
  |s|                      
  s := n.                          
  ^[:i| s := s+i. ]

because although in general lexical variables work, you can't do an assignment to a parameter, so you have to create a new variable s.



Well, the Lisp code has 34 significant characters while the Smalltalk code has only 25 significant characters (we can remove the last dot). So the Smalltalk code is 26% shorter than the Lisp code :)


  • Perl example: 32 characters
  • Javascript example: 46 characters
  • Python example: 54 characters
Yeah, Smalltalk is really powerful ;P


Update:
Looking at Parser code we can easily remove the temp. variable limitation and write:
foo: n               
  ^[:i| n := n+i]

So
  • One power of Smalltalk is to be able to change the system.
  • 17 significant characters: Smalltalk 100% more powerful than Lisp :D
  • (still a joke - but ....)


Why this design decision ? Some explanation from Nicolas and Adrian.

Thursday, October 28, 2010

Three views of OO Programming

By Ralph Johnson, quoted in The Myths of Object-Orientation p.624:


I explain three views of OO programming. The Scandinavian view is that an OO system is one whose creators realise that programming is modelling. The mystical view is that an OO system is one that is built out of objects that communicate by sending messages to each other, and computation is the messages flying from object to object. The software engineering view is that an OO system is one that supports data abstrac- tion, polymorphism by late-binding of function calls, and inheritance.


It seems that in (French) schools we learn the engineering view. Then with experience we can agree on the mystical view. With Smalltalk I think I now understand the Scandinavian view.


Oscar Nierstrasz have written in Ten Things I Hate About OOP:

For me the point of OOP is that it isn’t a paradigm like procedural, logic or functional programming. Instead, OOP says “for every problem you should design your own paradigm”. In other words, the OO paradigm really is: Programming is Modeling

Friday, June 18, 2010

Autotest for Pharo


I've started a new little project. Autotest is a live testing tool (similar to Ruby Autotest, but the Smalltalk way, more dynamic).

Autotest automatically runs tests related to the method you edit. Screencast to see it in action: 





Autotest uses the following heuristics to find the tests to run:
- if the method is a test, runs it
- it the method is a test setUp or tearDown, run all the tests of the TestCase
- else find all senders which are tests in the same package and runs them (it detects different packages that are related, for example ProfStef-Core and ProfStef-Test)

To activate the Autotest dashboard:
- open the settings browser
- go under System
- check "Show Autotest Dashboard" option

To load it:

Gofer new
squeaksource: 'Autotest';
package: 'Autotest';
load

HelpSystem book included.

Saturday, May 15, 2010

GNU/Linux install party des Savoie

Une grande Install Party des Savoie aura lieu le samedi 22 mai et - évènement unique - simultanément sur Chambéry (MJC Résidence Escoffier, 379 fbg Montmélian) et sur Annecy (CDDP, 2 rue des Aravis) de 10h à 17h (les associations seront sur place 1 heure avant).

La distribution retenue pour une installation grand public est Ubuntu 10.04 'Lucid Lynx' LTS, et ses dérivés au cas où matériel le nécessiterai.

Chambéry et Annecy seront reliées en vidéo via EKIGA (sous réserve d'essais préalables concluants).

L'annonce de l'Install-Party est diffusée sur les radio locales (France Bleu Pays de Savoie, ODS Radio, Montagne FM) et est relayée dans la presse par le Dauphiné Libéré. Des affiches sont également diffusées dans les villes.

Tuesday, April 20, 2010

easy_squeakvm on github

I've created my first repository on github. So easy!

easy_squeakvm is used to build the squeak vm from scratch on Linux in one command.
To build the VM, just get the the script and execute

./easy_squeakvm.sh


This will

  • checkout squeakvm sources from svn repository
  • download PharoCore image
  • load VMMaker into PharoCore
  • generate the interpreter
  • build the VM
  • put binaries in out/squeakvm, ready to use


I was tired of typing the same commands over and over :)

http://github.com/lolgzs/easy_squeakvm

Wednesday, March 10, 2010

How I build squeak vm on (Arch)Linux

I write this post as a memento for me. I will appreciate some feedback on building the VM on other Linux distro.

1. Prepare a working directory

All the work will take place in ~/squeakvm (/home/lol/squeakvm on my machine):


mkdir ~/squeakvm
cd ~/squeakvm


2. Get squeak-vm source

The easiest part. The VM source code tarball can be found on http://www.squeakvm.org/unix/. At the time of writing, the last stable version is 3.11-3.2135. Go and get it:


wget http://www.squeakvm.org/unix/release/Squeak-3.11.3.2135-src.tar.gz
tar -xvzf Squeak-3.11.3.2135-src.tar.gz


3. Load VMMaker tool

For more explanations on why VMMaker is needed and how it works, here is a good overview.

To generate the source code for your own VM, you need a running Pharo image. Here I use a fresh Pharo 1.0-10508 rc2 image from Pharo website.

Open your image, then load VMMaker by evaluating this in a Workspace:

Gofer new
 squeaksource: 'MetacelloRepository';
 package: 'ConfigurationOfVMMaker';
 load.
 
(Smalltalk at:#ConfigurationOfVMMaker) project lastVersion load.




4. Load FT2Plugin

UPDATE: Should not be necessary now. See Javier's comment.

To display anti-aliased font of Pharo images, you need the FT2Plugin. To load it:

MCHttpRepository
 location:'http://www.squeaksource.com/FreeTypePlus'
 user: ''
 password: ''.

MCHttpRepository
 location: 'http://source.impara.de/freetype'
 user: ''
 password: ''.


5. Configure VMMaker and generate the VM source

Now you can open VMMakerTool:

VMMakerTool openInWorld


In the Path to platforms field put the path to the extracted Squeak VM tarball: ~/squeakvm/Squeak-3.11.3.2135-src.

Then right-click on one of the plugins pane and select make all external for a simple configuration.



Note you can have a description of each plugin by reading the class comment.Classes are part of VMMaker-Plugins category.

In path to generated source select a directory where the VM source will be written. Here ~/squeakvm/src32.

The VMMakerTool window should look like this:



Then click on the Entire button (top-left of window). Wait a moment, pray, and the code should be generated.

Finally, I replace the original VM source with the generated one.

rm -rf ~/squeakvm/Squeak-3.11.3.2135-src/unix/src
cp -a ~/squeakvm/src32 ~/squeakvm/Squeak-3.11.3.2135-src/unix/src


Note: theorically this should not be necessary as the configure script accepts an option to specify the source directory path, but it doesn't seem to work.

6. Build the VM

First create a directory for the build and go in:

mkdir ~/squeakvm/Squeak-3.11.3.2135-src/build
cd ~/squeakvm/Squeak-3.11.3.2135-src/build


Then run the configure script

../unix/cmake/configure 


First problem. I have this error:

CMake Warning (dev) in 
/home/lol/squeakvm/Squeak-3.11.3.2135-src/build/=/CMakeLists.txt:
  Syntax error in cmake code when parsing string

    ${=_link_directories}

  syntax error, unexpected cal_SYMBOL, expecting } (21)


Thanks to this mail there's a patch to correct it.


cd ~/squeakvm/Squeak-3.11.3.2135-src/unix/cmake/
wget http://lolgzs.free.fr/pharo/Plugins.cmake.patch
patch -p0 < Plugins.cmake.patch
Then clean and run the configure script again
cd ~/squeakvm/Squeak-3.11.3.2135-src/build
rm -rf *
../unix/cmake/configure 
You should have the Makefile now. Run make:
make
Then another problem as libfreetype (needed by FT2Plugin) is not found. To correct it, create config.cmake for FT2Plugin this way:
mkdir ~/squeakvm/Squeak-3.11.3.2135-src/unix/plugins/FT2Plugin/
echo "PLUGIN_FIND_LIBRARY(FT2 freetype)" > 
    ~/squeakvm/Squeak-3.11.3.2135-src/unix/plugins/FT2Plugin/config.cmake
More informations on this error here.

UPDATE: See Javier's comment.


Clean and run make again:
make clean
make
Then install:
sudo make install
7. Conclusion
The process is not so easy. To help I put all the squeakvm directory (with sources, pharo image with vmmaker) on http://lolgzs.free.fr/pharo/squeakvm.tar.gz

UPDATE: Good post for MacOSX

Thursday, February 25, 2010

Pharo & Smalltalk party

J'organise avec quelques confrères une "Pharo & Smalltalk party", dans l'objectif de faire découvrir et partager les expériences du développement Pharo et Smalltalk.

Que vous soyez développeur curieux ou Smalltalker expérimenté, rendez-vous le Samedi 20 Mars de 14h à 18h dans les locaux de Félix Création à Cran-Gévrier (bassin Annécien).

Voici le plan du lieu de rendez-vous.

Saturday, January 30, 2010

Seaside-Hosting compatible Pharo

L'hébergeur gratuit (pour des applications non-commerciales) Seaside-Hosting accepte maintenant les images Pharo ! J'en ai donc profité pour déployer ma première image Seaside... et c'est d'une simplicité étonnante.

Il suffit juste de créer un compte, uploader son image, clicker sur Start et c'est fini. Cool.

J'ai donc mis en ligne une image avec SimpleWebDoc: http://magaloma.seasidehosting.st/

Friday, January 29, 2010

Screencast sous Linux

Après avoir essayé pas mal d'outils disponibles sous Linux pour réaliser des screencasts et alimenter Pharocasts, voici le contenu de ma boîte à outils du moment.

Pour enregistrer j'utilise Xvidcap. On définit une zone de capture et le mode multi-frame permet de générer la vidéo à la volée. Ma zone de capture est en 800x600, éviter les résolutions exotiques (garder du 4:3 ou 16:9). Dans le cas contraire on risque une perte importante de la qualité par les encodeurs et les sites de publication en ligne.
J'enregistre en avi/mpeg4.

Pour couper les scènes, j'aime bien Avidemux. Interfaces texte, GTK et Qt disponibles. Il s'appuie sur son propre fork de FFmpeg pour l'encodage et c'est très rapide si vous gardez le même format que la vidéo originale.

Pour encapsuler au format mov, car les possesseurs d'anciennes versions de MacOSX ont des soucis avec l'avi, j'utilise la commande suivante (qui ne doit pas être la meilleure, vu que le fichier généré double de taille pour une qualité moindre):
ffmpeg -i mavideo.mpeg -b 500k mavideo.mov

Je suis toujours à la recherche d'un outil sympa pour le montage, type Kdenlive, mais je n'ai encore rien trouvé qui me plaise vraiment.

Pour publier, entre Vimeo, YouTube et DailyMotion, c'est Vimeo que je préfère pour la qualité de la vidéo.

Friday, January 22, 2010

ProfStef news

ProfStef est inclut dans le Metacello Repository. Metacello permet de spécifier les dépendances entre packages.

Cela signifie qu'il est maintenant assez simple de charger ProfStef et ses dépendances dans Pharo via Loader (l'équivalent d'apt-get pour Pharo):
Gofer new
        squeaksource: 'Loader';
        package: 'Loader';
        load.

Loader new load: 'ProfStef'.


Il est maintenant possible de créer son propre tutorial intéractif pour ProfStef. Comment ? Il y a un tutorial pour ça :).

Dans un Workspace, évaluez:
ProfStef goOn: HowToMakeYourOwnTutorial.

Monday, January 18, 2010

Smalltalk interactive tutorial

ProfStef est un tutorial intéractif sur Smalltalk (un peu inspiré de Try Ruby).
L'objectif est d'apprendre les bases du langage Smalltalk de manière ludique.

Pour charger ProfStef dans votre image, évaluez le code suivant dans un Workspace:

Gofer new
    squeaksource: 'ProfStef';
    package: 'ProfStef';
    load.



Sunday, January 10, 2010

Blog dédié à Pharo

Je viens de mettre en ligne un blog qui me servira à publier et pointer des tutoriels vidéo sur Pharo. Ça s'appelle Pharocasts et c'est ici: http://pharocasts.blogspot.com/

Friday, January 8, 2010

GUI et Pharo

J'ai fait une vidéo sur Pharo montrant les techniques de base pour disposer des éléments dans une fenêtre et répondre aux clics sur les boutons.



Voici un des exemples de code de la vidéo:

|aWindow aPanel buttonPanel|

aWindow := SystemWindow labelled: 'My first window'.

aPanel := PluggablePanelMorph new.
aWindow addMorph: aPanel fullFrame: (
    LayoutFrame
        fractions: (0@0 corner: 1@1)
        offsets: (0@0 corner: 0@50 negated)).
aPanel color: (Color blue).

buttonPanel := PluggablePanelMorph new.
aWindow addMorph: buttonPanel fullFrame: ( 
    LayoutFrame
        fractions: (0@0.99 corner: 1@1)
        offsets: (0@50 negated corner: 0@0)).
buttonPanel  color: (Color green).


#(one two three) do: [:label| |aButton| 
 aButton := PluggableButtonMorph new label: label; yourself.
 buttonPanel addMorph: aButton fullFrame: nil.
].


aWindow openInWorld.

Monday, January 4, 2010

Ruby 1.9, SQLite et UTF-8

Comme abordé précédemment dans le billet Migrer vers Ruby 1.9, le gem sqlite3-ruby actuel (version 1.2.5) ne fonctionne pas vraiment avec des données UTF-8.

Un fork de la version 1.2.4 qui corrige ces problèmes est disponible ici: http://github.com/qoobaa/sqlite3-ruby.

Pour l'installer, clonez d'abord le repository avec git:

git clone git://github.com/qoobaa/sqlite3-ruby.git

puis allez dans le répertoire créé et construisez le gem:

cd sqlite3-ruby
gem build sqlite3-ruby.gemspec

si tout fonctionne vous avez maintenant le gem sqlite3-ruby-1.2.6.gem. Installez-le:

gem install sqlite3-ruby-1.2.6.gem 

C'est tout pour Linux, sous Windows cela se complique étant donné que le gem intègre une extension C qu'il faut linker avec SQLite. Vous devriez donc tomber sur l'erreur:

Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3-ruby:
        ERROR: Failed to build gem native extension.

ou si vous avec déjà installé le devkit:

checking for sqlite3.h... no

La suite nécessite d'avoir le devkit d'installé sur votre machine (voir http://rubyinstaller.org/download.html et http://wiki.github.com/oneclick/rubyinstaller/development-kit ).

Créez un répertoire qui contiendra les fichiers nécessaires à la compilation de l'extension, à savoir sqlite3.h (dans le sous-répertoire include) et sqlite3.dll (dans le sous-répertoire lib). Par exemple:

C:\Ruby19\sqlite3
            |- include
            |   |- sqlite3.h
            |- lib
                |- sqlite3.dll 

Le fichier sqlite3.h se trouve dans les sources de SQLite: http://www.sqlite.org/sqlite-amalgamation-3_6_21.zip

Le fichier sqlite3.dll se trouve dans la distribution binaire pour Windows: http://www.sqlite.org/sqlitedll-3_6_22.zip

Modifiez ensuite la configuration de la compilation de l'extension pour inclure le répertoire créé. Ouvrez le fichier ext/sqlite3_api/extconf.rb des sources du gem et ajoutez la ligne suivante:

dir_config("sqlite3", "C:\\Ruby19\\sqlite3")

Vous pouvez maintenant regénérer le gem et l'installer:

gem build sqlite3-ruby.gemspec
gem install sqlite3-ruby-1.2.6.gem