Thursday, September 30, 2010

Dont be in love with one language, be in love with the concepts

If you are like me, who does programming for living, if you are very passionate about one language and would never ever think of switching to any other language?

Then this blog post if for you. 

During my early years as programmer, I was very passionate about Java and only Java (does not mean that, I am any less passionate about Java today).  I wanted to do programming only in Java.  I thought I can do anything and everything in Java (which is true even today).

I was very apprehensive to do programming in any other language.

Then due to a project requirement I had to work on C++.  Because of that, I started appreciating Java even more.

How elegantly it does memory allocation and garbage collection etc.  I started appreciating the high productivity I could get using Java.


After that, I got an opportunity to work on Ruby on Rails.  I started admiring all the dynamic feature of Ruby language.  Started appreciating closures in Ruby and learned how a few lines of code can be expressed in just on single line.  Started admiring how simple, a modern web framework could be. 

Then came along .Net.  In .Net we had used a dependency injection framework called Castle.  I had used Spring framework from the Java world in the past, because of this I could apply same concepts in Castle framework.  This meant, I was productive from Day 1.  Effectively no learning curve involved!

I realized that as time passed, C# and Java have converged to each other.  Both these languages have learned from each other and implemented some very good features.

Then, I started working on Grails.  I was amazed to see that, Grails and Ruby on Rails are almost 90% similar.  They are so similar to each other in concepts and implementation that, I find the only difference is the syntax!

Again, was able to apply the concepts, that I had learned while doing the Ruby on Rails project in Grails.  End result productive from Day 1.


After all these years, I have learned one thing and that is, all these languages be it Java, Ruby, Groovy, C# etc. be it anything, they implement same concepts over and over and over again.

Now I feel, If someone is a good programmer it actually does not matter which language they use to achieve a given task.

Language and Framework are just tools to achieve a particular task. 

In the olden days car manufactures used old tools to manufacture cars and now as the tools and technologies improve they use better tools and manufacture wonderful cars!

Applying similar analogy we just have to keep updating the tools that we use so that we can create good efficient software.

That's why I keep saying to programmers, don't be in love with one language, be in love with the concepts!

Saturday, September 25, 2010

We deserve bad infrastructure and filthy rivers!

Recently, India - New Delhi, has earned lot of negative publicity.  All thanks to the conditions at the Common Wealth Games venue - India - New Delhi 2010. 

I use the term earned very carefully.  Earned literally means

acquire or deserve by one's efforts or actions

Conscious efforts have to be made to earn something.  And that is exactly what India has been doing.  There was enough time to prepare for CWG then why this last minute rush!

Papers, Media, News Channels, common man everyone has been cribbing we need better infrastructure, better roads, cleaner city!

But, I would beg to differ.  I think we deserve bad infrastructure, poor roads, filthy rivers, ugly cities! 

Its not the government who is at fault.  Its us, the common people, who are at fault. 


I have come across a lot of incidents where common people have damaged public properties like roads, rivers, parks, trains (and the list goes on) for personal or religious motives.

The recent example that I want to highlight in this post is the famous Ganesha Festival! 

I stay in Pune, where the festival is celebrated with a lot of enthusiasm! 

When the festival is nearing, one can see a lot of Ganesha pandals being setup up right in the middle of the road.  I am not kidding, people staying in Pune would agree with me, the pandals are literally in the middle of the road!

How are the pandals set up? 
Its simple!  Find 4 helpers, dig up the road, set up the pandal.  And we are done! 

Government spends huge amounts of taxpayer's (like us) money constructing the roads. 

Then one fine day, we (the tax payers) decide, who the hell needs roads!  We need Ganesha pandals!  Lets dig up the roads! 

As the years have passed by, more and more Ganesha pandals have been setup.  I think in Pune, there is a Ganesha pandal every 10 meters (or less)!  At some places the Ganesha pandals are right next to each other.  One bigger than the other!

End result: The road constructed by the government (using the tax payers money), is damaged by tax payers themselves! 

I don't know what are we achieving by doing this, but I think we are wasting our own money!

Do we need soooooooooo many Ganesha pandals?  What about the amount of money spent in celebrating this festival?  Can it not be brought to good use?  Can we not build schools and colledges out of it?  Can we not help poor and needy people in someway with that money?

I am not saying that we stop celebrating the festival all together.  But we could tone down the celebrations a bit.   We can come up with 10000 alternative ways of spending left over money for a constructive activity! 

Lets not talk about the environmental issues caused because of the massive and maddening Ganesha visarjan (idol immersion)!  Who is responsible for that?  You may think its definitely not me!  But, I think its all of us! 

How did this festival start in the first place?

If we look back in time, freedom fighter and social reformer Lokmanya Tilak, transformed the ganesh festival into a large and organized public event (before that it was a family affair)

Why did he do it?  During those times it was necessary to bring people closer to each other, to unite them. 

Wikipedia says:

It served as a meeting ground for people of all castes and communities in times when, in order to exercise control over the population, the British discouraged social and political gatherings. 
During those times, I feel it was for a good cause!  The festival had a constructive effect!

