Monday, April 30, 2007

Consensus Reached on Java Closures Proposal

A Consensus about Java Closures has been reached and you can see the JSR proposal here.

"After months of debates, Neal Gafter, co-author of one of the proposals announced on his blog that a consensus was reached, and that the authors of the three proposals all agreed to stand behind one JSR request to add closures to the Java language"

from http://www.artima.com/forums/flat.jsp?forum=276&thread=204090

As I already said on this blog, Closures are blocks of code easily manipulated, e.g, attributing it to variables, and understandable as well. They are like a simplification of inner class, but they're simpler. Below you can see an anonymous inner class:

button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println(e.getSource());
}
});


As you can see, it's a bit complex. Using closures you'll have something like this:

button.addActionPerformed({e => System.out.println(e.getSource())})


More simple, more clean. But the possibilities don't stop here, you'll be able to attribute closures to variables and invoke it too, see:

{int,int=>int} plus = {int x, int y => x+y};
plus.invoke(2, 3);

I got this example from Closures for the Java Programming. There you can see more details about Closures in the Java Programming. Enjoy it.

Wednesday, April 25, 2007

Firefox Pictures

Are you a Firefox Lover like me? So, visit Firefox Pictures site and enjoy it. I recommend the wallpapers section.

Tuesday, April 24, 2007

Ruby is Object Oriented

