Sunday, November 19, 2006

Adding scrolling to Emacs...

Easy...
;; mouse-wheel: scroll
(global-set-key [mouse-4] 'scroll-down)
(global-set-key [mouse-5] 'scroll-up)
I found a lot of posts about this, but none worked for me. I just took some pieces of information here and there and I came up with this (that works for me).
Emacs 21.4 on Ubuntu PPC.

Wednesday, November 15, 2006

Servoy Hu? 2

Today, while checking my gmail account I read an ad about Servoy being an alternative to Ruby and Rails

Actually, I wanted to check out what was that. I thought about some crappy PHP framework that pretended to do what Rails just cloning its structure, but without Ruby power

In the homepage the first thing you learn about Servoy is that Ruby syntax is complex and that Rails has limited capabilities. Further analisys makes me think it's a Java based environment scripted in Javascript. Basically they are asserting that Javascript syntax is clearer than Ruby one (which is debatable) and that a RAD like thing built on Java is less limited than Rails. Note that Servoy is not Java: it is something built on Java (so I don't expect it to be as powerful as Java, or it would be as complex as well).I'm not against RAD or 'easy' environments. I just find ridiculous when they say that Rails is limited (that is false) and that a closed component system is more complete.

Moreover, I don't know anyone using this Servoy. I haven't read about it on tech magazines, my fellow developers haven't heard about it either. My opinion is that it's a small environment tool that uses Rails popularity (as a comparison) to convince people to pay them for something they could have done easier in Rails.

The same conclusions have been made by this blogger

Difference Lists for visiting trees (Prolog)

This is are some (simple) exercises in Prolog using difference lists.They should be correct, but I have to say I'm a beginner Prolog programmer... so...

inorder_dl(tree(X, L, R), Xs-Ys) :- 
        inorder_dl(L, Xs-[X|Zs]), 
        inorder_dl(R, Zs-Ys). 
inorder_dl(void, Xs-Xs). 
preorder_dl(tree(X, L, R), [X|Xs]-Ys) :- 
        preorder_dl(L, Xs-Zs), 
        preorder_dl(R, Zs-Ys). 
preorder_dl(void, Xs-Xs). 
postorder_dl(tree(X, L, R), Xs-Zs) :- 
        postorder_dl(R, Ys-[X|Zs]), 
        postorder_dl(L, Xs-Ys). 
postorder_dl(void, Xs-Xs). 

Sunday, November 12, 2006

Difference lists

Well.... I just discovered this new wonderful world. I really like them a lot.

I suspect I'm getting a little bit more into Prolog programming. However, I still find more exciting Haskell lazy programming. But I have to admit that my scarce love for Prolog it's more a problem of (my) ignorance.

A couple of days ago my Programming Language teacher built under my eyes a small compiler and and interpreter for arithmetic expressions in less than 10 minutes (while explaining Prolog to my fellow students). In fact he used extensively Prolog unification mechanism (since the arithmetic expressions he was compiling were also Prolog terms).

However, thanks to DCG grammars building a parser is also quite easy.

In fact I'm falling in love with declarative programming. I definitely start liking declarative languages like Haskell (functional) or Prolog (logic) a lot more than classical programming languages.

In fact I still love Python and Ruby. I like C (and  we *need* C). I also like compiled languages like ObjectiveC (waiting for Objective C 2.0...) and D. After all, I like C++ too. But what is the point of Java? I definitely don't understand. It's dramatically uninteresting.

Ubuntu on Powerbook G4 (Trackpad Synaptics Two finger scroll multibutton emulation)

After such a long title (mainly for tagging reasons) I suppose I have to write a long article.
One of the things I didn't really like about Ubuntu standard configuration, was the track-pad.
In fact, although correctly recognized (using the synaptics Xorg driver) default was really poor: the mouse moved so slowly it was unusable. For the first hours you can use an external three button mouse and live happily. However, I wanted to fix my track-pad. I found some articles on the net.
There are plenty of blog posts on this subject and if you use synaptics as a key you find even more. This is a good starting point. However, I strongly advise to read synaptics manual (man synaptics). It is synaptics with a trailing s, not synaptic, the package manager.
If you read the manual, you get a lot of informations about how to configure your trackpad. You also have some GUI configurators (gsynaptics, ksynaptics, qsynaptics). They offer less
Options (but are easier to use).
While I was able to set tracking speed and acceleration correctly (mainly using the link I posted) I'm still somewhat unsatisfied with scrolling facilities. Two finger scroll does not seem to work, and edge scrolling (using the edges of the trackpad to scroll) is far from perfect.
The best thing is that I can use tapping to emulate buttons. Tapping in the right upper corner is a middle click and right lower a right click. Now I can use the powerbook without an external mouse.
I'm to post my xorg.conf. And remember... using 'radeon' codecs instead of 'ati' should be a good thing (I've not investigated, I only read it somewhere)
My XOrg:
# /etc/X11/xorg.conf (xorg X Window System server configuration file) 
# 
# This file was generated by dexconf, the Debian X Configuration tool, using 
# values from the debconf database. 
# 
# Edit this file with caution, and see the /etc/X11/xorg.conf manual page. 
# (Type "man /etc/X11/xorg.conf" at the shell prompt.) 
# 
# This file is automatically updated on xserver-xorg package upgrades *only* 
# if it has not been modified since the last upgrade of the xserver-xorg 
# package. 
# 
# If you have edited this file but would like it to be automatically updated 
# again, run the following command: 
#   sudo dpkg-reconfigure -phigh xserver-xorg  
Section "Files"         
FontPath        "/usr/share/X11/fonts/misc"         
FontPath        "/usr/share/X11/fonts/cyrillic"         
FontPath        "/usr/share/X11/fonts/100dpi/:unscaled"         
FontPath        "/usr/share/X11/fonts/75dpi/:unscaled"         
FontPath        "/usr/share/X11/fonts/Type1"         
FontPath        "/usr/share/X11/fonts/100dpi"         
FontPath        "/usr/share/X11/fonts/75dpi"         
FontPath        "/usr/share/fonts/X11/misc"         # path to defoma fonts         
FontPath        "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType" 
End
Section "Module"         
        Load        "i2c"         
        Load        "bitmap"         
        Load        "ddc"         
        Load        "dri"         #
        Load        "dbe"         
        Load        "extmod"         
        Load        "freetype"         
        Load        "glx"         
        Load        "int10"         #
        Load        "record"         #
        Load        "v4l"         
        Load        "type1"         
        Load        "vbe" 
