Categories
All JRuby

JRuby on its way up?

I am programming Ruby since a friend of mine pointed me to this language and I think that this language is even better then Smalltalk which has been my all time favorite since I learned it back in the late 80’s. The concepts are sound, minimal and powerful and don’t take too long to learn. All else you need comes either with the standard library or nicely packaged as ruby-gems.

Especially JRuby, designed to run on the JVM, gives you portability together with access to the huge fund of java libraries. An enormous powerful concept! I love it!

Last night I have been searching in Google a little bit about the usage of the different programming languages to see if the usage of Ruby is increasing. The good news is that Ruby seems to be constantly in the top 10 of the most used languages. But to be frank, I would have expected it before Python and fighting with PHP about its rank but that doesn’t seem to be the case.

There are plenty of sites which analyse the language popularity and the results differ depending of where they gather their information. Some of the major sites are: SourceForge, Tiobe and Langpop. Unfortunately I could not find any comparison about the usage of the different ruby implementations.

I asked myself: what does it need for a programming language to become successful?

  • an elegant, minimal, easy to learn and complete set of language elements.
  • the ability to add missing language features as natural extension of the language or in additional libraries.
  • a powerful infrastructure including IDE, build system, deployment, …
  • good frameworks for maximum momentum when starting a new project
  • killer applications

When I think about Smalltalk-80 and ask myself why did this language never get one of the top places in ranking even though it had undeniable a huge impact on all subsequent languages? I think it is because there are simply several factors missing which denied this language its broader success. Even though the language was elegant, powerful and extendable it had to fight with it’s, for that time, heavy weight virtual machine and the need to deploy the whole image. And I have never seen a so called killer application developed in Smalltalk.

When I come back to PHP, Python and Ruby I was wondering why PHP was clearly in front of Python and Ruby even though I think that the language concepts of Python and Ruby are sounder then the one of PHP.

They all have IDE support, good frameworks and powerful supporting infrastructure but PHP still has one big advantage. It nearly dominates the market of opensource CMS and Blogging products.

If we want to push Ruby into the first places I think there are only two ways to do this:

  1. development of killer applications
  2. bringing Ruby into the browser

For the first way we have the ideal starting point with JRuby. True Multi-threading and access to a vast fund of professional Java libraries together with the expressiveness of Ruby! I think that would qualify for a pole position.

The second way … OK, I don’t know how much would be needed to integrate ruby into a browser. But I think that Javascript is used everywhere on the client side in web applications in a lack of a better alternative.

While I was still writing I got some good news. It seems that there will be enough supporters to reconsider the Netbeans decision to discontinue the JRuby support. A good possibility to do something for the visibility of JRuby!

Let’s go for it!

Categories
All JRuby

Rails Plugin Documentations

As computer scientist I am working since 20 years now and since 2 years I have a lot of fun programming in Ruby or better in JRuby.

At the moment I am working on my first bigger Ruby on Rails project and have to state something which I wouldn’t perhaps have agreed with in my earlier years too:

Code (even well documented) is no substitute for good documentation!

I would like to address this specially into the direction of some developers who are writing really great plugins for RoR. A little bit more documentation about the basic ideas would lower the threshold for Rails newbies like me a lot. Naturally I am able to figure out how a plugin really works without documentation and I am sure that I can learn a lot from this experience. But eventually I will end up writing my plugins myself because that makes me faster then figuring out how something works which another programmer has developed.

So please keep in mind: Writing code in a computer language which is easier to understand and comes more natural does not subsitute for a good documentation!

Categories
All Patents

The Nonsense of Software Patents

I am Software Developer and my opinion is that Software Patents are not only Nonsense but also counterproductive!

There are not infinitely many ways to program something. Computer Science Theory already shows that for many problems there are only few methods to solve the problem with programming in a reasonable way if they are solvable at all. And then there are best practices in programming which simply evolved from many programmers coding a huge amount of code and trying to make everything more manageable.

On the other hand there are the software companies who try to claim every idea as theirs to gain control over their competitors or even a part of the software development universe. This turns programming more and more into a run through a minefield and I am already sure that one day when I finally think that I get a big success with one of my programs there comes one of these big patent hoarders and wants its part of my cake because I violated some sort of broad spread patent.

As I can read on Heise Online today this time someone tries to get his piece of cake from our dear competitor Microsoft. It seems that the Canadian company i4i holds a US Patent No. 5,787,449 which describes the separate manipulation of architecture information and data of a document within the same file.

Not that I am not a little bit mischievous that it hit Microsoft, one of the biggest supporters of software patents and rigorous enforcer of his own “rights”, but I have to state that I am a little bit astonished that such a patent is possible after all! I mean, the patent was filed in 1994 but at this time we had already the Java Programming language since 1992. And together with this language came the famous JAR-file which is an zip-archive enhanced with a metadata file. This metadata file describes the “architecture” of the jar-archive and can be manipulated independently from the class files which normally constitute the data. It becomes even more obvious that this method is common sense when you examine the usage of ear- or war-archives because with the appearance of J2EE the usage of XML-Files within the archive for configuration and architecture description of the data within the archive went a huge step further.

Since 2006 the Open Document Standard is specified, which actually does what every smart programmer would do without any guidance. It packs together the formatting information and the data of a document into one archive, the exact same path which was already prepared by the jar-archives.

So, especially in direction of Microsoft, I would like to ask: Does anybody else have the same impression as I that software patents are really counterproductive an therefore should be forbidden?

