News for hackers. Stuff that matters.
Re:All the jobs I failed to get by andi999 on Saturday September 19, 2020 @12:16PM (#24528475)
Honestly I think recursion is overrated. Does anyone here really write recursive functions in production? I mean it takes up stack space (which on some systems is a systemparameter), creates functioncall overhead and has rarely advantages. Trees have more natural recursive structures, but then you basically always have cache misses making your program orders of magnitude slower than if you can fit the data in a linear structure.

I mean, I would be worried if a candidate is not shy to use recursion that this will blow up software perfomance. (But then probably after hire the senior will tell: dont use recursion here)

Re:All the jobs I failed to get by juniper_strong on Saturday September 19, 2020 @02:52PM (#24529639)
I think I've used it twice in production code over the last 20 years. The first was to traverse a directory tree. I wouldn't write it that way now since there is now a standard library to do what I was doing then. The second was to traverse an object's children logging certain pieces of data from the sub-objects. I didn't design that one, I just wrote it so I don't know if there was a library that would have done it for me. Fun to write though.

Generally, developer interviews are just stand-ins for IQ tests since it is illegal to give a candidate an IQ test. Seeing if someone can easily write a recursive function is a pretty good IQ test.

Re:All the jobs I failed to get by giantg2 on Saturday September 19, 2020 @05:14PM (#24530351)
I guess it also weeds out the smart-asses like me who would question why I need to reinvent the wheel.
Re:All the jobs I failed to get by andi999 on Saturday September 19, 2020 @03:16PM (#24529771)
Finally it all makes sense. I was wondering about it and it also explains how the 'brain teaser question' like how many google engineers do you need to change a lightbulb or were there different questions, anyway, came about.
Re:All the jobs I failed to get by jimbokun on Saturday September 19, 2020 @01:22PM (#24529002)
If you can take a problem where I'm thinking of a recursive solution as the interviewer, but you can come up with an iterative solution and explain why you think it's better, I would give you full marks.
Re:All the jobs I failed to get by andi999 on Saturday September 19, 2020 @04:23PM (#24530103)
Tell me, how many recursive functions are in your companies code base. (Or course you might not be allowed to tell; but do you know the number?)
Re:All the jobs I failed to get by jimbokun on Monday September 21, 2020 @09:50AM (#24543405)
No idea, I know I've written a few.
Re:All the jobs I failed to get by andi999 on Tuesday September 22, 2020 @08:02AM (#24553484)
Thanks. How did you take tje stack size into consideration?
Re:All the jobs I failed to get by ido on Wednesday September 23, 2020 @05:01AM (#24564701)
I would guess they'd try to use tail call recursion: https://en.wikipedia.org/wiki/Tail_call
Re:All the jobs I failed to get by andi999 on Saturday September 19, 2020 @02:18PM (#24529405)
Thats not the point. I think it is possibly harmful to focus on recursion in teaching and interviews. (Of course if the understanding is, that you do not use it in real life, then its ok, but still why not test people on skills they need for the job; its like making people jump through hoops for a swimmers position).

Of course I will be embarressed soon, when it is only me who doesnt use recursion in production. :-)

Re:All the jobs I failed to get by creata on Saturday September 19, 2020 @02:39PM (#24529560)
I don't know what goes on in the minds of interviewers, but if I had to guess, they use recursion to test the interviewee's ability to reason inductively --- which, of course, is necessary for writing even simple loops. Maybe a question about loop invariants might be a good replacement.

Regardless, yes, I doubt many people write a lot of recursive functions, since the data structures people use tend to either be flat, based on arrays, or neatly hidden away in libraries.

Re:All the jobs I failed to get by andi999 on Sunday September 20, 2020 @04:11PM (#24536996)
The data structures people use are choosen by people. So it is a choice to have flat datastructures (probably by people how see the diadvantages of recursion)