- 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
Here's some more, then:
http://www.microsoft.com/technet/scriptcenter/guide/sas_vbs_kove.mspx
Cheers,
Nathan
Admin
Recursion (unlike, say, iteration) is a fundamentally important construct. It's also conceptually simple. How can they not teach it? It should also arise as a natural consequence of other essential teachings (for example, traversing trees is naturally recursive).
Admin
...as soon as they start teaching recursion!
Admin
No way did he count it up! He wrote a recursive function to count it for him.
Admin
Conceptually simple, but many have trouble getting it straight. Tree traversal was not something we got into.
Sincerely,
Gene Wirchenko
Admin
Disgusted? Hardly. Aware of the fact that even entry-level jobs require a very specific skillset and the fact that most employers don't care for on-the-job learning? Hell yeah. I'm almost done with my CS degree, and sometimes it's scary how many things ARE left out for the sake of PC nonsense classes.
Admin
Alright, I think we all need to retake a lesson in logic class. While most here blaber on about iteration being more efficient than recursion and offer equivalent algorithms in C, few are reading the code correctly. At first, I admit based on looking at it, the algorithm seems to warent a recursive solution, but OneMHz and W above him are right. The code reads :
etc. What I misread and I think everyone is misreading is the Not in front of the objNode.Parent is Nothing (if you did catch it, you are probably just going on the assumption that the function is supposed to do something useful, like counting the depth of a node in a tree). If Nothing means what I think it means (read VBspeak for NULL), then the ElseIf blocks are exectued when objNode.Parent Is Nothing (objNode.Parent == NULL). Because objNode.Parent is Nothing, objNode.Parent.Parent is Nothing as well. I don't really know VB too well, but assuming this to be the case, every elseif evaluates to false, so the only two blocks to ever see execution are the first and last. Thus W's code is equivalent, and everyone else's isn't. Please let me know if I'm wrong, which is probably the case, seeing as how so many of you want to offer recursive/iterative solutions. Also, I don't know the true meaning of Nothing in VB, this is all based on the above assumption.Admin
Your understanding of VB's meaning of nothing is correct. Your understanding of how this whole obscene block of craptastic VB-ness won't work as intended (double-WTF or mistake in anonymization? who knows) is also correct.
However, you're a bit late. I think your point of it only hitting the first and last blocks was originally pointed out on page 2 ...
But, I might be wrong.
Admin
But do look it up anyway. VB6's documentation for nothing, oops, Nothing was quite entertaining.
"What are you reading?" "Nothing."
Sincerely,
Gene Wirchenko
Admin
<clue_challenged>
<sarcasm>
Ack. Good point. I must have unconsciously gotten used to letting VB fix my capitalization for me.
</sarcasm>
</clue_challenged>
Disclaimer: nothing is to be implied or inferred by my use of <sarcasm /> tags; they are only there for those that are too clue challenged to correctly implement a sarcasm detector, or, having a sarcasm detector, do not have its sensitivity set high enough.
Pre-post edit: Is this ability to use bbcode new to CS2? I don't seem to remember it before. Or, maybe it was just masked by the general WTF-ness of CS1. Oh, yeah, I use that evil firefox thingy.
Admin
Fact 1: It doesn't work (well actually I don't have the spec, but based on the evidence this thing doesn't work)
Fact 2: It has nothing to do with aesthetics... It has to do with maintainability (refer to Fact 1)
Someone mentioned they could see how this would happen. It started off with well we have no more than 4 parents and a special case, on day 2 they added on 5 parents, etc... Yeah sorry I don't but it. If I thought it had only 4 parents I still would have written a loop. Or if I came in at day x (where x > 5) I would have rewritten it correctly. Shorter more "aesthetic" code is usually easier to maintain.
Admin
Actually, COBOL (at least up to COBOL85) did support functions, but not recursion.
Admin
"Fact 1: It doesn't work (well actually I don't have the spec, but based on the evidence this thing doesn't work)"
Well, as much as I could extract from the beginning Statement
"He asked the team submit what they felt were the latest and greatest code they've written" - I think that it worked... I assume it had to return "0" if it's a child-Node... "60" Otherwise ;-)... And because they surely presented some Code that worked - I think it's some /very volatile/ part of code... Like otherwise encapsulated in many "if(1=0)"-Blocks... And I assume, that there have been many other parts of "business logic" packed in this function in the meantime.
Fact 2: It has nothing to do with aesthetics... It has to do with maintainability (refer to Fact 1)
You are /generally/ right... for shure.
But some special cases do exists, where one would say "WTF" at the first impression - but "I understand" when knowing the backgrounds.
"Someone mentioned they could see how this would happen. It started off with well we have no more than 4 parents and a special case, on day 2 they added on 5 parents, etc... Yeah sorry I don't but it. If I thought it had only 4 parents I still would have written a loop. Or if I came in at day x (where x > 5) I would have rewritten it correctly. Shorter more "aesthetic" code is usually easier to maintain."
You are right again... There are only 10b solutions - iterating or recursion. So the one and only chance, why they did it like this is IMHO that they solved it per recursion/iteration - but had to change the implementation for new business logic every 10 minutes or so... so that they fell back to "make 100 if's and if somebody wants something new in 10 minutes - something like "If there are exactly 43 parents and my objectid=12345 - then return 24 - but don't do too many checks for parents"...
Or maybe they just wanted to ensure a sleepless night for the new IT-Manager... Something like a bad joke ;-)
Admin
How date subtraction should work may depend on your problem domain. I used to work with a bank loan application and each customer had its own set of rules how to calculate date subtraction. For example that the difference between two last day of month was always a multiple of 30, so Feb 28 - Jan 31 should be 30, even though its 28 days inbetween. We had a date math library with different methods depending on how it should be done.
Admin
the recursion here would be another WTF.. a minor one
Admin
Then may I ask, what was this diploma you did?
If it didn't cover basic data structures or fundamental concepts?
Admin
KFC college ... of course ...
---
captcha text = STFU !
Admin
Test for the special cases first in a switch-style statement and the do the loop or recursion for the normal cases. Unless (horror) the special cases can be normal at different depths in the hierachy :O
Admin
it's your fault this site exists.
Admin
His and CPound's.
Admin
I'm tired, so I don't read all posts before I quote this... But... If the post you quoted wasn't meant to be ironic, I'll be... Dunno, really, but I'd be very surprised... And that exact figure of 28 should be a giveaway too... Or? WTF???
Hang on... Was YOUR quote also to read ironically? WTF!!!
Admin
No one else found this funny :)
Admin
Admin
If looping was a flathead screwdriver, and recursion was a phillips head screwdriver; this developer used a hammer.
Admin
I once wrote an iterative code block to return the depth of a node in a B-tree. Once.
Admin
Computer Science degrees ensure that the code block above is written the exact same way, but with lots more comments. Why, I could rewrite this using Java Struts, Actuate, BIRT, a couple of beans, MONO, C#, an ActiveX control and some model cement glue and I don't have a CS degree...
Admin
I'll do you one better...
That was easy. Fall into the GAP.
Admin
That's not true. It needs some support on the language side (specifically, it needs a stack, or else some sort of RISC-y register windowing thing), and historically some languages didn't support it. (Don't think qbasic did).
Admin
You know, when you stare at it long enough, it stops looking like code.
Admin
But if the programmer doesn't support the language feature... then you can only CURSE
Admin
I recall someone telling me that some C++ (Edison?) compiler acutally sais:
"The compiler was unable to detect any of your errors"
instead of the more usual
"Compiled with 0 errors and 0 warnings"
Compilers may be getting there :)
Admin
Admin
The function does not even work because of the
"If Not objNode.Parent is Nothing" - if there is a parent return 0. If there is no parent then thing is going to throw an exception. So all that code and it either returns 0 or throws an exception or causes an error if VB6.
Admin
Objects passed ByVal are reference pointers, which makes the parameters essentially just.... Integers! ;-)
Admin
Boy, looks like I have stepped into the wrong site! The reading was definetly interesting though, thanks all!! Why again is this site named living with parents????
Admin
what happened if BASIC was typed in lower case?
Admin
May I ask why? recursion would lead to an easy to read and trivial to debug code here.
Admin
28, and that was the focus of my entire Computer Science degree--OOP using C++.
Of course, right after I graduated they switched to Java, which would've been far more useful to me in the long run. That's the problem with universities; they can't keep up with the pace of modern technology. My networking class used Novell Software on a Windows 3.1 computer, and my Java class was trying to run JDeveloper on Pentium 75s. It was baaaaaad....
Admin
That is apPARENTly so...
Admin
You generalize and what you said doesn't even apply to C. On Z8 Encore! (an 8 bit micro from Zilog), their C compiler supports static frames (for speed). If your project has static frames enabed, then no recursion is possible since once you enter a function, the frame that holds all the automatics (parameters and locals) has already been allocated at a fixed position by the linker, which analyzes the call tree to determine what can overlap with what else. In such a case, you have to declare the function as recursive in order to have it use dynamic (stack-allocated) frames. Like this:
The first one will give a linker warning (a WTF in itself -- should be an error) if you use static frames, the second one won't (and will actually work).
TRWTF is that Zilog's tools don't do any tail-recursion detection/optimization :( Heck, they occasionally generate incorrect assembly for quite "benign" code. But hey! - the tools are free as in beer... sobs...
Cheers!
Admin
Stupid errors...