General

How does Erlang Fare ?

Don Stewart recently wrote a blog comparing the time it took to compute Fibonacci numbers in Ruby, Python and Haskell, according to his results Haskell blew away the competition.

Here are HIS results

Ruby (1.8.5) 64.26s
Python (2.4) 25.16s
Haskell (GHC 6.8) 0.48s
Parallel Haskell (GHC 6.8) 0.42s

Since I am learning Erlang I wanted to see how Erlang does (please note I am a Erlang newbie) so here goes !

The Code

-module(fib).
-export([fib/1,for/2,start/0]).


fib(0) -> 0;
fib(1) -> 1;
fib(N) -> fib(N-1) + fib(N-2).


for(N,N) -> [fib(N)];
for(I,N) -> [fib(I)|for(I+1,N)].


start() -> timer:tc(?MODULE,for,[1,35]).

And the results

{3018587,
[1,
1,
2,
3,
5,
8,
13,
21,
34,
55,
89,
144,
233,
377,
610,
987,
1597,
2584,
4181,
6765,
10946,
17711,
28657,
46368,
75025,
121393,
196418|...]}
2>

That is 3.02 seconds, though not as good as Haskell, it still blew away Ruby and Python. Hey Erlang gurus out there is there any way we can seed this up ?

General

I am becoming a total nerd

Ok it is Saturday and as usual I am reading my feeds and I come across this article Style or Function canI please have both  and immediately my thoughts ran to hmm maybe he is talking about how Ruby language  has beautiful  syntax, and erlang is really great at extracting every bit of performance from a multicore processor but syntax is not that easy to read/beautiful hmm, or he is talking about lisp and bracket hell the possibilities were endless so I clicked on the link as quicly as possible ….

It turns out to be about a blackberry, oh the horror !!

General

My ‘InBox Zero’ Way

I am sure you have already heard about Inbox Zero by Merlin Mann, I love it and have modified to to fit my own needs. My process is very simple I classify all the emails I get into two categories,

  1. Ones that I need to process and delete which is a very broad category and,
  2. Ones that I need to backup which is a very narrow one.

Most of the emails once I process them, I delete them and by that I mean not just sending it to the trash box but emptying it out of my trash as well. Many people inadvertently turn there trash box into a mini backup folder. Which is really bad, if you have something to backup, well back it up, trash is well just trash and just as we do not pileup trash in our homes, we should not pileup trash in our mailboxes either. Also I process my email about once in an hour or when ever I remember to do it, keeping my mail open all the time is extremely distracting and I got better things to do than constantly processing my mail like a rat running in a wheel cage.

Second category of mails are the ones that I backup, I have a gmail account that I use specifically to do this, I have not found any other tool better capable of searching emails than gmail. What kind of emails do I backup ? only the ones that I have read and know I will need to refer back to it sometime in the future, like an explanation to some query. (Please don’t confuse this with an explain plan to a sql query :-)). An email has be of a lot of value to me in-order for it to go to backup. Think of your backup as a very precious resource. Clutter is your worst enemy even when it comes to email.

And that’s about it, armed with my system I have conqured my inbox, how about you ? What do you use ?

General

Some Interesting Articles

It is Saturday and I am just browsing and catching up on my feeds, came across some interesting articles.

Defining Success is an interesting article on IT projects, talks about how IT project success rate is really not as bad as what The Chaos Report makes it out to be. Here is an interesting quote from the article “It appears that project managers are more interested in delivering on time and on budget than delivering when the system is ready.laughing

Shared Mutable Memory Must Die, in another interesting article talks about problems with multi core cpu and programming languages, here is an interesting quote “Hopefully, if this trend continues, we shall find that certain warts of the computing industry, such as C, disappear from general use, appearing only in the most specific and suitable corners. Maybe even C++ and Object Orientation in general all but disappear as the assumptions of computing on which they are built become ever slower and unwieldy to maintain.

Comparing JVM Web Frameworks, now this article came as a shock to me , did not know flex was so popular!

In other news I have started using google reader, it has vastly improved in performance since I last used it about a year ago, it is now almost as good as desktop (LifeArea) feed reader that I use , few months ago it had crashed and since I was stupid enough not to backup my opml file, I had to setup my feeds all over again and since then I am thinking about moving to a web based feed reader. My main objection to using a web based reader was it was just not as fast as a traditional desktop app but things are changing.

General

YAY ! Java Erlang

Now that I got OtpErlang.jar (see my previous post), my next step was to connect Java to Erlang, if you have been following the book, you would have come across the Name server example in Chapter 10, this java code will connect to the name server

static void store(OtpConnection connection) throws Exception {
OtpErlangObject[] elements = new OtpErlangObject[] {
new OtpErlangString("weather"), new OtpErlangString("very nice") };
OtpErlangList erlangList = new OtpErlangList(elements);
connection.sendRPC("kvs", "store", erlangList);
OtpErlangObject received = connection.receiveRPC();
System.out.println(received);
}

static void lookup(OtpConnection connection) throws Exception {
OtpErlangObject[] elements = new OtpErlangObject[] { new OtpErlangString(
“weather”) };
OtpErlangList erlangList = new OtpErlangList(elements);
connection.sendRPC(“kvs”, “lookup”, erlangList);
OtpErlangObject received = connection.receiveRPC();
System.out.println(received);
}

