Archive for the 'Tech' Category

Top 10 traits of a good programmer

As I have written in one of my earlier posts, this is the 9th year of professional programming for me. In this post I will summarize my thoughts on what makes a good programmer (master programmer or chief programmer as called by some). I wouldn’t call myself a master programmer yet, but I am pretty sure I know the traits that define a good programmer.

Now before I go into the details, let me first clarify what the term “programmer” means to me. A programmer is not someone who blindly implements whatever design is given to them. Many software service companies in India are under this impression. This myth is purposefully floated around mainly because 90% of the programmers in these companies have less than a year of programming experience. So  coding/programming has to be projected as a mechanical activity!

So who is a programmer? A programmer is someone who has fairly good understanding of computer systems, can write good code, is intelligent and can visualize a software solution for a particular software requirement. He looks at the software requirement and starts thinking - How do I build this thing? How I can design the interface so that it is most user friendly? What happens when there is huge data volume? How do I ensure that no one hacks into my program (especially for Web applications)? How do I reduce coding effort? How do I ensure future additions have minimum overhead?

So as you can see it is much more than just mechanical coding.

Ok no more preaching! Here is my top 10 traits for a good programmer.

1. Think! -  This is the most important trait of a good programmer. He never jumps into anything. Given a problem, he first thinks over it. The more he thinks, the more ideas, questions and alternate solutions come to his mind. I see the lack of thinking as the primary source of all problems a novice programmer face. When he comes across a problem, he doesn’t think. Instead he bangs his head on it or asks for help from another guy. Sometimes you need to ask for help, but think on the problem or bug before you run across to your technical lead!

I will give an example of the importance of this “Think” factor. Sometime back we had a requirement to build around 40 interfaces. This basically required scripts to be written to transform data from a set of tables in one database to another. The estimates were done like this,

1 interface = 5 days and hence 40 interfaces = 40×5 = 200 days of build effort.

When I started on the project, everything was in place. The team, the effort of 200 days and the schedule. Then I thought over it. I saw that if a generic framework is written for the transformation, I could externalize the transformation rules into an XML file. The generic framework took me about 10 days to build. Then for all the 40 interfaces, the time taken was 5 days (since only tranformation rules were to be written). So my team got a lot of free time! :)

2. Learn! - Learn Baby, learn! A good programmer has a burning desire to learn new things every day. It is almost 15 years since I started programming. And even today, I spent a lot of time learning new things. When it comes to programming, every program you write teaches you something. I have fairly good knowledge of Java, C, C++, C# and Qbasic (yes qbasic is my first love!). Just recently I have started learning PHP.

Nowadays learning trait is something which I see less and less in my professional life. The learning itself is so formalized and force fed that people are bored with it.

By learning, I am not talking about taking professional certification. Sorry to say this, but I have nothing but contempt for many of the professional certifications (for example the Sun certifications). In India, it is very easy to manipulate the system and there is a lot of fraud happening on the certification front.

3. Help others! - This to me is the golden rule of programming. “Help other as you would want others to help you”. In my case, I think much of the programming wisdom I possess has come from helping others solve their problems! I used to sit till late hours and help others solve their programming problems or bugs. The advantage was,
 a) Immense experience in solving programming problems.
 b) Various ways people see a particular problem. Also you come across interesting/weird/strange ideas!
 c) Empathy towards programmers. The difficulty they face in their day to day job.

Unfortunately as I grew older and came in touch with extremely process centric enviornments, I realized that “Help others” is not something officially appreciated.

4. Lead by example! - Another important trait if you are a senior programmer or architect. Many times I have come across senior technical architects who say - “It is simple, you just do this and do that”. I am 100% sure that many of them can’t code what they so confidently say as “simple”!

If you are a technical lead or a lead programmer, lead by example. Write code in front of your team members. You will get more trust, respect and support from your team!

5. Know everything! - Ok, that doesn’t sound right. I will rewrite it - Know a bit about everything. For example, If you are a core Java programmer, you should also know about SQL programming. It also helps if you know a bit of regular expressions or a scripting language. For example, I have recently gone through XML specification twice even though I have no professional need right now. But someday I will need it.