I for myself have never in this business seen a striking innovation where I would have agreed that this should be protected by a patent. But I am only about 20 years in this business. Perhaps this point is still to come.

Categories
All Ruby

Ruby Objects, Class-Objects and MetaClass-Objects

After a while of evaluation I started over programming mainly in Ruby about two month ago.

Long time ago I learned for a short while object orientation programming in Smalltalk-80 but soon started to use C++, first with the AT&T preprocessor and later with the gcc. Since 1998 I am programming Java. All these years have left me with a certain idea of practical object orientation which was not really what I learned from Smalltalk-80.

But Ruby changed things a lot as I have to admit. In Ruby everything is an object and Ruby is interpreted like Smalltalk! What are the consequences. This is what my post will try to figure out.

From Ruby Core – Class documentation:

Classes in Ruby are first-class objects—each is an instance of class Class.

A big help for understanding Ruby Objects has been the Pickaxe Book.

In Ruby everything is an object. This includes as well Integers as Classes. So what happens if you write something like:

  a = "test1"
  b = "test2"

You get references a and b to your Objects a and b of class String which is an object too and has the class object Object as superclass. So far the only difference is that the Classes are realized as objects themselves.

But you can do things in Ruby which you cannot do in C++ or Java. For example you can add a method only to one object like:

  c = 'test'
  class < < c
    def double
      self + self
    end
  end
 
  c.double
  =>"testtest"

This piece of code generates a virtual class exclusively for the object c.

What happens if you try the same for integers? If you try the same for integers it should look like object b in this graph:

The code for this would be:

  b = 7
  class < < b
    def double
      self + self
    end
  end
 
  TypeError: no virtual class for Fixnum

So what is this? I thought that all objects can have virtual (or singleton) classes which hold the methods specially attached to this object?

The solution is quite simple. There are special classes like Fixnum which are called eigenclasses. Instead of a reference to an object these classes return the class object itself (for example as parameter for a method call). Eigenclass objects only have one single Object for example for each Fixnum value. This is why it is not possible to create singleton classes for eigenclass objects.

But what you can do is to extend an eigenclass with your own attributes like:

  class Fixnum
    attr_accessor :name
  end
 
  b = 5
  b.class
  => Fixnum
  b.name 'five'
  => "five"

The next thing I want to do is to define a class variable. I found a nice article about class variables in Ruby on John Nunemakers blog. At first I was really astonished about this:

  class Polygon
    @@sides = 10
    def self.sides
      @@sides
    end
  end
 
  puts Polygon.sides # => 10

This is a Polygon class with a class variable which holds the number of sides of the Polygon and a getter class method. Now we create a subclass which inherits from Polygon and holds its own number of sides:

  class Triangle < Polygon
    @@sides = 3
  end
 
  puts Triangle.sides # => 3
  puts Polygon.sides # => 3

What happens here? The Polygon sides have been set to 10 originally.

To understand this behavior you must have an understanding about the Ruby Meta-class and look-up mechanism for methods and variables. When you create a class variable or method Ruby actually creates the following Meta-Class for you:

The Meta-Class hold the Class level extensions of your class. If you subclass Polygon now you have the following image:

In Ruby everything, including class definitions, are executable code. The assignment to the class variable @@sides in the class Triangle leads the Ruby interpreter to search for an existing class variable @@sides which he finds in the Meta-Class of the superclass Polygon first and makes an assignment to this variable instead of creating a new meta-Class with the same variable for Triangle.

So what can we do if we want to have a variable for the sides of our class which is unique to the according class? As the class itself is an object you can assign a variable to the class object

You can do this with the following code:

  class Polygon
    @sides
    class < < self
      attr_accessor :sides
    end
  end

for the Class Polygon and the same for class Triangle. Be aware that you have to assign the accessors to the class object and not to the object itself.

I hope that my explanations are correct and can help other newbies in Ruby to understand the Class handling a little bit.

Categories
All IDE

XXX – the only IDE you need

I am a passionate programmer since I had access to a computer for the first time.

I have been working with many IDEs in my professional life. The first integrated IDE for me was the XEmacs which enabled me to include all build scripts and commands into the editor and start them via shortcuts or menu.

Since these days many things changed. You don’t write programs only in one language any more, a huge set of tools has to be controlled by the IDE and still an number of command line tools have to be integrated.

I used Eclipse since the version 2 because I liked the way they tried to make the IDE extensible. When the OSGi kernel came with version 3 I was completely convinced to finally have found my last IDE. Until this very day about a year ago when I tried to update the running Europa plugins and the update messed up my IDE in a form that I had to reinstall Eclipse completely from scratch. Because I was not able to get all needed plugins stable running due to dependency inconsistencies I had a look over to Netbeans.

As I could see the version 6.1 was a huge advancement to the last try I gave Netbeans. As I am a pragmatic programmer and only IDE user, not developer, I changed to Netbeans. You can guess how long. It started with a small problem to get the PHP module working together with other modules I needed so that I ended up with two installations. Now my main Netbeans 6.5 wanted to update some modules. After this update I had to deinstall Netbeans completely. No trick helped to recover from an inconsistency within the loaded modules.

So at the moment I have one Eclipse Environment for Java and Eclipse RCP development, one Netbeans 6.5 installation specially for PHP development and one Netbeans 6.7 beta for a Netbeans module I am working on. JRuby and Javascript development I am doing sometimes with Eclipse, sometimes with Netbeans.

I really thought with IDEs the world would become easier than during the times when I still programmed using the VI in different xterm windows and using command line tools but sometimes I have my doubts about this assumption.