End
Section "InputDevice"         
Identifier        "Generic Keyboard"         
Driver                "kbd"         
        Option                "CoreKeyboard"         
        Option                "XkbRules""xorg"         
        Option                "XkbModel""pc105"         
        Option                "XkbLayout""it"         
        Option                "Xkb
        Options""lv3:ralt_switch"         
        Option                "XkbVariant""nodeadkeys" 
End
Section "InputDevice"         
Identifier        "Configured Mouse"         
Driver                "mouse"         
        Option                "Device""/dev/input/mice"         
        Option                "Protocol""ExplorerPS/2"         
        Option                "ZAxisMapping""4 5"         
        Option                "Emulate3Buttons""true" 
End
Section "InputDevice"          
Identifier         "Synaptics Touchpad"          
Driver                 "synaptics"          
        Option                "CorePointer"         
        Option                 "SendCoreEvents""true"          
        Option                 "Device""/dev/psaux"          
        Option                 "Protocol""auto-dev"          
        Option                 "SHMConfig""true"          
        Option                 "MinSpeed""0.30"          
        Option                 "MaxSpeed""1.10"          
        Option                 "EdgeMotionMinSpeed""200"          
        Option                 "EdgeMotionMaxSpeed""200"          
        Option                 "FastTaps""1"          
        Option                 "MaxTapTime""100"          
        Option                 "AccelFactor""0.030"          
        Option                 "HorizScrollDelta""0"          
        Option                "VertTwoFingerScroll""1"         
        Option                "HorizTwoFingerScroll""1"         
        Option                "CircularScrolling""1"         
        Option                "CircScrollTrigger""0"         
        Option                 "FingerLow""1"          
        Option                 "FingerHigh""3"          
        Option                 "LeftEdge""80"          
        Option                 "TopEdge""80"          
        Option                 "RightEdge""850"                  
        Option                 "BottomEdge""560"          
        Option                 "TapButton1""1"  