6. Know basics of computer science! - There are many programmers out there who doesn’t have the basic knowledge of computers or their inner workings. This is very essential. Many of the programming difficulties that people face is due to the lack of knowledge of how computers work! If needed take a computer science course.

7. Perfect it as much as you can! - Nobody is perfect. You can’t write perfect code in the first iteration. Refactoring is the mantra. Analyse your code, find code fragments that can be reused and refactored.

8. Use tools! - Many programming tasks can simplied if you use appropriate tools. For example, in all my projects I use Ant to automate build and deployment process. You will be surprized at the time you save!

9. Explore code! - If you want to improve your coding skills quickly, one thing I recommend is exploring code written by others. If I would have said this 10 years back, you would ask me- “Where can I find good code?”  But now the scene is completely different. Open source movement has revolutionized everything.  There is so much good open source code out there that I feel overwhelmed by it!

10. Be Humble! - Humility is the last of the top 10 traits a good programmer should have. But it is not the least! As you get more and more experience, it is very natural to feel arrogant. The moment you become arrogant, you loose the trust and respect of your fellow programmers.

I have come across many who are intelligent and technically quite good. But again I have no respect for them simply because they are arrogant. Being arrogant also shows how ignorant you are!

Remember, no one is perfect. You can also make mistakes. If someone points it out, thank him and accept his valid comments.

Closing thoughts

Now you might be thinking - Why is this guy not talking about “design patterns”? Why is he not talking about “Ruby on Rails”? What about extreme programming? What about open source contribution? Linux? and so on.

My dear friends, In my opinion talking about design patterns or practising pair programming(as in XP) etc. are not one of the top 10 traits. Being aware of design patterns definitely helps, but I think you will anyway come across it yourself if you are a regular programmer or if you explore code written by others!

Again I want to stress my first point. A good programmer is someone who can build a “good” software system given a software requirement. The “good” here means - correct, optimized, reusable, extensible and elegant. Everything else (tools, language, methodology) are just tools to achieve it.

Programming is not for everyone. If you don’t have the passion for it, quit and find another job. If your company doesn’t recognize your talent, quit the company.

Further Reading

Here are a couple of good books for exploring further on this subject. If you know a good one do let me know by commenting below.

The Mythical Man-Month: Essays on Software Engineering, 20th Anniversary Edition - The good old classic by Frederick P. Brooks.

Code Complete, Second Edition by Steve Mcconnell - A must read.

The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt and David Thomas - I endorse the apprentice method

Expert One-on-One J2EE Design and Development (Programmer to Programmer) by Rod Johnson - A must read if you are a J2EE guy.

Your thoughts are welcome!

Hiding sub categories in Wordpress - a quick hack

Here is a quick hack to hide sub categories in Wordpress. This has the added advantage that even though sub categories are not visible, they will still get crawled by search engines. For example, the categories you see on the right are only the root categories.

All you have to do is to add the following line to the Wordpress stylesheet.

.children { display: none; }

This works because the secondary level categories have “children” as the style class.

In praise of Google Reader

What is Google Reader?

Google Reader is an online feed reader tool which allows you to subscribe to feeds (RSS/Atom)  provided by various blogs/websites. These feeds represent the latest content on the blog/site.  Instead of visiting all the Websites/blogs, you can read all the latest content from one place!

In praise of Google Reader

Google calls Google Reader as the inbox for the Web. I think that is an apt description of Google’s feed reader.

I have been using Google Reader for a month or so now. I find it very user friendly and responsive. Earlier I was using Feed Reader, which was a desktop based RSS/Atom feed aggregator.

There are couple reasons why I switched from a desktop based aggregator to online aggregator.

1. I use a couple of computers. I have one at home, another at office and sometimes I carry around a laptop. So synchronizing feeds across all these became a chore.

2. When you have a huge number of feeds subscribed, any desktop based aggregator will affect your bandwidth. I have a 256kbps link at home and it crawls when I start FeedReader.

3. I am always on the net.  I have three broadband connections and there is never a time I am not connected. So the advantage of offline reading with desktop aggregators doesn’t mean much!

4. The best thing with online aggregators is that you can read your feeds from anywhere!

Following screenshot shows how my feeds appear on Google Reader. The left side shows all the feed sources organized neatly in folders and the right side shows the feeds in the selected site.