Answering to requests of our hundreds of readers :) I'm going to continue posting about Ruby language. So, today I'm going to say about object orientation in Ruby, specifically how to write a simple class, write methods (that's what I know to do with Ruby for the time being), etc.

So, below you can see a simple class written in Ruby:

class MyClass
end


And an object instantiation:
m = MyClass.new

Adding methods is very easy too:

class MyClass
def my_method
puts "That's a Ruby method!";
end
end


If you're using irb (interactive ruby), a tool to execute interactively ruby expressions read from stdin, you don't have to re-instantiate 'm', the changes made in MyClass will affect 'm' dynamically (on the fly), so if you call 'm.my_method', don't worry, it'll work.

If you're not sure about a method in a object, you can do this:

if m.respond_to? "my_method"
m.my_method
end

Do I need to explain something else?

The 'initialize' method represents a constructor in a Ruby class and the parameters come after:

class MyClass
def initialize name = "Hello World!"
@name = name
end
def hello
puts "#{@name}"
end
end

The '@name' is a field, like 'private Object obj;' in Java, and in the case above 'name' has "Hello World!" as its default value.

If you try to call 'm.name' you'll get something like:

NoMethodError: undefined method `name' for ...

This is because name is 'private', to create 'getters' and 'setters' you have to add 'attr_accessor :name' before the constructor. So, after that you can call 'm.name' or 'm.name = "hello"', for example, as you wish.

Ruby in 20 minutes

I was looking around the Ruby website and I found an interesting Ruby tutorial: the Ruby in Twenty Minutes. It shows cool features of that awesome programming language. It's really incredible what we can do with Ruby and with a few lines of code. For example, let's compare the Java code with Ruby code:

String[] anArray = new String[]{ "1", "2", "3", "4", "5" };
for(String elem : anArray) {
System.out.println("Number: " + elem);
}

That's a simple iteration over a String array written in Java5 or Java6. In Ruby the same thing could be written like this:

an_array = ["1", "2", "3", "4", "5"]
an_array.each {|num| puts "Number #{num}"}

That's really more simple than Java code, but it's not complex, the code between the curly braces is executed for each element in the "an_array" and the "|num|" is a reference to each element of the array. In Groovy, a Ruby-based scripting language, the code between curly braces is also known as "Closure":

an_array = ["1", "2", "3", "4", "5"]
an_array.each({ num -> println "Number ${num}" })

Closures are simple structures that can carry an implementation, it's like inner classes, but Closures are more simple and clear, see Closures for the Java Programming Language for a complete description of Closures and its adoption by Java.

Sunday, April 22, 2007

Learning Ruby

Nowadays I'm trying to learn Ruby, an object-oriented computer language. It's included in the category of Dynamic Languages and it's quite easy to learn and to understand it, besides it's pretty cool to develop with it as well.

I've heart about it for the first time reading some articles about Java, also object-oriented, but I got interested when I saw this article in Linux Journal magazine and these videos about Ruby on Rails, the latter really impressed me.

I'm using irb shell to learn Ruby syntax, so it's been so enjoyable. Maybe I'll develop some web application using Ruby on Rails to test my abilities with Ruby.

You should try it too!

Thursday, April 19, 2007

Ubuntu Feisty Fawn

It was released today Ubuntu Linux 7.04 a.k.a. Feisty Fawn which can be downloaded from http://mirrors.cat.pdx.edu/ubuntu-iso/feisty/. There are several enhancements, which you can see at Ubuntu Site. The great surprise was the inclusion of some Java Packages to Ubuntu multiverse repository. The list of sotwares includes:

  • GlassFish J2EE Container;
  • Java SE (JDK 6);
  • Derby-based Java DB 10.2;
  • NetBeans IDE 5.5.

That's one more step of the partnership between Sun Microsystems and Canonical. I hope more good surprises like that.

Wednesday, April 18, 2007

Have you seen Google Reader?

Have you seen Google Reader? So, Google Reader is a Google service that provides a "RSS Reader-like" application for web. In the Firefox Web Browser it's even possible to automatically add a web site feed to your Google Reader's list using that browser.

I'm really thinking giving up aKregator, RSSOwl and others local Rss Readers :P. So, one day everything will be in the web, including the operating systems and its applications and I think Google will have its own web operating system.

Friday, April 13, 2007

Dolphin, a new KDE File Manager

Dolphin is a new proposal for KDE File Manager. At first look it seems simple, but it's so powerful:



It has a simple and easy-to-use navigation tool bar. Its options are, in my opinion, easy to access, hence, they are not buried into a lot of menus, like Konqueror. But don't understand badly, Konqueror is the best file manager that I have used in my life, but it's a bit "swollen", so, it's a navigator, a file manager and more (as described in its website), I think it's really in time to change this, Konqueror is a navigator and Dolphin a file manager, each one in your side.

I really like the easily way to use Dolphin, simple options but enough, some of them are quite interesting indeed like disk usage in right bottom corner, I like it.

So, if you are like me, a new Dolphin user, and you are interested to use it as a default file manager in your KDE, just right-click on any folder and select "properties", after that click on "Edit File Type" button, near to "Type" information. In that window, add dolphin as the first application to open folders, just that, now dolphin will be your default KDE file manager, so, any folder will be opened using it. Of course, don't forget to install dolphin before.

So, that's it, enjoy Dolphin!

Thursday, April 12, 2007

KBFX vs Kickoff

KBFX is a replacement for KMenu, the default KDE menu. It's a WinXP-like menu, but it's a quite improved. It's possible to define themes for it, which can be downloaded at Kde-Look site, besides define a image as a start button. Its navigability is easier than WinXP button too, the items are showed in categories, what facilitate the users to find out their favorite softwares. The KBFX's configuration panel is easy and intuitive, and the themes can be easily added.

On the other hand, there is, in my opinion, a more improved KMenu replacement than KBFX, the first post of this blog say about it: Kickoff, a KMenu replacement created by the KDE and usability team at SUSE. Kickoff is quite special because it has more integration with KDE environment, for example, it's easily possible to add a favorite software or folder in Kickoff favorite menu just dragging and dropping a item on it, besides it, you can replace items in Kickoff menu.

In default configuration Kickoff menu is separated in five tabs: My Favorites, Recently Used, My Computer, All Programs and Leave, and each of them has a well divided and easy-to-navigate items. Specially in the Computer tab, the removable devices (USB devices, for example) are dynamically added when the user put a device. The real-time search rocks, it uses the beagle index to find out items in the computer.

So, KBFX and Kickoff are very good projects, but Kickoff is quite completed and integrated, otherwise, KBFX has the theme configuration, a real good functionality.

So, choose your menu!

Wednesday, April 11, 2007

KDE PIM

KDE PIM, or KDE Personal Information Manager, is a set of applications that aims to manage personal information. KDE PIM is part of KDE (K Desktop Environment) and it's formed by several applications like KMail, KNotes, aKregator and others. Its main result is Kontact, a personal information manager that aggregate in a unique software the others formerly cited.

Below you can see a screenshot of Kontact:



Besides source code, KDE PIM is distributed as a binary package in several Linux distros like openSuSE (as a rpm suse package) and Kubuntu (as a deb package).

Differently as in Kubuntu, the KDE PIM binary package for openSuSE is distributed as a big package, called kdepim, that is formed by its components. The problem is that not everyone use all programs
of KDE PIM, like me, for example. I love aKregator, but I don't use Kontact or Kmail. Thus, why don't openSuSE packagers pack the KDE PIM as in Kubuntu, separately? I'd thank so much.

Yesterday I tried to remove kdepim and install RSSOwl, an excellent Java RSS Reader, but I lighted upon an impressive dependency: I'd have to remove all KDE! So, I almost lost my KDE and, thus, I've had to keep on my openSuSE 10.2 the aKregator and the set of KDE PIM softwares.

So, what can I do?

Fisl8.0

Hi guys,

On April 12nd, 13rd and 14th of 2007 is going to happen the 8th International Free Software Forum. I've heard that it's going to be showed by Free Software TV, so, don't forget watching it.

TV Software Livre