July 21, 2006

Divide and rule - use multiple struts config files for one application

Too tired of searching through the long struts config file for the module you are working on? Get a new config file for your modules. All you need is to modify the web.xml to use multiple config files.

<servlet>

<servlet-name>action</servlet-name>

<servlet-class>

org.apache.struts.action.ActionServlet

</servlet-class>

<init-param>

<param-name>config</param-name>

<param-value>

/WEB-INF/struts-config.xml,

/WEB-INF/module1.xml,

/WEB-INF/module2.xml,

/WEB-INF/module3.xml

</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

When the ActionServlet is loaded, Struts will merge the results of the specified configuration files into a single in-memory configuration. Just make sure that syntax of each file is correct.

April 7, 2006

Can we trust the profiling tools?

Can we trust the profiling tools? Plain and simple: Not if you don’t know what you are doing. Running the tool is not sufficient.

Know that there are multiple things that can affect the outcome of the profiling exercise, timings are the last thing you want to trust. Lets look at the prominent reasons:

1. Operating system – Various OS have their own ways of prioritizing the threads of execution, hence these priorities will impact your results. Specially in Windows environment, default setting gives more time to processes running on foreground.

2. Cache – Most developers profile their code by restating the application server to ensure these start with minimum threads, however it affects the systems which use cashing. We must ensure the consistent environment to profile for improvements.

The most reliable way to check the timing will be to use System.currentTimeMillis() in the code that needs to be tested. Caution – use judicially.

Last words… know your profiling tool before you start the process of profiling and fixing the code. Happy coding!

February 1, 2006

Where are the technology people in India?

No offence intended, but what does these so called technology companies in India do? Outsourced work! Is that all what we can do? We, the IT people, do we create something innovative or just use what has been created by others? How many times do we get an opportunity to work on something other than the usual business functions (which will be CRUD) to be implemented?

Yes, we do have brains and knowledge to use the technology. How about creating something new, like a new language or doing something innovative. Why is it that most Indians show new ideas and innovative thinking after going outside of India? Is it because of our upbringing and education? Well, the answer is NO. Those wonderful advertizing ads which we see on TV and print media are brain child of our fellow Indians. So why can’t we (IT people) be creative?

Creativity in IT is nothing sort of new to the Indians since we have all read the stories of Indians being successful in doing so. I guess, Hotmail is the most commonly used example in this case. Innovative thinking does not necessary means complex algorithms, it essentially means simple technology…simple technology put to good use.

India’s educational tradition of strong mathematics, science and a strong system of tertiary education has created a strong vast pool of talented programmers and IT professionals. However, it is sad to notice that we still are the “clerk” that British empire had created. Yes, that’s what we are at our core…a clerk. IT people are no different. We do what we are asked to do. Never think out of the box. No new ideas.

So, it doesn’t matter if we are creative programmers or not; at the end of the day, we win our bread and butter.

January 26, 2006

How bad can Test-driven development (TDD) go...

We have been working for a project for big telecommunication giant in US. I have a team which enjoys working in an Agile (so called) team however they are not aware of the methodologies and the efforts in educating them are not fruitful because they deliver quality work on time (every time). Management is happy and so are the team members.

So what’s the problem you may think, it is all in my mind (I guess)…to begin with. What’s going in my mind is the question “How bad can TDD go”, the answer is as bad as the developers working in the team.

For those who don’t know, Test-driven development (TDD) is a software development methodology (used in XP) that uses short development iterations based on pre-written test cases that define desired functionality.

The sequence of development should be:

1. Write the test cases based on required functionality.

2. Test run the test cases, they will fail.

3. Start coding the functionality enabling each test case to pass. Keep executing the test cases to verify.

4. Deliver when all test cases have passed.

How my team does it:

1. Coding the functionality.

2. Write the test cases based on the code.

3. Deliver after testing that all test cases have passed.

To my surprise, I found out that this problem is not unique and limited to my organization, there are plenty of such examples available across the globe. The problem it seems is the motivation to use TDD comes from the fact that people want to use something new and tell others about is (prospective clients). They are unable to realize the importance of the new thing (technology/tool/methodology), hence they don’t get the benefits and end up blaming the methodology/technology.

TDD was and still is a very good technique for test-first programming concept.

December 8, 2005

Divide and rule - use multiple resource bundles

Too tired of searching through the long struts resource bundles file for the text you added? Get a new resource file for your module. All you need is to modify the struts-config.xml in the following manner:

<message-resources

parameter=" com.text.sachin.msgText "

key="msgText">

</message-resources>

<message-resources

parameter=" com.text.sachin.pageText "

key="pageText">

</message-resources>

On application startup, Struts creates a runtime representation of the message resources and stores it in the servlet context.

Note: If the properties file was located in /WEB-INF/classes/com/text/sachin/msgText.properties, you would set up the message resources element as follows:

<message-resources

parameter="com.text.sachin.msgText"/>

Use “bundle” parameter in “bean:message” tag to identify the file having the properties.

<bean:message bundle="msgText" key="msgText.welcome"/>

I’ll try to upload files with working example to illustrate this technique of struts. Post me in case you need help.