Jayson’s feeds on Google Reader

Cool features of Google Reader

Here are some cool features of Google Reader.

1. There are two kinds of views for the feed inbox. In the expanded view, merely scrolling down makes feeds as read. This is very neat feature when you have thousands of feeds! You can just scroll down and “star” the ones which you find interesting. Later, you can read those “starred” ones and then remove star!

2. You can share interesting feeds on a single click. The “Hot Links” you see on the right side of this page are actually my shared feeds from Google Reader. This can be customized as well (Currently mine is set to 5 items).

3. Google Reader interface is fast. It uses on demand loading and hence is fast even when you have a large number of feeds.

So in summary, if you are looking for a good online feed reader check out Google Reader. It is still in “labs” stage and daily I could see improvements on it. For example, the refresh link at the bottom was recently changed to a refresh button on top left.

Backing up your Wordpress installation on Dreamhost

I did a complete backup of this Wordpress blog yesterday. There isn’t much written, but loosing my blog entries is not something I am looking forward to! It is very important to backup your blog. I will give some reasons if you are not convinced.

First, this blog is hosted on Dreamhost. Recently many problems have been cropping up with dreamhost such as router disaster or network disaster or something like that. You never know when they will have a disk failure and it turns out that their backup tape/disk is unusable!

Secondly, Wordpress is not very secure if the recent events are any indication. The Wordpress 2.1.1 was modified by some deranged cracker. So it is quite possible that there are problems in Wordpress 2.1.2 also and if some nutcase decides to hack your site? Boom!!! - all your posts are gone..

How to backup my Wordpress blog hosted on Dreamhost?

The backup process involves two things. Backing up your blog database and backing Wordpress files which includes theme files modified by you. You must backup both.

Backing up Wordpress database - Backing up Wordpress database is very simple in Wordpress 2.1+. In earlier versions you need to install backup plugin. In Wordpress 2.1+ you can find export option under manage as shown below,

Backing up Wordpress 2.1+

Backing up Wordpress files including customized theme files - My host is dreamhost and I will explain how the Wordpress file backup can be done very quickly. If you use Windows explorer and try to copy everything, it can even take hours! This is because the dreamhost installation contains hundreds of themes you don’t use and also transferring thousands of files over FTP is very slow.

Here is a quick backup solution. Connect to the Dreamhost shell using Putty (A secure shell client). Go to your Wordpress installation folder and type the following command.

zip -r backupall.zip *

This will create a single zip named backupall.zip which contains everything. Now this can be quickly copied to your system!

Limiting query results in DB2. Replacing ROWID in Oracle

While working with DB2 tables, many times we may need to limit query results. This is especially true when we just want to test out our queries. If the data volume is huge, the queries can take hell lot of time.

In oracle, the solution is to use ROWID in WHERE clause. In DB2, you can use the construct FETCH FIRST 10 ROWS ONLY. For example,

SELECT * FROM CUSTOMER FETCH FIRST 10 ROWS ONLY;

Error in RAD 6.0: Resolve against non-hierarchical or relative base error

RAD error due datasource configurationWhile changing the datasource configuration in Rational Application Developer 6.0, I across the following error.

java.lang.IllegalArgumentException: resolve against non-hierarchical or relative base

This turned out to be a very nasty problem. I first tried removing the datasource configuration and reconfiguring it. When that didn’t work tried deleting the server configuration. No luck!

On googling, I came across this solution.
http://www-1.ibm.com/support/docview.wss?uid=swg21218587

Solution
Open the resources.xml and find:
<cmpDatasource href=”tempworkarea.xmi#DataSource_1125683336050″ mce_href=”tempworkarea.xmi#DataSource_1125683336050″/>

The only way to fix this error is to manually edit the resources.xml. On searching under runtimes folder, I came across multiple resources.xml files. Edited all of them and removed cmpDataSource references completely.

The steps are,

1. Shutdown RAD.
2. Remove cmpDataSource entries completely from resource.xml files under “runtimes” folder.
3. Start RAD and reconfigure datasources.

It worked!

Apple, Cisco marriage?

BBC reports that Apple and Cisco has reached a settlement on the iPhone brand name.

