- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
OMG - when will they start teaching recursion?
Admin
Admin
Make the bad man stop....
Admin
Shouldn't those last two cases be 69 and 70?
(not the Greg that submitted)
Admin
of even how to do a simple loop.
Admin
An iterative solution would work just fine here (you get C, because I don't know VB):
And a larger WTF: what on earth is this supposed to do?
Admin
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.
Admin
Admin
DAMN you 61st level of nesting! You break my code!
Admin
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.
Admin
Does Visual Basic even support recursion?
Admin
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.
Admin
That would be the single case of undocumented mystery business logic.
(captcha=whiskey fitting for today)
Admin
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.
Admin
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.)
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
Admin
dammit - i always forget the 'in_between_21_and_22' nesting level
Admin
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.
Admin
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"
Admin
Well, you asked for code (oh, the management stories are boring), you got code. Now suffer!3
Admin
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
Admin
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.
Admin
Fred Foobar gets it.
And extra bonus points for not having done VB for a while.
Admin
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.
Admin
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)
Admin
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?
Admin
lol omg wtf pwned..
you actually counted that shit up dude?
man get to work slacker jesus christ.
:)
woot null captcha!
Admin
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.
Admin
Okay, Java version, with strange undocumented case handled...
public int getNestingLevel( Node objNode) {
int level = 0;
Node currentNode = objNode;
while ( currentNode.parent() != null ) {
level++;
currentNode= currentNode.parent();
}
if (level==4 && objNode.id()==3382) {
level = 3;
}
return level;
}
Brillant!
Admin
I don't see the "3 & 4 nesting levels exception" in your code...
Admin
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.
Admin
Hypertalk's "Too much recursion" error: (scroll down a bit)
http://www.jaedworks.com/hypercard/HT-Masters/scripting.html#advanced
[image]
Admin
Keep the jobs, outsource the employees.
Admin
And, if you happen to be using .NET you want to keep your stack short... deep stacks degrade garbage collection.
Admin
I've been through post secondary, I would be more inclined to suspect the cs degree people...
Admin
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.
Admin
FORTRAN?
Ancient versions of Basic?
Admin
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
Admin
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
Admin
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
Admin
C'mon, do it the VB way...
Public Function GetNestingLevel(objNode As node)
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?
Admin
Actually you can recurse with every language.
In basic a recursion is a selective statement that jumps back || further in the code.
Admin
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".
Admin
Oh good - we get to have this argument again.
sincerely,
Richard Nixon
Admin
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?
Admin
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?
Admin
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!
Admin
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.
Admin
"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.
Admin
Well, if they have a CS degree, they should be hired and paid 6 figures without looking at anything.
Admin
For the answer to this question, please refer back to the last time it was asked.