| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Next » |
|
OMG - when will they start teaching recursion? |
If objNode.NodeId = 3382 Then |
|
Make the bad man stop....
|
|
Shouldn't those last two cases be 69 and 70?
(not the Greg that submitted) |
|
of even how to do a simple loop.
|
An iterative solution would work just fine here (you get C, because I don't know VB): int get_nesting_level(node *n) {
And a larger WTF: what on earth is this supposed to do? |
|
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.
|
No recursion is necessary to make this work. I'll edit this function to make it |
|
DAMN you 61st level of nesting! You break my code!
|
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. |
Does Visual Basic even support recursion? |
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. |
That would be the single case of undocumented mystery business logic. (captcha=whiskey fitting for today) |
|
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. |
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 |
|
dammit - i always forget the 'in_between_21_and_22' nesting level
|
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. |
|
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" |
|
Well, you asked for code (oh, the management stories are boring), you got code. Now suffer!3
|
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 |
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. |
|
Fred Foobar gets it.
And extra bonus points for not having done VB for a while. |
|
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. |
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) |
|
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?
|
lol omg wtf pwned.. you actually counted that shit up dude? man get to work slacker jesus christ. :) woot null captcha! |
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. |
|
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! |
I don't see the "3 & 4 nesting levels exception" in your code... |
|
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.
|
|
Hypertalk's "Too much recursion" error: (scroll down a bit)
http://www.jaedworks.com/hypercard/HT-Masters/scripting.html#advanced ![]() |
|
Keep the jobs, outsource the employees.
|
And, if you happen to be using .NET you want to keep your stack short... deep stacks degrade garbage collection. |
I've been through post secondary, I would be more inclined to suspect the cs degree people... |
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. |
FORTRAN? Ancient versions of Basic? |
|
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 |
|
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 |
|
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 |
|
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? |
|
Actually you can recurse with every language.
In basic a recursion is a selective statement that jumps back || further in the code. |
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". |
Oh good - we get to have this argument again. sincerely, Richard Nixon |
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? |
|
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?
|
|
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!
|
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. |
|
"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. |
Well, if they have a CS degree, they should be hired and paid 6 figures without looking at anything. |
For the answer to this question, please refer back to the last time it was asked. |
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Next » |