Apple and Cisco Systems have resolved their dispute over the iPhone brand, with both companies agreeing that each can use the name for their products.

There are no details on what type of agreement is reached. Probably Cisco would have seen that trying to protect iPhone in court is not worth the money! By now everyone already identifies iPhone as the “cool mobile from Apple”. 

Configuring DB2 connectivity in Rational Application Developer (RAD)

Rational Application Developer (RAD 6)When you start Web application in RAD 6.0 (Rational Application Developer 6.0), the first thing you need to configure is the database access. In this article, I will show you how to configure DB2 database access in RAD. I assume that DB2 is hosted on a Windows machine.

First thing you need to configure DB2 is the DB2 universal JDBC driver. These can be taken from DB2 server installation or from DB2 connect installation. The files you need are,

db2jcc.jar
db2jcc_license_cu.jar
db2jcc_license_cisuz.jar

Copy these files to a folder. This can be anywhere(I would suggest that you keep this under Rational root folder).

I assume you have already created a server configuration in RAD. Now right click on the server (from server window) and click on “Run administrative console”. This will open up the administrative interface. Typically it runs at “http://localhost:9060/ibm/console/“.

Login by giving any userId. Click on “JDBC providers” under “Resources”. On the right side you will see JDBC providers listed. Click on “New”. Now select values as shown below.

RAD JDBC Provider Settings

Click on Next. Now fill the driver paths in the Class path as shown below. You need to change this to point to the folder where JDBC jars are stored.

 RAD JDBC settings

Click on Apply button. Once you have pressed apply button, you will see a Save link above. Click on Save and then click on “Data sources” link on the right side. Fill in as shown below. Please substitute your DB2 server configuration (IP address, DB name and port etc.). Also note the JNDI name, which you will use in your application.

 RAD Datasource configuration

RAD Datasource settings
Click on “J2C authentication entries” on the right and fill in as shown below. This should be the DB2 userid/password. After completing this, press apply and return to Datasource screen.

RAD Datasource settings
Now you need to select the userid alias you have created from “J2C authentication entries” under component managed authentication alias as shown below. Please note that this is in Datasource screen.

RAD Datasource settings

Now you can apply and save the settings. Click on “Test Connection” to verify the settings. If you see a successful message, you are all set for DB2 access from your Web application!

Any problems? Mail me!

Fighting comment spam in a Wordpress blog

We all are used to email spam. I get around 100 spam mails daily in my Gmail account. Thankfully most of these are identified as spam by Gmail and gets moved to spam folder automatically.

When I started this blog, I never thought that spam would be a major issue. Initially I haven’t added any comment moderation. Within a week, I started seeing spam comments mostly related to pharmacy and drugs. I started manually deleting spam and soon I realized it is not going to work.

In Wordpress, under options->discussion, there are a couple of spam fighting measures available. I enabled comment moderation which automatically puts a comment in moderation queue if it contains 2 or more links. I have also enabled common spam word protection. This means that any comment which contains words in this list will be automatically put into moderation queue.

The solved the problem for a few more days. Then I noticed that I have over 100 comments to moderate. Now sorting through 100 comments to find a genuine comment is not something you would cherish!

Wordpress provides something called comment blacklist. If any of the words in this list is part of the comment, the comment will be nuked. It will not appear in moderation queue. So I analyzed few spam comments and added the common words into the comment black list.

I had hoped that these measures would solve the spam problem. Soon I realized that I was too optimistic. I started getting a lot of comments and it contained black listed words with spelling mistakes! For example, the word viagra will appear as viegra or something similar.

Looking at the spam comments I noticed that all of them are coming from a set of specific IP addresses. So what I needed was a way to blacklist IP addresses.

In Wordpress, under manage->files you can see the .htaccess file. This can be used to block a specific set of IP addresses. So I added the following entries in this file (Substitute the actual IP address instead of 127.0.0.1)

order allow,deny
deny from 127.0.0.1
allow from all

So today, I have no comments to moderate. Thank god! :)

Notes

1. There are sophisticated spam fighting tools such as the Akismet which is distributed. I am yet to use it.
2. It is better to disable trackbacks. Tools such as trackback submitter is widely used by spammers.