Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. how many times in your life have you implemented recursive methods

how many times in your life have you implemented recursive methods

Scheduled Pinned Locked Moved The Lounge
62 Posts 45 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jsc42

    Unfortunately, that is not recursion. It is an infinite iteration.

    F Offline
    F Offline
    Fabio Franco
    wrote on last edited by
    #39

    Nope, it's an infinite recursion. The link is a method call.

    To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

    E 1 Reply Last reply
    0
    • V Vasily Tserekh

      I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

      F Offline
      F Offline
      Fabio Franco
      wrote on last edited by
      #40

      I think that happens to you for one of the reasons below: 1 - For the problems you need to solve on your tasks specifically, recursion is not a good solution. Although I find it difficult to never see business rules that can make good use of it. 2 - A stack makes more sense in the cases you find. 3 - You don't realize how recursion can be a great solution to your problems. To me it's just like math classes I had in college; I used to be really impressed with the vision my teacher had to solve some steps of the problem when I used a whole sheet of paper instead of 2 lines like he did.

      To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

      1 Reply Last reply
      0
      • V Vasily Tserekh

        I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

        B Offline
        B Offline
        BrainiacV
        wrote on last edited by
        #41

        I've used it for drilling down through directories and tree structures, and some math functions use it. Once I used it to overcome a limitation of the DOS/370 Assembler, as opposed to the OS/370 Assembler. The DOS version would only allow you to assign 8 characters to a string. The OS version allowed up to 255 characters. I needed to parse some strings that I was using in a Macro. I noticed that if I called another Macro, I could pass 255 characters in the parameters. So I wrote a recursive Macro to peel apart the input string, add the new characters and then reassemble the characters of the symbol I wanted the Macro to create. One problem I found with recursion, is that once you understand it, you have a hard time going back to methods that do not use it. Back in my Apple II days, I needed to drill down through the new subdirectories that ProDOS (the quantum leap from DOS 3.3) now allowed you to create. Applesoft Basic did not support recursion. I stared at the problem for while because I remembered doing recursive like code before I learned recursion in PL/I. I was finally able to unwind my mind back to those days and got the program to do what I needed, but the whole time I was thinking how much easier the problem would have been if the language had supported it.

        Psychosis at 10 Film at 11 Those who do not remember the past, are doomed to repeat it. Those who do not remember the past, cannot build upon it.

        1 Reply Last reply
        0
        • V Vasily Tserekh

          I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

          T Offline
          T Offline
          Thornik
          wrote on last edited by
          #42

          I have to agree, recursion is the latest methodology I used in code. Once it was traversing directory tree and second is WPF visual tree. That's ALL! TWICE in my life :)))

          1 Reply Last reply
          0
          • F Fabio Franco

            Nope, it's an infinite recursion. The link is a method call.

            To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

            E Offline
            E Offline
            englebart
            wrote on last edited by
            #43

            And the back button on your browser is the "return" opcode

            1 Reply Last reply
            0
            • A AspDotNetDev

              I imagine some developers come across recursion more often than others. For example, I sometimes deal with recursion when writing code that traverses the file system, but I don't do that very often. Video game developers might do it when they handle BSP, closest path algorithms, collision detection, and so on. And just because you don't use it often does not mean it's not incredibly useful. Some problems might seem insurmountable without recursion. You might also seldom use trigonometry, but when you need it you really need it.

              Thou mewling ill-breeding pignut!

              E Offline
              E Offline
              englebart
              wrote on last edited by
              #44

              For file system traversal, you only need to write the recursive code once. Then implement a visitor pattern.

              class/interface DirectoryVisitor {
              void enterDirectory(dirName, depthFromRoot) throws AbortTraversal;
              void exitDirectory(dirName, depthFromRoot) throws AbortTraversal;
              void visitFile(fileName, depthFromRoot) throws AbortTraverasl;
              }

              1 Reply Last reply
              0
              • V Vasily Tserekh

                I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                C Offline
                C Offline
                Conan Callen
                wrote on last edited by
                #45

                What's the difference between recursive and redundant? ;P

                1 Reply Last reply
                0
                • V Vasily Tserekh

                  I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                  G Offline
                  G Offline
                  geekware
                  wrote on last edited by
                  #46

                  Recursion is quite often the most elegant solution to many problems. I cannot encourage you enough to buy a copy of "The Little Schemer" by Daniel P. Friedman and Matthias Felleisen. It has but one aim, to teach you to think recursively. It will rock your world and make you a better code monkey. Plus you might develop a crush on Lisp/Scheme.

                  1 Reply Last reply
                  0
                  • M Mike Hankey

                    Quite often, recursion is very handy.

                    VS2010/Atmel Studio 6.0 ToDo Manager Extension
                    Version 3.0 now available. There is no place like 127.0.0.1

                    R Offline
                    R Offline
                    RafagaX
                    wrote on last edited by
                    #47

                    I've implemented recursive methods at most 10 times in my life, but half of these times, i had to replace them with iterative methods because of stack overflows or for consuming too much memory. :doh:

                    CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

                    1 Reply Last reply
                    0
                    • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                      Countless. I event made recursion is SQL... However today I use a better way to implement the idea of recursion - faster and lighter...

                      R Offline
                      R Offline
                      RafagaX
                      wrote on last edited by
                      #48

                      Kornfeld Eliyahu Peter wrote:

                      Countless. I event made recursion is SQL...

                      That's masochism. :-D

                      CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

                      1 Reply Last reply
                      0
                      • V Vasily Tserekh

                        I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                        H Offline
                        H Offline
                        Harley L Pebley
                        wrote on last edited by
                        #49

                        Frequently. A couple times in the last week alone.

                        1 Reply Last reply
                        0
                        • V Vasily Tserekh

                          I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                          G Offline
                          G Offline
                          giuchici
                          wrote on last edited by
                          #50

                          Like many others have said, recursion is not happening that often in most of programmers' lifes. However if you are designing a compiler, think of all the method calls: methods that call methods that call other methods and they have to return. Or functional programming languages rely heavily on recursion, using it where a procedural language would use iteration. You don't have to be a fancy compiler designer. I had to implement an electronic data interchange EDI for X12-211 Motor Carrier Bill of Lading. Good luck doing it without recursion. The point is that there are problems for which the recursive solution is 1000 time less consuming to implement than a traditional iterative way or any other way. Those are the moments you learn it for. And because it is not easy there's more satisfaction to be had when all the pieces come together and it works recursively. Cheers.

                          giuchici

                          1 Reply Last reply
                          0
                          • G gavindon

                            Chris Losinger wrote:

                            it helps to have done it before, because it can be a little tough to get your head around it sometimes.

                            I agree, I still remember the smoke coming out of my classmates ears the section we were doing recursion in c++. course, come to think of it these were the same guys that responded with an answer of a "if" when asked what kind of loop they would use in "x" situation....... :doh: Thought my poor instructor was going to have a stroke on the spot. This was not in the beginning course either, it was in data structures. (3rd course in c++ for us, beginner, advanced, then data struct.).

                            Common sense is not a gift it's a curse. Those of us who have it have to deal with those that don't.... Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow. You can't scare me, I have children.

                            O Offline
                            O Offline
                            onemorechance
                            wrote on last edited by
                            #51

                            Ah, yeah ... the old "if loop". I went to school with a few of those folks as well. Almost the exact same situation you described, but my instructor wasn't close to having a stroke ... he just made a miserable attempt at not laughing out loud.

                            1 Reply Last reply
                            0
                            • G gavindon

                              Chris Losinger wrote:

                              it helps to have done it before, because it can be a little tough to get your head around it sometimes.

                              I agree, I still remember the smoke coming out of my classmates ears the section we were doing recursion in c++. course, come to think of it these were the same guys that responded with an answer of a "if" when asked what kind of loop they would use in "x" situation....... :doh: Thought my poor instructor was going to have a stroke on the spot. This was not in the beginning course either, it was in data structures. (3rd course in c++ for us, beginner, advanced, then data struct.).

                              Common sense is not a gift it's a curse. Those of us who have it have to deal with those that don't.... Be careful which toes you step on today, they might be connected to the foot that kicks your butt tomorrow. You can't scare me, I have children.

                              L Offline
                              L Offline
                              Leng Vang
                              wrote on last edited by
                              #52

                              Think recursive with C++ or any other high level languages is complex, try doing it in pure Lambda Expression. Still scratching my head.

                              1 Reply Last reply
                              0
                              • V Vasily Tserekh

                                I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                                J Offline
                                J Offline
                                jcmaida
                                wrote on last edited by
                                #53

                                In compiler design, recursion is quite useful. It can get overly complicated though. For example: subroutine A and subroutine B are both recursive and call each other. You can see how complicated it can get tracing the execution path. Really not as bad it seems, but you better have your recursion hat on.

                                1 Reply Last reply
                                0
                                • V Vasily Tserekh

                                  I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                                  L Offline
                                  L Offline
                                  Leng Vang
                                  wrote on last edited by
                                  #54

                                  Recursive is what makes a computer useful. Recursive in theoretical computation is very useful and couldn't be easily done without it. Try some Lambda Calculus for example.

                                  1 Reply Last reply
                                  0
                                  • V Vasily Tserekh

                                    I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                                    M Offline
                                    M Offline
                                    Moshe Katz
                                    wrote on last edited by
                                    #55

                                    In many functional languages, such as OCaml, recursion is the best way to write code that processes a list. There are certain situations in that language where recursion is faster and/or more efficient than iteration. I haven't used it for any major projects though.

                                    1 Reply Last reply
                                    0
                                    • V Vasily Tserekh

                                      I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                                      T Offline
                                      T Offline
                                      TRK3
                                      wrote on last edited by
                                      #56

                                      I write them often enough -- but that's because the problems I'm trying to solve are best solved by recursive methods. The problem with teaching recursion in school, is that too often the examples you are given are examples that could just as easily (and often more easily and efficiently) be written as loops. So, you are shown the example, and your immediate reaction is: "Why would I ever want to do it that way?" And you, being a practicaly person who just wants to build useful things, quite naturally decide that there is no point to doing things recursively so you don't bother to learn it. Where, on the other hand, your academic minded professor is so stuck on the "mathematical beauty" of thing he can't be bothered with explaining the practical aspects of it. There are certain classes of problems (graphs, trees, parsing) where recursion is the natural way to solve the problem and where trying to do it in a loop is just painful.

                                      1 Reply Last reply
                                      0
                                      • V Vasily Tserekh

                                        I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                                        S Offline
                                        S Offline
                                        SeattleC
                                        wrote on last edited by
                                        #57

                                        Lots of problems have easy-to-understand and easy-to-remember recursive solutions. It's good for a quick hack, and useful as a basis for the less-expensive iterative or dynamic programming version of the solution. The Holy Grail of recursive expressions is getting the compiler to automagically code the iterative realization of your easy-to-specify recursive solution. Some progress has been made in this regard, particularly in functional languages where practically everything is recursive.

                                        1 Reply Last reply
                                        0
                                        • V Vasily Tserekh

                                          I can count with the fingers of my hand the times I had to implement recursive methods in my life, so what was the fuzz all about when you are in school ant programming teachers tell you that that is the holy grail of programming!!! ps: i know that is important but most of recursive functions are implememnted and you only have to use them.

                                          M Offline
                                          M Offline
                                          Member 4608898
                                          wrote on last edited by
                                          #58

                                          I deal a lot with parsing so there is recursion and mutual recursion involved. If I use recursive descent, then I don't need to find a port of yacc or bison on the platform I'm using. It is a lot faster anyway since the scripts are generally correct so there is no need for good error messages that yacc is better at giving than recursive descent. I also use it for duplication on screens top, left, right and down and inserts, deletes and searches on home brew tree structures. Some structures are mutually recursive classes so that is quite a bit. All in all about 20 to 30 times in every company I've worked for so that is at least 200 times. It depends on what field you work in. If it is just controlling devices, you'll never need to use it.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups