Archive for August, 2006

Eclipse, your way

August 16, 2006

Recently I found a great website called easyeclipse.org that has many specialized versions of Eclipse. For instance, if you are a Web developer, EasyEclipse Server Java should do the trick for you.

The catch is that they offer versions with the most useful plug-ins pre-configured into the distribution. In addition, you also can download self-installing plug-ins from the website.

PROS

  • Out-of-the-box configuration
  • MacOS, Linux and Win32 automated installation
  • Download, click, install plug-ins
  • Multiple languages versions, like LAMP, PHP, Ruby on Rail, Python, …

CONS

  • Based on rather old 3.1 version

So, that’s it. Let’s just hope they make the migration to 3.2. When they do I will most likely start to use it as my default IDE.

See ya next time!

Update: Cool! EasyEclipse.org’s member Phillip just sent the link to the 3.2 beta preview. Keep up the good job!

Advertisements

Coding best practices: thinking about it

August 15, 2006

Today I have joined a discussion that emerged on our development team: whether to use multiple return statements within the same method.

Well, back when I was a terrible newbie programmer using Clipper as the main development language, someone convinced me that every function (that was the name for a procedural equivalent of today’s object’s methods) needed one unique return point. I stickied to it but never questioned myself ever again if this is really a good thing to do. Nowadays I got myself doing just the opposite: using multiple return points and when I analyzed it, I found that really better. I’ll explain.

Imagine the following method that searches for a particular object within an ArrayList:

private boolean userExists(String name) {
  boolean found = false;
  for (User u : this.getAllUsers()) {
    if (u != null && name.equals(u.getName())) {
      found = true;
      break;
    }
  }
  return found;
} 

Doesn’t this method seems a lot cleaner and easier to understand than:

private boolean userExists(String name) {
  for (User u : this.getAllUsers()) {
    if (u != null && name.equals(u.getName())) {
      return true;
    }
  }
  return false;
} 

There are other cases where I can see the code begging for an immediate return 🙂 like:

private void loadUsers() {
  if (usersLoaded) {
    return;
  }

  // do all the lengthy user loading...
  (...)
}

In my opinion, the early return when the users are already loaded are easier to interpret and easy to review by another coder than:

private void loadUsers() {
  if (!usersLoaded) {
    // do all the lengthy user loading...
    (...)
  }
  return;
}

I really don’t think it’s a major problem and using one or the other is pretty acceptable but I’d like to hear from you what you think about it so please leave a comment about it if you can. Thanks.

Update: A friend of mine just e-mailed me an article that addresses the same issue.

Changing colors of an image in real time

August 15, 2006

Recently I needed the ability to change colors of a picture in real-time. I was developing a game where I needed to paint the player costumes many times within the game. I have researched on the internet and didn’t find any J2ME code available.

I digged all around for an algorithm to do that and found a way to do it.

(more…)