Io e Netbeans

November 20, 2005

Per una serie di casi del destino anche il sottoscritto si è ritrovato costretto ad usare Java. D’altra parte era stato ampiamente previsto, e la cosa non mi ha trovato più impreparato di un tot.

Complessivamente mi sono assuefatto all’ambiente. Il linguaggio è abbastanza “stupido”, ma va bene nella maggioranza dei casi. Certo, avendo dei templates decorosi… la mia opinione sui generics di Java non è certo delle migliori.

D’altra parte la piattaforma regge bene. La libreria continua ad essere ben fatta. E complessivamente anche Swing mi piace abbastanza. Non è troppo cervellotica da usare (mai usato Carbon?), e si comporta entro grandi linee bene ovunque (mai provato Tk?).

Proprio riguardo alle GUI si possono apprezzare alcune dei maggiori vantaggi di NetBeans 5. Il nuovo GUI editor, Matisse, è semplicemente favoloso. Sicuramente sta al pari con InterfaceBuilder dei Developer’s Tools di Apple, forse è anche migliore.

Matisse

Qui un piccolo screenshot di Matisse. Fare le GUI è davvero semplice.
Si tratta di disporre i controlli all’interno della finestra. NetBeans automaticamente mostra delle guide, per disporli “bene” in relazione fra loro.
Per esempio NetBeans tenterà di suggerire che tre campi di testo uno sopra l’altro finiranno allineati e così via.

L’utente poi potrà specificare quali controlli vorrà che si ridimensionino con la finestra e quali no, e quali vuole che siano “ancorati” ad un qualche bordo, in modo che si spostino con la finestra stessa.

Anche se la spiegazione non rende l’idea, posso garantire che il tutto ora è davvero molto semplice e comodo, niente a che fare con il famoso GridBagLayout (in pratica i Layout sono caduti in disuso, a quanto pare)

Tutte le proprietà dei controlli, codice da inserire prima o dopo per inizializzarli e la scelta del costruttore possono essere fatti direttamente da Matisse.

Refactoring

Finalmente anche NetBeans ha aggiunto le funzioni di refactoring che eravamo soliti trovare su Eclipse. Non c’è molto da aggiungere, fanno il loro dovere, punto e basta.

Altro…

Altro non ho ancora avuto il modo di provarlo. In effetti Java continua a non essere il mio ambiente naturale, per quanto mi stia sforzando di affrontarlo con mente aperta. Sono in grado di vederne i pregi, ma mi balzano anche all’occhio i difetti.

Allo stesso modo devo dire di NetBeans che è davvero un bel progetto, un IDE ben fatto di cui più lo si usa, più si scoprono utili funzioni e interessanti scorciatoie.

Purtroppo è terribilmente mastodontico. Sembra di manovrare un camion, è lento e spesso si ferma a pensare davvero troppo. A causa dei limiti di Java diventa sostanzialmente impensabile scrivere il codice semplicemente con un editor di testi, ma la tentazione è forte. TextMate è maneggevole, snello, veloce. Risponde ai miei comandi.

NetBeans ha i suoi tempi. La cosa che continua a torturarmi è… ma abbiamo davvero bisogno di una piattaforma che ha bisogno di centinaia di megabyte di IDE per sopperire alle sue mancanze? A quanto pare si, ma c’è qualcosa che mi suggerisce all’orecchio che mi hanno fregato (con questo Matisse è comunque fantastico, e mi piacerebbe averlo a disposizione anche per le mie GUI Python, Swing è una libreria abbastanza buona — specie adesso che usa il freeform layoyt ).

Attenzione!

Se usate NetBeans 5 sotto MacOS, ricordatevi di copiare il jar org-jdesktop-layout.jar dentro il classpath standard della vostra versione di Java, altrimenti non riuscirete a combinare nulla.


First thoughts about Java

October 31, 2005

Something does not work. In my head, I mean. If you know me, you should be aware I’m pretty skeptical about Java. Let’s say that the first thing I do when I hear someone talking about Java is: Hey, there is Python out there, that is much better.

Still I heard much talking about Java Tiger, that is to say Java 5 (or 1.5, I still haven’t figured out which is the correct version number). There are *generics* (that is to say “templates” if you know C++). And autoboxing. These were the two single things I hated most in Java. Still I won’t talk about it here, there is plenty of places on the Internet when someone says that a strongly typed language that forces you to cast everytime you have to use a resizeable collection simply sucks.

I’ve quite changed my mind on this, but let’s go further. With generics it is not necessary anymore.
And with autoboxing you have not to change integer types back and forth from Integer objects.

So, I bought Core Java Volume I, written by Horstmann and Cornell. In fact I find it a well made book. It’s clear. And complete. Probably it’s not meant for a newbie. But I already new some Java and am quite skilled in C++ and Python, at least. I’m not new to theoretical object oriented programming (and for this I have to thank my university teachers) and have made many practical stuff, in very different environments, ranging from QT and Python or Cocoa to old C version GTK 1.

I thought I’d read it in some time, just to know what was happening out there in the Java world. Well. I was impressed. Java 1.5 is much better than Java 1.3. Its standard library is fabolous (something I knew even if not believed). And programming Java is not bad.

It has faults. And that is something that Core Java authors do not fear to stress. I find it really honest. It’s not a fan book. They like Java, but they are able to show its weaknesses.

This morning I bought Core Java Volume II. There are many things to learn… it’s really interesting. Even if I tend not to program cross platform anymore (thanks to Cocoa) I occasionally need some crossplatform environment.
QT 4 is giving me some troubles, and I think I could give Java a try… well, I won’t say more. ☺

And, oh… one of the first thing I chose to develop is a small plotting applet (which could be extended, if I have time to finish it and to make code readable). And I chose not to use 1.5 features, to let more people use it. Well… in fact a part from a pair of crappy hacks I had to do since it’s not as dynamic as I liked and I could not use generics, it is not that bad. Oh, the code I’m talking about is this:

public void stateChanged(ChangeEvent event){
    JComponent source = (JComponent)event.getSource();
    if(source.getClass() == spinner.getClass()){
        /* wow... heavycode! */
        newValue = ((Double)((JSpinner)source).getValue()).doubleValue();
        newValue *= factor;
        slider.setValue((int)newValue);
    } else if (source.getClass() == slider.getClass()){
        /* wow... heavycode! */
        newValue = ((JSlider)source).getValue();
        newValue /= factor;
        spinner.setValue(new Double(newValue));
    }
    firePropertyChangeEvent(
            new PropertyChangeEvent(this, "syncChange", new Double(0.), 
                    new Double(newValue) ));
}

Probably there is a javish cleaner solution. But in Python it would have been

def stateChanged(event):
    source = event.getSource()
    # source.factor is appended to each source before passing it
    # and can be > 1 or