• (nodebb)

    Ah, the basics of OOP are very hard to understand; I struggled myself for a few hours.

    Addendum 2024-11-19 06:44: Just kiddin'. By first thought about C with classes was "Finally I don't have to prefix every function"; OOP is pretty much the natural thing how to order and structure interactions with data - a subject or object does an action, it ain't the other way around.

  • (nodebb)

    Of course the documentation says the parameter is a "group number" but the name of the parameter is just "group". I suppose referring to both of those things as an e.g. "GroupId" would be just waaaay too hard for these bozos.

  • Vera (unregistered)

    Did something like this by accident once, back when I was first learning Java. Had this object representing a UI window, and I wanted to add a function to close it from some other object, named it public void close(), had it call the setVisible(false) function and tried it out. Turns out that I was using the same name as a deprecated function that setVisible() was using, so it looped until the stack overflowed.

  • (nodebb)

    This is a very lame attempt at making CPU work at full capacity, because the stack overflows way too quickly.

    Please follow best practices and use timed while loops, which also have the added benefit of not crashing the application.

  • Lothar (unregistered)

    FWIW: In Java a static method overloading a static method doesn't make sense, because - as you can see in the code block itself - you have to specifiy the class name, i.e. even if there is a SubGroupEntity.find(String) that particular method will end up in an endless loop.

  • Argle (unregistered)

    "Antediluvian?" I haven't seen that word used in a very long time. Marvelously fitting, though.

  • markm (unregistered)

    This looks to me like someone read Donald Knuth's The Art of Computer Programming (from the 1960's and 1970's) and tried to implement his recursive algorithm for searching a tree or a sorted array - but missed both the key steps. Knuth's method was to divide the search area in two at each step and recurse into it, until it either finds the searched-for key or has narrowed the search to one item that is closest to where the key would be if it was in there.

    For an example, if you have an array of structures sorted by the key you are searching for (in pseudo-c rather than the assembly language Knuth preferred):

    Find(key, start_index,last_index) { If (start_index == last_index) return start_index Take the middle of the array mid_index = (start_index + last_index)/2 record = array[mid_index] If (record.key is less than key) Find(key, start_index, mid-index - 1) If (record.key is greater than key) Find(key,mid-index + 1,last_index) return mid_index }

    If I was going to use this, I'd do a bit more work to make sure it doesn't

    So the person who wrote that code in the original post:

    1. Forgot to divide the search area.
    2. Forgot to end the search and pass the result back up the chain of recursion.
    3. Probably forgot that the function he called does the complete search, either with Knuth's algorithm or one better suited to the database it is searching.
  • DB guy (unregistered) in reply to Lothar

    @Lothar - Method overloading is when you have a method with the same name that takes different arguments. It absolutely makes sense in a static context.

Leave a comment on “Recursive Search”

Log In or post as a guest

Replying to comment #:

« Return to Article