Friday, November 16, 2007

Recursive, is it good?

Want a job? Reverse a string ...
having read the blog above, remind me of an interview I had which exactly, asked me to write a code which reverse a string. The code I wrote was a simple for loop doing exactly what was asked, so simple a code that I'm so sure it won't have any bug.

The blog I read made me think, was recursive really the code that was expected by my interviewer (which then became my boss for the shortest time of my employments' life... ever :p)
Anyway, that's not what I'm talking about here, the point of interest is recursive.

Recursive, imho, is very useful, sometimes an undisputable way to solve a problem efficiently. BUT... it is not the silver bullet which will work efficiently for every problem. Yes, it will work undisputably well for layouting components (e.g. Swing, JSF), some mathematical stuffs (e.g. permutation), deleting folder and its content and many other things.

Wise programmer will try to write a simple, elegant and performing code. Less bugs, easy to maintain, faster code, less memory consumed aren't those the traits we all want for our code (there are some more...).
Only unwise programmer will try to write a recursive code for reversing a string, or maybe....
only an interviewee who knows where this question lead to, will write it that way (and hoping that he will get the job at some high salary :p).

It's really funny remembering that I've had this kind of test in my interview... If I did write a recursive code for reversing a string... was I a super programmer? or even a genius?

2 comments:

kanghari said...

Hm hm waduh bhs Madura semua, blajar dimana nich, gue mo blajar kagak punya duit, blajar di internet lupa2 mlulu, ada tipsnya ga??

http://kanghari.blogsome.com

trims commentnya di blogku

Santoso said...

hehehe, itung-itung belajar bahasa inggris nih. Belajarnya dari baca-baca artikel/buku aja kok, mo kursus juga ga punya duit :D
kanghari jg pasti bisa dan mestinya bisa :p baca manual mysql aja udah inggris, googling jg bhs inggris :p

Thx jg buat koment-nya.