- 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
Ah, of course. Perhaps a table lookup would be the best way to do it?
id recursion_level
1 1
2 2
3 BRILLANT
4 FILENOTFOUND
(I know there's a serious point in there somewhere, but I couldn't resist tweaking you a bit.)
Admin
<FONT style="BACKGROUND-COLOR: #d3d3d3">I had one instructor that I put a certain amount of fear into. When I challenged him on deducting marks because I did not validate a name by checking that it was not numeric, he challenged me to come up with a case of a numeric name. I came up with two.</FONT>
<FONT style="BACKGROUND-COLOR: #d3d3d3">Which were ?</FONT>
<FONT style="BACKGROUND-COLOR: #d3d3d3">I mean, I certainly can't come up with any.</FONT>
FortyTwo
Admin
I have used that compiler too, and I was shocked when I found out about that restriction. If you think about it, though, it kind of makes sense: The PIC microcontrollers have precious little RAM and some of the really small ones have a hardcoded 3 element hardware stack.
Admin
I had one instructor that I put a certain amount of fear into. When I challenged him on deducting marks because I did not validate a name by checking that it was not numeric, he challenged me to come up with a case of a numeric name. I came up with two.
Which were ?
I mean, I certainly can't come up with any.
FortyTwo
Admin
I was taught recursion using the Fibonacci number sequence, factorials and tree traversal. But it is needless to say that I didn't learn anything out of that. I had prior experience in programming.
Captcha = stfu :)
Admin
I have the perfect definition of recursion.
recursion, n.: see main entry recursion.
Brillant!
Admin
In my computer science curriculum, they taught it (with the caveat of BE CAREFUL).
The problem is all these "get your certification in 6 months" courses. There's no instruction in the actual SCIENCE of things anymore. They push these know-nothings out the door with the absolute minimum knowledge to create "Hello, World".
As a collegue of mine once mentioned after I finished explaining data structures for expedited data retrieval to other devs: "Keep the science in computer science!"
The concept that this programmer used a hierarchy of objects like that, but couldn't manage them, is terrifying. Image what other code to handle that structure looks like, and what's going to happen when they hit 61 levels, then 62, then 63. Talk about job security.
Heh. Captcha is "jiggles". That beats batman any day!
Admin
Now that I think about it, anyone with half a brain would get a bit into this and say to themselves "There HAS to be a better way", and then go ask questions or do research.
I hope this person was let go soon after claiming this as their "Greatest work". Oh, the humanity!
Admin
Actually, there are (or were) some architectures with no stacks. I've worked on one; it started out as the UNIVAC 1100 mainframe series. Over time, the company morphed into what is now UNISYS, and the architecture added hardward-supported stacks.
The languages available at the time were COBOL and FORTRAN, neither of which supported recursion. (As pointed out, though, the later dialects of FORTRAN do support recursion).
Originally, the return address for functions were stored in, in effect, a static variable for the function. The assembler op code used for subroutine calls was SLJ, or store location and jump; it stored the return address at the target location, and transfered control to the target location plus one. So subroutines looked like this:
... main code:
SLJ SUB
....
SUB: 0
... body of subroutine ...
J *SUB ; jump to location stored at SUB
Obviously, trying to recurse with this architecture didn't work at all. It also meant that all code segments had to be writable.
When languages that could recurse showed up, indexing registers were pressed into service to implement stacks. Eventually, as I said, "real" stacks showed up, with a proper assembler call-subroutine instruction.
CAPTCHA: clueless. How appropriate.
Admin
yay for irrational recursion hating
i assume you've never done binary space partitioning or octrees for accelerated graphics rendering and collision detection
i'll forgive you
CAPTCHA: stfu
Admin
Okay, so you claim the recent graduates (say 21-22?) don't know basic programming principles, and also the old farts (28+ LOL) don't know OO exists. Wow, you must be that PERFECT age of 23-27??? That brillant age group that singlehandedly invented OO, recursion, and The Interwebs??? LOL the WTF is YOU. Get a clue, freak, I know people over 40 that were doing OO whilst you were busy soiling your diapers, and could still pwn you in that and CS.
Admin
Woah!
That's all I gotta say...
Yeah ummm...recursion...static variable counting instances instantiated...yeah...
Admin
Admin
Admin
Admin
Having a Degree means nothing. At the most, it means that if you are and idiot, you are an gradutated idiot.
I haven´t got a degree and I code circles around most gradutated devs around. Been doing this for the last 12 years too.
Admin
If you had a degree, you'd realize that your single example means nothing. I guess you skipped the 'stay-at-home stats' course to watch the People's Court instead.
sincerely,
Richard Nixon
Admin
Why are you using circles when you should be using iteration!?!?!
Admin
Useful for what you do? And that phrase is what separates those who understand what a college degree should be about from those who are just plodding along and getting in the way. A college degree is not job training. Just because you may not use recursion often, it is a core fundamental of Computer Science and should be taught.
If you think your "diploma program" should have only covered the set of tools you'd need to function in a job, you were looking for a certificate from ITT Tech, not an honest-to-goodness college degree.
It's scary how people are so disgusted with the idea of learning for the sake of learning.
sincerely,
Richard Nixon
Admin
The best people I have worked with, have had no CS degree, and some of the crappiest have. And lots of people in between both.
Admin
The following recursive should work just fine, and allows for handling of any number of special case business rules, separated from th main routine.
<FONT face="Courier New" size=2>public int function GetNestingLevel(Node objNode)
{
int nestLevel = 0;
if (CheckSpecialCases(objNode, ref nestLevel))
return nestLevel;
while((objNode == objNode.parent) != null)
nestLevel ++;
return nestLevel;
}
private bool function CheckSpecialCases(Node objNode, ref int nestLevel)
{
if (objNode.NodeID == 3382) { nestLevel = 3; return true; }
//else if (... //handle all other special cases here
// ...
else return false;
}</FONT>
Admin
Yay for the University of Waterloo. Except when I took my intro CS course it was CS 131 and we still used those stupid robots.
Admin
OMG how could you guys not comment on this.. i mod this +5 funny!
//captcha = "enterpisey"
Admin
Am I the only one that's scared that this part reads objNode.NodeId = 3382 and not objNode.NodeType = 3382
;)
Seriously though, as others have mentioned before: how the *beep* can you NOT think "there must be a better way..."?
Admin
My guess would be that some people are one or more of the following:
1) to proud to admit that their way is not the best.
2) to damn lazy to go look for a better way.
3) work for a manager that doesn't care and just wants it to work so they dont bother to change it
//captcha = "photogenic" heh, not this code
Admin
It is amazing how many people don't understand what a Computer Science degree is. No real computer science program would omit teaching recursion. Maybe these people are mistaking information systems degrees, vocational degrees in computer program, or whatever, for a real bachelors degree in computer science. Or else the people who they think have real CS degrees are lying about it. I really don't know. Quite scary, really.
Admin
Its either
1) You think, "There must be a better way, but I don't know what it is."
2) Your performance assessment is tied to the number of lines of code you write.
Admin
It might not work in all versions of BASIC, but I do not know of one where it will not. Caveat: Some BASICs have limited GOSUB depth.
As to your remarks about GW-BASIC, I call bullshit. I just ran the program under GW-BASIC. The recursion most definitely happened. (I traced it with TRON.) GW-BASIC allows GOSUB nesting to fill available memory. I have written recursive code in MBASIC (the parent of GW-BASIC).
Sincerely,
Gene Wirchenko
Admin
The real WTF is the fact that the guy did not get fired for this.
Admin
It is much easier than that. Set up the storage statically. There are no stack frames. Each routine has its local storage defined at compile-time at fixed addresses, and so there is only one copy.
Sincerely,
Gene Wirchenko
Admin
Stacks and Queues work very well for tree traversal without recursion. Switching between depth-first and breadth-first just becomes a list implementation change. Trying to do breadth-first using recursion seems rather counterintuitive.
Admin
Yeah, stupid Karel robot class, robot.move(), robot.pickBeeper(), robot.explodeHorriblyAndViolently()
As I recall, the exam question had you pick up some beepers, and then build a staircase or something out of them, until you ran out of beepers. Iterative works, recursive works (though it doesn't make the problem easier), but in any case there was no worry about running out of stack space since it was known that the number of beepers was like 10 or something, can Java handle 10 recursive calls?
But CS at waterloo did teach us recursion, eventually, when we were permitted to know what it was. It was still scary how some poeple managed to actually advance though, as when I was in Graphics (one of the big three) in my last year, I'd still see people wrestling with problems like comparing two floating point numbers for equality, and "what does that little star symbol do?"
captcha=truthiness (is it like a fortune teller?)
Admin
OMG thank god someone beat me to saying what. I wonder what they would do if maybe there is a change in levels. I had modified the code to interpret the programmers thought at time.
ELSE 'I should have learned recursion
Admin
Quoting restored
A numbered corporation (e.g. "123456 B.C. Ltd.") could easily be referred to as "123456". (If you do not believe that the abbreviation to the main part of the name would be used, when was the last time you used the term "Microsoft Corporation"?)
Ordering pizza. Your phone number is effectively your name. (Yes, this is a bit of a stretch, but concepts get stretched all the time.)Is this a good time to head off to the 7-11? (Or any of the variants also with two numbers?)
Sincerely,
Gene Wirchenko
Admin
In Germany, there is "4711", a famous eau-de-cologne.
In Austria, there is a mobile network operator named "3".
Admin
I know that it is important and used in some areas. It is not used much in what I do. I try to use appropriate tools. If recursion were it, I would use it, but it usually is not.
Maybe, you do not understand the distinction of "diploma" and "degree" as used at least in my neck of the woods. A diploma is a two-year program; a degree is four. Yes, some things did get left out. I can see why recursion was left out. The program was rather full.
Even more so how many think that all learning is of equal value. If you are designing a cirriculum, you have to make choices.
The program laddered into a baccalaureate program. Recursion was dealt with there.
Sincerely,
Gene Wirchenko
Admin
When my compiler needs a quart of milk, it says it's off to the Negative Four.
--Rank
Admin
I never said all "learning" was of equal value. In fact, I specifically said that recursion was a fundamental aspect of COMPUTER SCIENCE. I would discuss this further but you'd just end up deleting my post without a second thought.
Go ahead Gene, enjoy your power trip.
sincerely,
Richard Nixon
Admin
Haven't you learned anything in this thread? Don't code in circles, use recursion.
Admin
Number 5 is alive!
Admin
Perhaps those who think of recursion are smart enough to avoid language-implementations without proper tail recursion?
At least don't call it a wtf on the programmers, when its a wtf on the implementation of the programming language. Proper tail recursion is always possible and should therefor always be implemented. If I have to think of a stack and a bunch of registers, i'll go and program in assembly, thank you :-)
Admin
The bigger moron is the manager who clearly is not cut-out for a management position. If your subordinates are writing this type of code, then you need to train them, mentor them or even fire them if they can't get better.
But what you don't do is post their code to a popular site where they will certainly come across it and see what an ass-hat their manager is. Sounds like he is an insecure twit that was promoted because he was a good programmer. Shame his subordinates are going to have to endure the fact he is a lousy manager.
Admin
It is fundamental? That would mean that many things are based on it. Oddly, I rarely need these alleged derivative. That is true for many other people as well. That makes recursion not fundamental. It may be very useful in some areas, but it is not useful in all of them. A thing need not be fundamental to be useful.
As to your ad hom, complain to Alex. He made me a moderator. I did not ask for it. If he thinks that I am abusing my moderator privileges, he can easily remove them.
Sincerely,
Gene Wirchenko
Admin
You're wrong; really old Fortan didn't allow a function to call itself. It gave a "recursion error", meaning that Fortran detected that a function called itself, or that a function called another function that was already in the stack.
I don't know if current Fortran allows recursion or not.
David
Admin
Sure. Every time I see VB code I curse. Curse, curse again, recurse...
Admin
Ha Ha. What a poor argument you've made Gene. The only thing you've demonstrated is your own ignorance of the grand picture.
You said, "That would mean that many things are based on it. Oddly, I rarely need these alleged derivative."; which is laughably foolish. Who made the allegation? I said that recursion is fundamental. I never said anything about what can be directly traced to recursion. You, having a rather poor understanding of Computer Science, assume you know what is related to recursion but obviously do not - because otherwise you'd know that most of the concepts you rely on daily can be traced to the philosophical idea that recursion represents. Instead of asking me to expand on my thoughts, you immediately assumed that you had all the answers and decided to insult me.
I have complained about the fact that you are a moderator. I think it is a very bad decision based on the petty way you carry yourself. You should realize that you are not up to the task and voluntarily give up your moderator status.
sincerely,
Richard Nixon
Admin
Did Paula also write that FILENOTFOUND code? If so, can someone refresh my memory as to which forum thread contains that snippet? :)
Admin
<font face="Arial" size="6">Generator in JavaScript!</font>
The solution is to change maxLevel to something higher, like 100 million. Duh. It's so obvious.
Admin
Ok, thank you for pointing out what a billion other people have already stated... I tend to generalize when trying to make a point.... Sure, 20 years ago not everything supported recursion, but it's 2006... I shoulda stuck the qualifier "modern" in before "language" in that last sentence...
It is a very valid point though.
Admin
My first thoughts were '007' and '7 of 9'. (James Bond and Star Trek: Voyageur, respectively)