End
Section "Device"         
Identifier        "ATI Technologies, Inc. RV350 NP [Mobility Radeon 9600/9700 M10/M11]"         
Driver                "radeon"         
BusID                "PCI:0:16:0"         
        Option                "UseFBDev""true"         
End
Section "Monitor"         Identifier        "Generic Monitor"         
        Option                "DPMS" 
End
Section "Screen"         
Identifier        "Default Screen"         
Device                "ATI Technologies, Inc. RV350 NP [Mobility Radeon 9600/9700 M10/M11]"         
Monitor                "Generic Monitor"         
Default
        Depth        24         Sub
Section "Display"                 
        Depth                1                 
        Modes                "1280x786"         
End
Subsection "Display"                 
        Depth                4                 
        Modes                "1280x786"         
End
Subsection "Display"                 
        Depth                8                 
        Modes                "1280x786"         
End
Subsection "Display"                 
        Depth                15                 
        Modes                "1280x786"         
End
Subsection "Display"                 
        Depth                16                 
        Modes                "1280x786"         
End
Subsection "Display"                 
        Depth                24                 
        Modes                "1280x786"         
End 
End
Section "ServerLayout"         
Identifier        "Default Layout"         
Screen                "Default Screen"         
InputDevice        "Generic Keyboard"         
InputDevice        "Synaptics Touchpad"         
InputDevice        "Configured Mouse" 
End
Section "DRI"         
Mode        0666 
End

Ubuntu Edgy 6.10 on Powerbook G4 (general)

Recently I had to install a GNU/Linux system on my notebook. Mywork-group is heavily Linux-based and the software which I'm going touse/extend for my thesis at the moment compiles only on Linux (andprobably on BSD, however, not on MacOS X). Although it's a Prologsoftware some parts are written in C++ and I haven't had time to makeit work on MacOS X. Modifications are quite trivial (it's a matter ofbuilding a dylib). However, I should port the build system to libtoolto make it work on both platforms.

