Wednesday, February 11, 2009

The 8th Habit of a Programmer !

Oh don't go on the title of this post. I am just trying to read this book called 'The 8th Habit' but my daughter won't approve. It seems only one person, who is allowed to read a book in my house, is my 2 years old daughter. Never mind.

There was an interesting post by Jeff Atwood, Don't Reinvent The Wheel, Unless You Plan on Learning More About Wheels. I won't go that far to expect programmers will rewrite the libraries and use it in live projects. But sometime a programmer should think about how the wheel was invented, at first place.

Interestingly, one of my favourite questions, which I ask during technical interviews and mainly to the junior developers:
Assume a particular programming language statement/Function does not exist as yet. Now explain how would you go about building a logic to replace the original statement / Function.

e.g. What if SAP has not provided a SORT statement for the internal tables? or
You need to print the amount in words and let's assume there is no function [ SPELL_AMOUNT ] available in SAP.
I don’t expect them to explain exactly the way it should be, neither do I know it by myself. But their approach to answer this question does help in identifying the real programmers.
How does a candidate react to these type of questions, is also very revealing. The programmers, who really like programming - logic, analysis etc. - they are pleasantly surprised. And those who are wrongly in this profession, will have a completely different reaction. They try to argue to prove it's an unnecessary question. They don't get the motive behind these questions. 
If spelling the amount seems to be too difficult then try with a coffee corner question. I like reading threads in the coffee corner at SDN and there was a funny question by Amit Khare.

Try it without looking at the answers.

1) Pick your favorite number between 1-9
2) Then Multiply by 3
3) Add 3, then again Multiply by 3
4) You'll get a 2 or 3 digit number.... right?
5) Add the digits together.
Example: if your number is 34, 3+4 so that your number is 7

Now with that number see who your ROLE MODEL is from the list below :

1. Mother Teresa
2. Nelson Mandela
3. Your mother
4. Your father
5. Bill Gates
6. Gandhi
7. Brad Pitt
8. Hitler
9. Amit Khare
10. Barack Obama

Well it does not take much of the available common sense to realize that you'll always get Amit Khare as your role model, in case you decided to calculate.

However, if you are a programmer, you may immediately get the urge to solve the logic (or maths) behind the equation, even if it's trivial.

Let's say the number that you choose ( between 1 to 9 ) is X.
Then the calculated number will be : 3(3X+3) =  9X+9 = (10X -X) + 9 = 10X + (9-X)
Basically, the idea is to arrange this in the form of (10*X + Y ) to represent any two digit number.
e.g. 24 =10*2 + 4

So the final number is 10X + (9-X) and that means the first digit of the number is X and 2nd digit has value (9-X). So the addition of the digits = X + (9-X) = 9.
Basically, you will always get 9 for this calculation, irrespective of your chosen number.
Well that does not require much of your logical skills.. so what about this? Write a program, which will generate these kind of questions, in favor of any of the selected role models :) . Have fun !!

No comments:

Post a Comment

Info : Comments are reviewed before they are published. SPAMs are rejected.