Comment On Living With Parents

A few weeks ago, Greg moved one step closer to becoming "the man" and took a management job at a small software development company. Things were a bit of a mess (to put it nicely) and Greg thought a good place to start would be to get an idea of his subordinates' skill levels. He asked the team submit what they felt were the latest and greatest code they've written and thought he'd share with us what was the best of their best: the code had proper casing, it was indented, it not only had a "serious" sounding name (unlike eyeEyeCaptain()) but actually did what the function said it would, and only had a single case of undocumented and out-of-place mystery business logic, and so on, ... [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Re: Living With Parents

2006-05-31 15:39 • by steve

OMG - when will they start teaching recursion?

Re: Living With Parents

2006-05-31 15:40 • by W
   If objNode.NodeId = 3382 Then
GetNestingLevel = 3
Else
GetNestingLevel = 4
End If

I really don't get that. What's the reason for that?


Oh, yeah, frist, and all that.

(and captcha is batman, cool)

Re: Living With Parents

2006-05-31 15:41 • by Scott Stroz
    Make the bad man stop....

Re: Living With Parents

2006-05-31 15:42 • by greg
Shouldn't those last two cases be 69 and 70?

(not the Greg that submitted)

Re: Living With Parents

2006-05-31 15:42 • by rt
75251 in reply to 75244
of even how to do a simple loop.

Re: Living With Parents

2006-05-31 15:42 • by jesuswaffle
75252 in reply to 75244
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?

Re: Living With Parents

2006-05-31 15:48 • by 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.

Re: Living With Parents

2006-05-31 15:49 • by Xocomil
No recursion is necessary to make this work. I'll edit this function to make it
do what the code shows:

Public
Function GetNestingLevel(objNode As Node)

If Not objNode.Parent Is Nothing Then
GetNestingLevel = 0
Else
GetNestingLevel = 60
End If

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

Re: Living With Parents

2006-05-31 15:49 • by Gnictigezoink
DAMN you 61st level of nesting! You break my code!

Re: Living With Parents

2006-05-31 15:51 • by GoatCheez
75258 in reply to 75254
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.

Re: Living With Parents

2006-05-31 15:51 • by JoeBloggs
75259 in reply to 75244
Anonymous:

OMG - when will they start teaching recursion?



Does Visual Basic even support recursion?

Re: Living With Parents

2006-05-31 15:51 • by joe bruin
75260 in reply to 75252
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.

Re: Living With Parents

2006-05-31 15:51 • by Anonymous
75261 in reply to 75247
Anonymous:
   If objNode.NodeId = 3382 Then
GetNestingLevel = 3
Else
GetNestingLevel = 4
End If

I really don't get that. What's the reason for that?


Oh, yeah, frist, and all that.

(and captcha is batman, cool)


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

(captcha=whiskey fitting for today)

Re: Living With Parents

2006-05-31 15:52 • by Colin
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.

Re: Living With Parents

2006-05-31 15:52 • by Fred Foobar
75263 in reply to 75252
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

Re: Living With Parents

2006-05-31 15:52 • by steve
75264 in reply to 75254
dammit - i always forget the 'in_between_21_and_22' nesting level

Re: Living With Parents

2006-05-31 15:52 • by GoatCheez
75265 in reply to 75259
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.

Re: Living With Parents

2006-05-31 15:55 • by Maxim
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"

Re: Living With Parents

2006-05-31 15:58 • by SadBugKiller
Well, you asked for code (oh, the management stories are boring), you got code. Now suffer!3

Re: Living With Parents

2006-05-31 15:59 • by Bus Raker
75268 in reply to 75259
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

Re: Living With Parents

2006-05-31 15:59 • by Manni
75269 in reply to 75263

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.

Re: Living With Parents

2006-05-31 16:00 • by Urinal Cake Eater
75270 in reply to 75263
Fred Foobar gets it.



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



Re: Living With Parents

2006-05-31 16:00 • by Bill
75271 in reply to 75265
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.

Re: Living With Parents

2006-05-31 16:01 • by Zlodo
75273 in reply to 75260
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)

Re: Living With Parents

2006-05-31 16:01 • by Fred Foobar
75274 in reply to 75263
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?


Re: Living With Parents

2006-05-31 16:06 • by BizTalk
75275 in reply to 75262
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!

Re: Living With Parents

2006-05-31 16:06 • by merreborn
75276 in reply to 75265
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.

Re: Living With Parents

2006-05-31 16:06 • by Suffer
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!

Re: Living With Parents

2006-05-31 16:08 • by bigkif
75278 in reply to 75266
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...

Re: Living With Parents

2006-05-31 16:10 • by John Hensley
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.

Re: Living With Parents

2006-05-31 16:14 • by merreborn
75280 in reply to 75279
Hypertalk's "Too much recursion" error:  (scroll down a bit)

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


Re: Living With Parents

2006-05-31 16:14 • by Xepol
Keep the jobs, outsource the employees.

Re: Living With Parents

2006-05-31 16:16 • by Greg
75282 in reply to 75260

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.

Re: Living With Parents

2006-05-31 16:16 • by Xepol
75283 in reply to 75279

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...

Re: Living With Parents

2006-05-31 16:17 • by Adonoman
75284 in reply to 75265
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.

Re: Living With Parents

2006-05-31 16:18 • by r3jjs
75285 in reply to 75265
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?

Re: Living With Parents

2006-05-31 16:19 • by jkaiser
75286 in reply to 75259
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

Re: Living With Parents

2006-05-31 16:20 • by Shaithis
75287 in reply to 75278
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

Re: Living With Parents

2006-05-31 16:22 • by Jefffurry
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





Re: Living With Parents

2006-05-31 16:24 • by Kyle Bennett
75289 in reply to 75266
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?






 

Re: Living With Parents

2006-05-31 16:25 • by V.
75290 in reply to 75285
Actually you can recurse with every language.
In basic a recursion is a selective statement that jumps back || further in the code.

Re: Living With Parents

2006-05-31 16:26 • by Jeff S
75291 in reply to 75268
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".

Re: Living With Parents

2006-05-31 16:26 • by Richard Nixon
75292 in reply to 75283
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

Re: Living With Parents

2006-05-31 16:27 • by Marc
75293 in reply to 75280
merreborn:
Hypertalk's "Too much recursion" error:  (scroll down a bit)

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




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?

Re: Living With Parents

2006-05-31 16:28 • by warmachine
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?

Re: Living With Parents

2006-05-31 16:28 • by MikiWatts
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!

Re: Living With Parents

2006-05-31 16:28 • by janoc
75296 in reply to 75260
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.


Re: Living With Parents

2006-05-31 16:29 • by YourName
75297 in reply to 75273
"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. 

Re: Living With Parents

2006-05-31 16:29 • by Bus Raker
75298 in reply to 75279

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.

Re: Living With Parents

2006-05-31 16:30 • by Alun Jones
75299 in reply to 75244
Anonymous:

OMG - when will they start teaching recursion?



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

« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Add Comment