So I decided to install a GNU/Linux distribution. My first choice was Fedora. I'm not particularly fond of RH little sister, but that is the first choice in my team. The PPC version quite sucks. It's not that things do not work: simply it seems just a bit more than a recompilation of the x86 version. For example package pbbuttons (that makes multimedia keys of my pb work, wasn't even on the repositories). It's not that I particularly want to have the buttons working: it is like those who built it never used it. I mean no one ever tried to use it on a notebook? Moreover, it's painfully slow. Six minutes to boot. To start some applications (Emacs, the gnome 'quick' disc burner, etc) it takes minutes. This does not happen on the x86 version.

Partitioning

So I tried Ubuntu 6.10. It's heaven. Everything worked without my intervention. Well, almost everything.

The live CD did not recognize properly my screen. It thought it was a 20000x30000 pixel screen (and of course that was *wrong*): I just had to fix that manually. After booting the live CD, I started the installation. Everything went quite smoothly. Details in next posts

Monday, November 6, 2006

ssh-copy-id

I develop a lot on unix remote machines. I have CVS/SVN accounts and shell access. In fact it's quite tedious to retype the password everytime.
For this reason I started using ssh keys to automate this project. You find a lot of tutorials and informations on this subject, I won't spend more time on this. Basically you have to generate the key and then you have to upload it with scp or similar on the remote machine. However, I find scp syntax quite boring to type... :P
There is a nifty script that does the job for you. You call something like (with you correct remote credentials), it asks you password and you're done.
ssh-copy-id -i ~/.ssh/id_rsa.pub rik0@shell.berlios.de
This script is not in my open-ssh distribution and I had to find it on CVS. The direct download is . However, the script may be upgraded. So if you read this post after some time it has been posted, you may want to find a newer version.

Sunday, November 5, 2006

Cazzeggio (Which file extension are you?)

ogg-2006-11-5-19-21.jpg Which File Extension are You?
You are .ogg Even though many people consider you cool and happening, a lot still find that you're a bit too weird to hang out with.

Agile software development

In some sense I've always done agile programming. I've been in the Python community for a while, and a lot of agile practices are very common. I've done a lot unit testing (even if not really before coding but just afterwards) since the very first years as a developer.

In fact, it was even before my Cocoa and ObjectiveC studies that I learnt about patterns and how to use them. In fact patterns are well known in the ObjectiveC community even among newbie programmers, for exampl Anguish, Buck and Yacktman describes Cocoa showing which patterns are used in the framework and how their names differ from the classical GOF ones.

Of course this is not enough to say "Agile Development": I only had some practices in common with some (most) agile developement methods. I also find quite natural to use tests and code to learn instead of documentation (that is quite common for a lot of open source libraries). What I missed was a theoretical mind-framework.

In some software engineering courses I was introduced to UP. And in fact I could not believe that some people are convinced that it could work well (I agree that you may make it work, however, I think it's a suboptimal way to develop). It is like freezing insects in order to take pictures of them. While frozen, they stand still and are easier to photograph: however, if you want to photograph insects in the wild this just doesn't happen to work.

Some of my concerns were also due to Java and to the quantity of code that is not part of the problem but needs to be written for the way Java works. Python leans quite naturally towards agility: the way components interact, the way you can change things and refactor (even without complex refactoring tools like Eclipse).

After some time I discovered Ruby and got in touch with the Ruby community and all the hype about agile programming.

Eventually, I decided to buy Kent Beck's book on Extreme Programming. However, I wanted a technical book about agile programming. I bought Martin's Agile Software Development

I love them both and I will talk about Beck's book another time.

Agile Software Development is a very interesting book. There is plenty of information on agile techniques, and even if you are not a Java developer (which in some sense is my case, since I rarely work in Java) there are lots of interesting stuff.

You learn how to use test driven development and to think using TDD (there is a big difference between writing tests and thinking in a 'test oriented way'). You learn how to design interfaces while writing tests, and there are examples on software evolution driven by tests.

You definitely have to read the sources (that are really readable and easy to understand): while the explanation is great, the sources would be enough by themselves.

The book also offers a clear explanation of classical principles of object oriented software design (OCP, SRP, LSP, DIP) and packaging (ADP, SDP, SAP). So, you may want to buy this book even if you are not into agile programming and are only interested in a book about Object Oriented software development.

Saturday, November 4, 2006

Closures in Java

This is a hint abount implementing closures in Java. Of course, if you want to do it in an acceptable way, you would create a custom interface that Does The Right Thing™, something like (semi pseudocode)
interface Closure {
    public Object foo(Object bar);
}
However, you can get some ideas from the sequent code

public classStateModifierextendsObject{
    protectedString x ;
    
    public StateModifier() {
        x = "foo";
    }
    
    public ThreadgetThread() {
        finalString y = "yy";
        Thread t = newThread() {
            public voidrun(){
                x = "boo"+ y;
            }
        };
        return t;
    }
    
    public static voidmain(String[] args) {
        StateModifier sm = newStateModifier();
        Thread t1 = sm.getThread();
        System.out.println(sm.x);
        t1.start();
        try {
            t1.join();
        } catch (Exception e){
            // ...
        }
        System.out.println(sm.x);
        System.exit(0);
    }
}