December 21, 2007

Encapsulation and don’t repeat yourself

Richard Moore comment on Access Anxiety explains why Encapsulation is a good thing. I think both are missing the point. Nobody doubts that encapsulation is a good thing, and Michael Feathers tries to present ruby way as a more “relaxed” thing.

The author was comparing the ‘ruby style’ of direct access to member variables with the getter/setter pattern common in Java code

So what is the ruby style really?

The annoying thing about java setters is that they are functions. So you either start with them (which is overkill for simple things) or don’t use them and then you are lost when you want to add things like Richard showed.

Ruby on the other hand, makes it easy, because you can’t expose member variables, but you can very easily create default accessors.

Michael Feathers example is wrong. Usually you start by actually offering a simple default accessor.

class GlazeObject
  attr_accessor :store, :formatter

  def initialize
    @store = DefaultStore.new
    @formatter = DefaultFormatter.new
  end
end

Now, if you need something more special, like Richard example:

public void setFormatter(Formatter formatter) {
        this.formatter = formatter;
        this.expensive = doCalculation(formatter);
    }

You can just remove attr_accessor :formatter and add to the class:

class GlazeObject
  def formatter
    return @formatter
  end

  def formatter=(f)
    @formatter = f;
     @expensive = doCalculation(f);
  end
end

What is the difference? In ruby, for client code consuming this class, you always see obj.formatter for both cases. In java you have to start from the beginning copy-pasting repetitive accessor code if you don’t want to start changing obj.formatter to obj.getFormatter() and obj.formater = something to obj.setFormatter(something).

C# has a similar feature, called properties.

public class Person
{
  private int _age; 
  public int age
  {
   get
   {
     return _age;
   }
   set
   {
     _age = value;
   }
  }
} 

No matter if we start with a public variable called age, we can move it to setters and getters (which are the providers of encapsulation without having to change the operation mode from variables to functions.

July 30, 2007

Preguntas y Respuestas en el caso Microsoft-Gobierno de Chile

July 20, 2007

I jump on the git bandwagon too!

It was not my intention to use git. All started when I was looking for some way of doing commits to subversion repositories while being offline and at the same time creating local branches.

I tried SVK. At the beginning it seemed fine. But soon after I started to face it’s limitations:

  • depot / checkout separation is sick. Detach a checkout just to move it around? no thanks

  • Something (probably me?) went wrong and I ended up overwriting Michael’s commits in ZYpp subversion.

  • To share and move commits between machines, I would need to mirror the depot of the other machine in my laptop.

  • slow

  • packaging it was not fun

So, during aKademy in Glasgow, while having some italian food with some trolls and KDE people, Simon told me he was using git to interact with perforce and subversion.

Back in Nürnberg, I started to try it. First I tried tracking KDE4 subversion repository using git-svn (tutorial). Then ZYpp. It works really well, especially with cmake (it forces you to compile out of the source tree), so you can do workflows like this:

  • being in master, sync your master branch with subversion.

  • ok, now you have to implement feature X.

  • create a local branch, checkout it, work, compile from your build dir

  • do a couple of commits.

  • Somebody comes to your office, to discuss some bug. Your feature is half broken so you want to discuss using the clean master. Checkout master.

  • The nice thing is, checkouts are in the same working copy, so if you recompile from the build dir, only the files changed between branches will be recompiled. In other system, every checkout has to be in a different directory (except svn switch which is crap).

  • you switch back to your feature branch and continue working and commiting.

  • when it works, merge it to master. git-svn dcommit will send it back to subversion.

Till now, I am really satisfied with it. I will keep blogging about it as I learn more.

July 5, 2007

Developers cooling on Windows desktop, study finds

In a survey, Evans Data found that almost 65 percent of software developers are targeting some version of Windows for their applications, as opposed to nearly 75 percent last year.

The research group expects the number to drop another 2 percent in the coming year.

The culprit? Linux. Developers are choosing to write applications for Linux desktops in almost 12 percent of cases, which is a 34 percent increase from last year.

“It’s clear that a shift away (from) Windows began about two yeas ago, and the data show that this migration is now accelerating. Linux has benefited, but we also see corresponding growth in niche operating systems for non-traditional client devices. The landscape is changing,” said Evans Data CEO John Andrews in a statement.

Full link

June 23, 2007

Parlement

parlement 0.13:

parlement is a mailing list and a Web forum moderated using Direct Democratic principles: votes and personal filters. It is also a P2P system that aims to implement electoral lists and PGP signatures.

May 31, 2007

ZFS presentation : The last work in filesystems

link.

Also, ZFS FUSE implementation.

May 29, 2007

Links

May 21, 2007

truecrypt

Truecrypt updated to 4.3a.

Don’t ask me what KBUILD_STR is, but defining it as #s seems to work.

May 15, 2007

Eclipse and cmake

cmake editor for Eclipse announced.

May 11, 2007

Busy week

This has been a really busy week. Moving to a new apartment. At home I only see boxes everywhere :-(

Lot of news coming from the Java field. I am happy for what is happening with the Java world.

  • The strategy for Solaris finally makes some sense: making it like Linux, but with its own strengths. Everyone will win here. (it will be GPL soon][1] ). The only looser will be Microsoft and whose can’t use GPL code. I am not sure if the strategy is right, but making Sun a player with both Linux and Solaris is much better than the “Linux, eeer Solaris, er Linux… Solaris!… Linux!” strategy.
  • Flash and Silverlight will get a competitor from Sun and the Java world. This is good news for Linux, as it can be the first free solution on this platform. Watch the demos.
  • Platform for cellphones.
  • There is a video of a Google Earth like client done by Sun and NASA, based on the new FX technologies. It will be free and can be used as a component in Java programs.

Also: