• steve (unregistered)

    OMG - when will they start teaching recursion?

  • W (unregistered)
       <span>If</span> objNode.NodeId = 3382 <span>Then</span>
    GetNestingLevel = 3
    <span>Else</span>
    GetNestingLevel = 4
    <span>End If<br><br>I really don't get that. What's the reason for that?<br><br><br>Oh, yeah, frist, and all that.<br><br>(and captcha is batman, cool)<br></span>
  • Scott Stroz (unregistered)

        Make the bad man stop....

  • greg (unregistered)

    Shouldn't those last two cases be 69 and 70?

    (not the Greg that submitted)

  • rt (unregistered) in reply to steve

    of even how to do a simple loop.

  • jesuswaffle (cs) in reply to steve
    Anonymous:
    OMG - when will they start teaching recursion?


    An iterative solution would work just fine here (you get C, because I don't know VB):

    int get_nesting_level(node *n) {
      int i;
      for (i = 0; n; i++)
        n = n->next;
      return i;
    }


    And a larger WTF: what on earth is this supposed to do?

  • OneMHz (cs)

    A recursive or iteritave method wouldn't work. I think Alex accidentally snipped out the cases where the nesting level was non-numeric. Anyone who didn't realize the cases were there is just dumb.

  • Xocomil (unregistered)
    <span>No recursion is necessary to make this work. I'll edit this function to make it<br>do what the code shows:<br><br>Public</span> <span>Function</span> GetNestingLevel(objNode <span>As</span> Node)

    <span>If</span> <span>Not</span> objNode.Parent <span>Is</span> <span>Nothing</span> <span>Then</span>
    GetNestingLevel = 0
    <span>Else</span>
    GetNestingLevel = 60
    <span>End</span> <span>If</span>

    Much smaller and all that extra fluff is gone. I guess if I got paid to code
    per line I might leave it in....
  • Gnictigezoink (unregistered)

    DAMN you 61st level of nesting! You break my code!

  • GoatCheez (cs) in reply to OneMHz
    OneMHz:
    A recursive or iteritave method wouldn't work. I think Alex accidentally snipped out the cases where the nesting level was non-numeric. Anyone who didn't realize the cases were there is just dumb.


    I'm curious as to how you came to that conclusion...

    I agree with this being a major WTF, but it does appear that it isn't as straight-forward as it appears. The line that checks the Node's ID pretty much explains why. For some reason, certain nodes with certain IDs report their nesting level differently than the non-special nodes.
  • JoeBloggs (unregistered) in reply to steve
    Anonymous:

    OMG - when will they start teaching recursion?

    Does Visual Basic even support recursion?

  • joe bruin (unregistered) in reply to jesuswaffle
    jesuswaffle:
    Anonymous:
    OMG - when will they start teaching recursion?


    An iterative solution would work just fine here (you get C, because I don't know VB):


    Actually an interative solution is better because it won't cause a stack overflow when there are a million parent objects.  Those of you who thought of using recursion, consider yourself WTF-enabled.
  • Anonymous (unregistered) in reply to W
    Anonymous:
       <span>If</span> objNode.NodeId = 3382 <span>Then</span>
    GetNestingLevel = 3
    <span>Else</span>
    GetNestingLevel = 4
    <span>End If<br><br>I really don't get that. What's the reason for that?<br><br><br>Oh, yeah, frist, and all that.<br><br>(and captcha is batman, cool)<br></span>


    That would be the single case of undocumented mystery business logic.

    (captcha=whiskey fitting for today)
  • Colin (unregistered)

    Nobody needs more than 640 KB of RAM^H^H^H^H^H^H^H^H^H^H^H^H^H 60 levels of depth!  (I count 69 not 59 Parents as well)

    And for-loops are for the typing-endurance-challenged.

  • Fred Foobar (cs) in reply to jesuswaffle
    jesuswaffle:
    Anonymous:
    OMG - when will they start teaching recursion?


    An iterative solution would work just fine here (you get C, because I don't know VB):

    int get_nesting_level(node *n) {
      int i;
      for (i = 0; n; i++)
        n = n->next;
      return i;
    }

    I think it would go something like:
    Public Function GetNestingLevel(ByVal node As Node) As Integer
        Dim i As Integer
        i=0
        While node.Parent Is Not Nothing
           i=i+1
           node = node.Parent
        WEnd
        GetNestingLevel = i
    End Function

    Is Not Nothing. VB needs a Something for these cases.
    (Haven't done VB in a while, don't syntax-flame me.)

    And a larger WTF: what on earth is this supposed to do?

    I think it tells you how deeply nested a node in a tree (a DOM tree, maybe) is. Why that would be useful? Dunno.

    EDIT: Anonymization typo, maybe? What's that Not doing in there? (If Not node.Parent Is Nothing
  • steve (unregistered) in reply to OneMHz

    dammit - i always forget the 'in_between_21_and_22' nesting level

  • GoatCheez (cs) in reply to JoeBloggs
    Anonymous:
    Anonymous:

    OMG - when will they start teaching recursion?

    Does Visual Basic even support recursion?



    Better question would be what DOESN'T support recursion. Recursion isn't a language feature, it's a programming method. If a language has what we all call functions, then you can recurse.

  • Maxim (unregistered)

    Dim objNodeTesting as Node
    Dim NestingLevel as Integer

    objNodeTesting = objNode.Parent
    While not objNodeTesting = Nothing
       objNodeTesting = objNodeTesting.Parent
       If Not objNodeTesting = Nothing Then
         NestingLevel = NestingLevel + 1
       End If
    End While

    Return NestingLevel


    ************
    Didn't test my code but this is less "line consuming"

  • SadBugKiller (unregistered)

    Well, you asked for code (oh, the management stories are boring), you got code. Now suffer!<span idspanfor="frame" mlb_idspanflag="true" style="border: 1px solid black; padding: 0px 3px; z-index: 500; font-size: xx-small; font-family: sans-serif; position: absolute; top: 0pt; left: 0pt;">3</span>

  • Bus Raker (cs) in reply to JoeBloggs
    Anonymous:
    Anonymous:

    OMG - when will they start teaching recursion?

    Does Visual Basic even support recursion?

    Ahhh .. the vb 6.0 days relived

     

    Dim mintLevel as Integer

    Function RecursiveFunction()

    mintLevel = mintLevel + 1

    RecursiveFunction

    End Function

     

    He's obviously payed by the line.  And if that's his 'latest and greatest; .. hmmmm

  • Manni (cs) in reply to Fred Foobar

    Fred Foobar:
    I think it would go something like:
    Public Function GetNestingLevel(ByVal node As Node) As Integer
        Dim i As Integer
        i=0
        While node.Parent <> Nothing
           i=i+1
           node = node.Parent
        WEnd
        GetNestingLevel = i
    End Function

    (Haven't done VB in a while, don't syntax-flame me.)

     

    I didn't test it either, but that's about how it would work. If you're talking VB6, you probably need "Set node = node.Parent", or maybe even to create a secondary node object. VB.Net is much better in that regard.

    But yeah, VB goes out of stack space pretty easily when you're talking about recursion. Use it for integers and stuff, not for objects being passed ByVal.

    Judging by the competence level of the original "programmer", I'd say the purpose of this function is non-existent. Probably an unnecessary function to account for other shitty programming elsewhere in the system.

  • Urinal Cake Eater (unregistered) in reply to Fred Foobar

    Fred Foobar gets it.

    And extra bonus points for not having done VB for a while.

  • Bill (unregistered) in reply to GoatCheez

    Not always. A C compiler I use on a PIC does not allow recursion, or reentrant functions in general. I'd assume this means it is not making use of the stack for any local variables.

    Still, a recursive solution to this problem would be dumb in most cases.

  • Zlodo (unregistered) in reply to joe bruin
    Anonymous:
    jesuswaffle:
    Anonymous:
    OMG - when will they start teaching recursion?


    An iterative solution would work just fine here (you get C, because I don't know VB):


    Actually an interative solution is better because it won't cause a stack overflow when there are a million parent objects.  Those of you who thought of using recursion, consider yourself WTF-enabled.


    Recursion and iteration are essentially the same thing. And any compiler able to distinguish his ass from a hole in the ground will optimize a tail-call recursion into a loop anyway.

    That said, I would use a loop anyway. I posted merely for the sake of contradiction :p

    (CAPTCHA: genius. 'Nuf said)
  • Fred Foobar (cs) in reply to Fred Foobar

    WTF? I go to post, it tells me "Edit timeout expired" (HowTF long is that, anyway?), I try again, I see the post went through anyway? WTF is up with that?


  • BizTalk (unregistered) in reply to Colin
    Anonymous:
    Nobody needs more than 640 KB of RAM^H^H^H^H^H^H^H^H^H^H^H^H^H 60 levels of depth!  (I count 69 not 59 Parents as well)

    And for-loops are for the typing-endurance-challenged.


    lol omg wtf pwned..
     
     you actually counted that shit up dude?

    man get to work slacker jesus christ.

     :)

    woot null captcha!
  • merreborn (cs) in reply to GoatCheez
    GoatCheez:
    Anonymous:
    Does Visual Basic even support recursion?

    Better question would be what DOESN'T support recursion. Recursion isn't a language feature, it's a programming method. If a language has what we all call functions, then you can recurse.


    I seem to remember fairly easily getting the "Too much recursion" error, back in my HyperTalk coding days.  (I was 11 years old.  Gimme a break)

    Looks like a lot of javascript implementations have a similar issue:
    http://calculist.blogspot.com/2005/06/too-much-recursion_111886156463188710.html

    So, yeah, you're right, recursion's not really a feature, per se, but it *is* artifically limited in some high level languages.
  • Suffer (unregistered)

    Okay, Java version, with strange undocumented case handled...

    <span style="font-family: Courier New;">public int getNestingLevel( Node objNode) {</span>
    <span style="font-family: Courier New;">    int level = 0;</span>
    <span style="font-family: Courier New;">    Node currentNode = objNode;</span>
    <span style="font-family: Courier New;">    while ( currentNode.parent() != null ) {</span>
    <span style="font-family: Courier New;">       level++;</span>
    <span style="font-family: Courier New;">       currentNode= currentNode.parent();</span>
    <span style="font-family: Courier New;">    }</span>
    <span style="font-family: Courier New;">    if (level==4 &amp;&amp; objNode.id()==3382) {</span>
    <span style="font-family: Courier New;">       level = 3;</span>
    <span style="font-family: Courier New;">    }</span>
    <span style="font-family: Courier New;">    return level;</span>
    <span style="font-family: Courier New;">}<br><br><span style="font-family: Arial;">Brillant!</span><br></span>

  • bigkif (unregistered) in reply to Maxim
    Anonymous:
    Dim objNodeTesting as Node
    Dim NestingLevel as Integer

    objNodeTesting = objNode.Parent
    While not objNodeTesting = Nothing
       objNodeTesting = objNodeTesting.Parent
       If Not objNodeTesting = Nothing Then
         NestingLevel = NestingLevel + 1
       End If
    End While

    Return NestingLevel


    ************
    Didn't test my code but this is less "line consuming"

    I don't see the "3 & 4 nesting levels exception" in your code...
  • John Hensley (unregistered)

    Take note: This is what happens when an employer advertises for "CS degree or equivalent". If someone doesn't have a CS degree, they better be able to show you an outstanding portfolio of past work.

  • merreborn (cs) in reply to John Hensley

    Hypertalk's "Too much recursion" error:  (scroll down a bit)

    http://www.jaedworks.com/hypercard/HT-Masters/scripting.html#advanced

    [image]

  • Xepol (cs)

    Keep the jobs, outsource the employees.

  • Greg (unregistered) in reply to joe bruin

    Anonymous:
    jesuswaffle:
    Anonymous:
    OMG - when will they start teaching recursion?


    An iterative solution would work just fine here (you get C, because I don't know VB):


    Actually an interative solution is better because it won't cause a stack overflow when there are a million parent objects.  Those of you who thought of using recursion, consider yourself WTF-enabled.

    And, if you happen to be using .NET you want to keep your stack short... deep stacks degrade garbage collection.

  • Xepol (cs) in reply to John Hensley

    Anonymous:
    Take note: This is what happens when an employer advertises for "CS degree or equivalent". If someone doesn't have a CS degree, they better be able to show you an outstanding portfolio of past work.

    I've been through post secondary, I would be more inclined to suspect the cs degree people...

  • Adonoman (cs) in reply to GoatCheez
    GoatCheez:
    Anonymous:
    Anonymous:

    OMG - when will they start teaching recursion?

    Does Visual Basic even support recursion?


    Better question would be what DOESN'T support recursion. Recursion isn't a language feature, it's a programming method. If a language has what we all call functions, then you can recurse.

    Any language that has functions, but lacks locally-scoped variables doesn't support recursion.  Also languages where locally scoped variables are given a static lifetime. 

    Old versions of FORTRAN, and some dialects of Basic can't do recursion without some serious work-arounds (like an explicit stack).

    But I suppose you could say those languages don't support "functions" if you define functions as requiring their own stack-frame with local variables.

  • r3jjs (unregistered) in reply to GoatCheez
    GoatCheez:
    Anonymous:
    Anonymous:

    OMG - when will they start teaching recursion?

    Does Visual Basic even support recursion?



    Better question would be what DOESN'T support recursion. Recursion isn't a language feature, it's a programming method. If a language has what we all call functions, then you can recurse.


    FORTRAN?
    Ancient versions of Basic?

  • jkaiser (unregistered) in reply to JoeBloggs

    yes, it does. 

    An because Alex stated that he had the right Caps in the code.  I'm assuming that the orig. wasnt in VB.  Considering VB will Caps it for you.....thats just a guess though

  • Shaithis (unregistered) in reply to bigkif

    public function GetNestingLevel(objNode as Node)

      iNode = 0
      sId = objNode.NodeId

      while not objNode.Parent is nothing
        iNode = iNode + 1
        set objNode = objNode.Parent
      wend

      if iNode = 4 and sId = 3382 then
        iNode = 3
      end if

      GetNestingLevel = iNode

    end function

    here you go, should work the same

  • Jefffurry (cs)

    Yeah, okay, there are better ways to code that function that most compentent programmers could come up with in a few minutes. However, what I think this calls for is a different level of advice:

        Run, Greg, Run!!!
        Escape! Flee!
        Get away before they turn your brain to mush!!!

    On the other hand, sticking it out and helping those coders learn and grow and stuff is a sure but arduous route to sainthood. If that is the path you choose, then I for one respect and admire your sacrifice!

    Jeff





  • Kyle Bennett (unregistered) in reply to Maxim

    C'mon, do it the VB way...

    <span>     Public</span> <span>Function</span> GetNestingLevel(objNode <span>As n</span>ode)
             onerror goto  Done
         dim count  = -1
         do while true
           objnode = objnode.parent
              count = count    +1
             if count = 4 and objnode.nodeid = 3382 then
            count = count - 1
            endif
      loop
    Done:
     GetNestingLevel = count
    End sub

    As a bonus, it returns an error code called with a null object

    Umm, since it's VB, the forum "IDE" will fix the capitalization and indenting when I submit, this, right?






     

  • V. (cs) in reply to r3jjs

    Actually you can recurse with every language.
    In basic a recursion is a selective statement that jumps back || further in the code.

  • Jeff S (cs) in reply to Bus Raker
    Bus Raker:
    Anonymous:
    Anonymous:

    OMG - when will they start teaching recursion?

    Does Visual Basic even support recursion?

    Ahhh .. the vb 6.0 days relived

     

    Dim mintLevel as Integer

    Function RecursiveFunction()

    mintLevel = mintLevel + 1

    RecursiveFunction

    End Function

     

    He's obviously payed by the line.  And if that's his 'latest and greatest; .. hmmmm



    WTF?  Are you joking around or are you claiming this is the way "recursion" is done in VB?   I sure hope this isn't some "proof" that "VB is the WTF".

  • Richard Nixon (cs) in reply to Xepol
    Xepol:

    Anonymous:
    Take note: This is what happens when an employer advertises for "CS degree or equivalent". If someone doesn't have a CS degree, they better be able to show you an outstanding portfolio of past work.

    I've been through post secondary, I would be more inclined to suspect the cs degree people...



    Oh good - we get to have this argument again.

    sincerely,
    Richard Nixon
  • Marc (unregistered) in reply to merreborn
    merreborn:
    Hypertalk's "Too much recursion" error:  (scroll down a bit)

    http://www.jaedworks.com/hypercard/HT-Masters/scripting.html#advanced

    [image]


    If you read about the problem, appears to be an error like "Too many messages in queue"... but that most likely happens from recrusion, so they translated to make it easier to find?
  • warmachine (cs)

    When I saw the first few lines, I thought "It's a quick and dirty hack but they're acceptable." Then I saw level 60 I thought the author is completely stupid. Why generate so much work for yourself and still be left with a solution that's harder to read and maintain? What kind of thought process, what set of knowledge, could possibly come up with this?

  • MikiWatts (cs)

    What, only 60 levels? why, back in my days, when we still wrote in white on blue, we went up to 120 levels with char assembly codes and we liked it, yes siree!

  • janoc (unregistered) in reply to joe bruin
    Anonymous:

    Actually an interative solution is better because it won't cause a stack overflow when there are a million parent objects.  Those of you who thought of using recursion, consider yourself WTF-enabled.


    Educate yourself about the benefits of tail recursion and how to convert iteration to recursion and back (they are equivalent, surprise!). Then you wouldn't be WTF-enabled yourself.


  • YourName (unregistered) in reply to Zlodo

    "And any compiler able to distinguish his ass from a hole in the ground"

    If you are using a compiler that has achieved self-awareness, you sir are using a much better compiler than I. 

  • Bus Raker (cs) in reply to John Hensley

    Anonymous:
    Take note: This is what happens when an employer advertises for "CS degree or equivalent". If someone doesn't have a CS degree, they better be able to show you an outstanding portfolio of past work.

    Well, if they have a CS degree, they should be hired and paid 6 figures without looking at anything.

  • Alun Jones (unregistered) in reply to steve
    Anonymous:

    OMG - when will they start teaching recursion?

    For the answer to this question, please refer back to the last time it was asked.

Leave a comment on “Living With Parents”

Log In or post as a guest

Replying to comment #:

« Return to Article