public static void main(String[] args) throws Exception {
OtpSelf self = new OtpSelf(“client”);
OtpPeer other = new OtpPeer(“gandalf@devender-laptop”);
OtpConnection connection = self.connect(other);

store(connection);
lookup(connection);
}

General

YAY I finally got OtpErlang.jar

It’s the small things in life that make you happy !! As you know I have Ubuntu 7.10 and I installed erlang using ‘apt-get install erlang’. Unfortunately this style will not install Jinterface libraries. So the only way we can get it is by actually downloading the erlang source and building it yourself.

  1. Download the source from here
  2. Make sure you have all these libraries installed (use apt-get install ) # gcc
    libssl-dev, m4, libncurses5-dev, g++, openssl, gcc, java-gcj-compat, java-gcj-compat-dev, make, unixodbc-dev
  3. Make sure you have Java installed and have the JAVA_HOME variable set up in your profile.
  4. Do a ‘./configure’ followed by a ‘make’ and ‘sudo make install’

Many thanks to the following 2 links
Ethical Hacker
CouchDb

General, random thoughts, Tech

RE: Software Metrics Don’t Kill Projects, Moronic Managers Kill Projects

Great article Software Metrics Don’t Kill Projects, Moronic Managers Kill Projects, couldn’t agree less. I had written about working for good managers a while ago, thinking back about it and in general about the rate of successful Software projects I can’t help but think, Does the software industry in general have a high rate of Moronic Managers ? how come the software industry has so many failed projects ?

I think part of the problem lies in the fact that most managers have a technical background, they are great programmers and their success was rewarded with a promotion. Wish there were some online program or cash course that these new budding managers could take. I know there are a lot of books that can help too. I think it should become mandatory that one has to either read or get certified before he becomes a manager.

We have a saying in India, ‘For an intelligent person, you just need to show him the direction”, he will do the rest, I think programmers in general are very intelligent they just need the right direction 🙂

Blogroll, General

Busy Busy Busy

It has been two months since I touched my blog, I apologize for that its been really busy. First there was the trip to India which was really nice, it seems like every time I go to India the traffic on the streets have increased. With the exponential increase in the number of banks that want to give loans the number of cars have increased but the streets have not kept pace with it.

During my vacation I discovered Vince Flynn, he is a real good writer can’t put down the books once you start reading. He also has a website that you can go to. So far he has written nine books of which I have read six and plan to read the rest. His books are all about the CIA and CIA super agent “Mitch Rapp”, they are real page turners.

Also upgraded my Ubuntu install to the latest version (7.10) it felt sluggish at first but after turning off beagle it seems to be doing much better. Really impressed with tracker search and with the new Broadcom drivers my wireless card seems have better signal strength. I had to turn off all the desktop effects cause it still gives me problems with some applications like SqlDeveloper (the window does not seem to refresh), but overall. the upgrade went very smooth which was a pleasant and welcome surprise.

Also started reading “Programming Erlang“, a very interesting programming language. I strongly believe in “using the right tool for the job” which in my world translates to “using the right programming language for the project”. It does not matter if it is a small or a big project using the right tool makes all the difference, which is why I try to keep learning new languages.

So as you can see I have been real busy but now that things are settling down I hope to be more regular in updating my blog.

General

Dynamically updating JBoss Rules with Spring

JBoss Rules or formally know as Drools is a popular open source Rules Engine, it is “augmented implementation of Charles Forgy’s Rete algorithm tailored for the Java language.” I have used it for the past 2 years in various projects and have come to like it below is a list of things I like about Drools

  1. It is open source, which will help you overcome a major obstacle when trying to introduce into a project.
  2. It is light, by that I mean you do not need a dedicated server to just host a rules engine or learn a new tool, it just another Jar file you add to your existing project.
  3. Plays well with Spring, now this is a winning combination for me cause I love the Spring Framework (Spring just makes life easy).

I am not going to go in dept about using Drools with Spring you can read my other post about it, what I want to talk about today is how you would dynamically update Rules, here is my setup.

A Rules POJO

 

RulesService
{
	/** returns an instance of the Rules Base */
	getRulesBase(); 

	/** initializes an instance of a Rules Base object by reading files from a specific directory */
	init(); 

}

Make sure the RulesService is a singleton which it should be by default when you are using Spring, your spring config should look something like this.

 

	<bean id="rulesService" class="edu.apollogrp.qtask.RulesService" init-method="init">
		<!-- where to the files are stored -->
		<property name="drlResourcePath" value="RulesDirectory"/>
	</bean>

This will make sure that as soon as your context starts, the RulesService POJO will start up and initialize a Rules Base Object by reading files (usually DRL or Decision Tables) from some specified directory (we will call this RulesDirectory) on the hard disk. RulesBase is a thread safe object so no worries there.

Calling Services

All services that need to execute rules should be injected with the RulesService POJO and use the RulesService to get the instance of the RulesBase and then create a working memory using it

 

INeedRules{
	RulesService rulesService;

	someMethod()
	{
		final WorkingMemory workingMemory = rulesService.getRulesBase().newWorkingMemory();
		workingMemory.assertObject(someObject);
	}

	setRulesService(RulesService rulesService)
	{
		this.rulesService = rulesService
	}
}

Refresh

Create an Action class and inject it with the RulesService, this Action class when executed should call the RulesService.init() method, make sure this action is only allowed to some super user.

That it! now anytime you can deploy new rule files into the RulesDirectory and call the refresh action and it will immediately take effect.