3

I have 2 year of experience in IT. I haven't seen any recursive code. I would like to know If there is any company or organization Who use recursive code on their Production Environment. It would be great If some also explain the use cases also.

shubham12511
  • 620
  • 1
  • 9
  • 25
  • 1
    umm... you would be pretty much screwed if you couldn't use recursion if you are developing in lisp or scheme for instance. – bolov Jan 17 '17 at 09:49
  • 3
    If a web developer never sees C++ code in production it doesn't mean C++ is not used. IT is such a big field you can find legitimate uses for virtually any paradigm – bolov Jan 17 '17 at 09:55
  • @bolov Since recursion can always be replaced by iteration, any sentence containing "has to use recursion" (in the sense of calling functions recursively) is fundamentally wrong (sorry to be so harsh ;-) ). That said, it is true that many recursive data structures can be handled beautifully with recursive functions.But it is also true that iteration is usually faster and less risky in terms of, well, stackoverflow. – Peter - Reinstate Monica Jan 17 '17 at 10:14
  • @PeterA.Schneider I completely agree. – bolov Jan 17 '17 at 10:18

3 Answers3

3

All code which uses variadic templates necessarily uses recursion, see e.g. http://kevinushey.github.io/blog/2016/01/27/introduction-to-c++-variadic-templates/.

The answers to this question give a few recursion examples. The most convincing one is a hand-coded compiler (or rather parser) implementation for a recursively defined language (like C and most others, where blocks can contain blocks, expressions expressions etc.). Perhaps it's only most convincing to me because I did that in a CS course, but still. Even here it is admittedly possible that production compilers are created with tools and are not recursive. If anybody shed light on the inner workings of gcc or one of the other open source compilers, I'd appreciate it.

I would generally assume that some programs handling recursive data structures with a limited recursion depth (like balanced trees, as opposed to normal trees or lists) use recursion, just because it is simple and elegant, and the depth limit removes the greatest obstacle for recursion.

Come to think of it, I have actually used recursion to parse a simple "option language" for an internal custom-made program which has an option -eval <file>, where the referenced file contains more options, possibly including more -evals. The referenced files are indeed simply recursively evaluated.

Community
  • 1
  • 1
Peter - Reinstate Monica
  • 15,048
  • 4
  • 37
  • 62
  • 3
    the fractal of your avatar are most likely generated recursively. – bolov Jan 17 '17 at 09:57
  • @bolov Actually, if I remember correctly, while the math is recursive (the output of step n is used as input of step n+1) my implementation was iterative. The reason being that tens of thousands of iterations can be necessary to achieve a result. – Peter - Reinstate Monica Jan 17 '17 at 09:59
  • well... it's not a production environment and it doesn't count! (just kidding :)) ) – bolov Jan 17 '17 at 10:05
1

If the programs are basically CRUD (create, retrieve, update, delete) screens to interface to a database of some kind, you won't see much call for recursion. And that's a lot of of serious, real world programming.

But large numbers of programs have trees. E.g. an artwork tree, or a 3D animated object tree. Once you work with trees, recursion is by far the easiest way to solve problems.

There's also the "functional programming" paradigm which replaces iteration with recursion. It has some theoretical benefits and is used in some environments, though it's still a bit academic and experimental.

Malcolm McLean
  • 6,258
  • 1
  • 17
  • 18
0

For your information I was into a IT company in my earlier days where I use to write loads of recursive code in production Environment. and more over it depends upon the coder if you wish to c I can send some recursive code example

smn_onrocks
  • 1,282
  • 1
  • 18
  • 33
  • I don't need examples. I am just curious, In what situation someone need to go with recursion rather than any alternative approach. – shubham12511 Jan 17 '17 at 09:53
  • 1
    @sbmc7 You literally asked "I would like to know If there is any company or organization Who use recursive code", and smn said "yes, we did!". This clearly exactly answers the question. If you don't like this answer, you may want to rephrase your question to " In what situation [does] someone need to go with recursion rather than any alternative approach", which is a much more interesting question because it is absolutely impossible that no company ever used recursion. (Btw., there aren't many alternative approaches, are there? There is exactly one.) – Peter - Reinstate Monica Jan 17 '17 at 10:26
  • 1
    @sbmc7 let me give you an example we have a scenario like we had a process proc1 which can't run until process 2 get completed so I did a trick I wrote 1 main process in which I wrote 1 IF else statement like if the process 2 run successfully then only process 1 got its slot to run else it take a sleep for 2 minute and again call itself. Hope it bit clear for you now. – smn_onrocks Jan 17 '17 at 10:40
  • @smn_onrocks Yes! I got the point. – shubham12511 Jan 17 '17 at 12:46