October 4, 2006

Struts authentication on every request

Today, somebody asked me if we always need to implement an interceptor design to authenticate the user request every time before it is processed. Fortunately for him, he is working on a Struts based solution, hence my answer was that you have an option to create a subclass of RequestProcessor.

Override processPreprocess() (which returns true in normal conditions) to call your method which will authenticate the user request. Return true to proceed and false to abort request processing.

I have learned this trick the hard way (doing it wrong the first time), but you have my blog to simplify things for you. Write to me (Sachin) if you need any particular solution.

September 19, 2006

Speech at a High School by Bill Gates

Bill Gates recently gave a speech at a High School about 11 things they did not and will not learn in school . He talks about how feel-good, politically correct teachings created a generation of kids with no concept of reality and how this concept set them up for failure in the real world.

Rule 1 : Life is not fair - get used to it! Rule 2 : The world won't care about your self-esteem. The world will expect you to accomplish something BEFORE you feel good about yourself. Rule 3 : You will NOT make $60,000 a year right out of high school. You won't be a vice-president with a car phone until you earn both. Rule 4 : If you think your teacher is tough, wait till you get a boss. Rule 5 : Flipping burgers is not beneath your dignity. Your Grandparents had a different word for burger flipping: they called it opportunity. Rule 6 : If you mess up, it's not your parents' fault, so don't whine about your mistakes, learn from them. Rule 7 : Before you were born, your parents weren't as boring as they are now. They got that way from paying your bills, cleaning your clothes and listening to you talk about how cool you thought you were. So before you save the rain forest from the parasites of your parent's generation, try delousing the closet in your own room. Rule 8 : Your school may have done away with winners and losers, but life HAS NOT. In some schools, they have abolished failing grades and they'll give you as MANY TIMES as you want to get the right answer. This doesn't bear the slightest resemblance to ANYTHING in real life. Rule 9 : Life is not divided into semesters. You don't get summers off and very few employers are interested in helping you FIND YOURSELF. Do that on your own time. Rule 10 : Television is NOT real life. In real life people actually have to leave the coffee shop and go to jobs. Rule 11 : Be nice to nerds. Chances are you'll end up working for one.

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.