But now, we have forgotten the real motive behind the festival.  These days people are more concerned about whose pandal is bigger or whose pandal is more attractive!

At the end when the festival is over, it has a more destructive effect on our roads, rivers and city in general.

Its not just the Ganesha festival in Pune, I am sure Durga puja is also celebrated in similar fashion in in Kolkata!

Because we, ourselves damage the infrastructure, environment and the cities, we have no right to ask for better infrastructure, clean rivers, clean cities!

We deserve all this!  Unless we change, things will not change!

PS: I don't intend to hurt any ones religious sentiments. 

Monday, September 20, 2010

How to connect to mysql server from a remote machine

My colleague wanted to connect to my local MySql server 5.5 (installed on Windows 7) from his machine. I had not give "root" user, privileges to connect remotely.

Hence, I decided to create a new user for my colleague and give the new user remote access.

So how do we do it?

Let say the user we want to create is called "batman". Lets say that, the machine from which this batman user is going to log on to my local MySql server is called "batmanscave". My machines name is supercomputer.

Our first step towards allowing remote access is to create a user. This is how we do it.

The above syntax tell MySql to create a user batman who is at batmanscave i.e. he will connect to the MySql server from batmanscave machine. And his password is catwoman.

At this point if you try to login to MySql from the batmanscave using the following command it wont work

Because, the user batman still does not have rights to connect to MySql server installed on my machine remotely.

Next, we need to grant remote privileges to the batman user. This is how we do it.

Basically, We are granting all rights to the batman user.

Next, we need to flush privileges so that they are persisted in MySql tables using the following command.

We are almost done!

Even after doing all this we were not able to connect to my machine remotely. Tried various things but no luck.

Turned out that problem was not with MySql, but the real problem was windows firewall. It was blocking the default port of MySql 3306.

I opened up the port in the windows firewall and bingo! We were able to connect to MySql installed on my machine remotely!

Wednesday, September 15, 2010

Be a Programmer not an Architect!

In a lot of projects that I have worked so far, I have come across a situation where one/or more person/people act as an Architect to the project.

One would wonder, what are the responsibilities of these Architects
  • They are supposed to see the bigger picture
  • They are supposed to guide the project in the right direction
  • They are supposed to give good solutions to technical problems
Time and again I have felt that, the intent is right! But, (there is always a but!) the problem is people take up the role in the wrong spirit.

A lot of architects that I have met, have stopped doing active programming. Most of their time is spend in attending meetings, calls and drawing some pretty diagrams.

You might think whats wrong with that?

Well, I think (and these are strictly my views), If someone is not in touch with programming then how can he/she suggest a sane solution to any technical problem?

If someone has left programming years ago then
  • How can he/she solve any technical problem? 
  • How can he/she visualize that there is going to be a technical problem implementing a solution that he/she is suggesting?
I think answer to all of the above questions is, they can't!

And I am making these claims out of personal experience.

First example:

I have worked in a project where some architect decided that, there is no MVC framework in the Java world that suites our requirements!

And the project ended up have its very own brand new MVC framework. This was not some project in 1980 (BTW I was not even born by then!). This was a project executed in 2009.

I don't understand that in 2009 how can one decide to write a new MVC framework?

One might thing whats wrong with writing a new MVC framework? Most important problem is, re-invent the wheel!

Lots of open-source projects have invested a hell lot of time and money in making sure that, a MVC framework does what its supposed to do.

If someone write an MVC framework, may be he/she is not aware of all the possible cases an MVC framework should support.

End result, a half baked solution that solves the "todays problem" but its no good for the future!

Another thing to consider is the cost: Who is paying for this framework anyways? Its the client of-course.

End result, software becomes expensive!

I think such wrong decisions make software expensive then it should have been. Client gets a piece of software that he never needed in the first place.

I think there must be at least 25 MVC frameworks in the Java world in 2009. I am sure at least a few would have fit whatever requirements we had.  Its just short slightness on the part of the Architect, to decide to write a new MVC Framework rather than finding one that fits the requirements.

Another example:

I had worked in a project where Architect's had decided that, we should not be using any types other than String's.

We had a few web-services to do various things in the project. One of them was to do payment. According to his suggestion, all arguments to the methods in payment web-service should be of String type!

Man! the first time I head of this decision, I was thinking, what the @#$%^&!

Imagine passing amounts as String and then in the web-service implementation converting them into proper types.

Imagine because of the fact that amounts were of type string, client's of web-service could pass "abcd" as the amount.

Hence, web-service implementation had to validate these values and throw an exception or return an error message stating that "abcd" is not a valid amount!

All that validation code and the mapping code is all waste!  It's just a big big big waste!  Something that was not required in the first place. Client paid for that code! (Its almost like distributing free money.)

Why did this happen?

Because the Architect was not in touch with Programming, he could not visualize the real problems that would appear because of this decision.

End result, maintenance nightmare, ugly code, overly complicated system.

I think in the end all I want to say is, Stay in touch with Coding. Coding is not a mundane task that anyone can do.

A person can become a good Architect iff (if an only if) he/she is a good Programmer!
Have some Fun!