• woliveirajr (unregistered)

    frist ! with aliquam

  • (cs)

    Re: Wrong Answer, this sounds a lot like the original Inner-Platform Effect story. Same company?

  • (cs)

    "And the only reason that release went out was they had fired the QA group for repeatedly rejecting Charles' and Terry's high quality work."

    Hooray, lets fire people for doing their jobs well. I have seen this shit myself in the not-so-distant past. People who don't work in IT wonder why I became so jaded.

  • Anon (unregistered) in reply to CaptainCaveman
    CaptainCaveman:
    "And the only reason that release went out was they had fired the QA group for repeatedly rejecting Charles' and Terry's high quality work."

    Hooray, lets fire people for doing their jobs well. I have seen this shit myself in the not-so-distant past. People who don't work in IT wonder why I became so jaded.

    And I'm sure they were told that they were being fired because they aren't "team players".

  • Not a Java programmer (unregistered)

    To clarify, that second one just reverses the string right? Does the Java string type not have a method to do that?

  • John Galt (unregistered)

    Won't that Java snippet run forever in an infinite loop if you supply it with a string that's more than 1 character long? It looks like all it's doing is moving the first character to the end of the submitted string over and over again.

  • John Galt (unregistered) in reply to John Galt
    John Galt:
    Won't that Java snippet run forever in an infinite loop if you supply it with a string that's more than 1 character long? It looks like all it's doing is moving the first character to the end of the submitted string over and over again.

    Ah - never mind, didn't see the parenthesis in the last line.

  • (cs) in reply to Not a Java programmer
    Not a Java programmer:
    To clarify, that second one just reverses the string right? Does the Java string type not have a method to do that?

    Yes, it reverses the string. And, it doesn't matter if there is a built-in for that; this was a coding challenge to gauge the ability of the interviewee to see if they could tell from looking at the code what the code should be doing - well, I hope that's what it is, anyway. :)

  • Xenon Xavior (unregistered) in reply to John Galt
    John Galt:
    Won't that Java snippet run forever in an infinite loop if you supply it with a string that's more than 1 character long? It looks like all it's doing is moving the first character to the end of the submitted string over and over again.

    That's what I thought at first, but look closer at the parenthesis. It will reverse the string.

  • (cs)

    I once interviewed a "C++ programmer" who couldn't pass FizzBuzz. He didn't even know how to do logical negation (!).

    Less amusing, I had an assembly programmer who did pass it, but without using the mod operator or even attempting to roll his own. He had to use string conversion and tested for the decimal point.

  • Not a Java programmer (unregistered) in reply to dohpaz42

    I looked it up and it doesn't anyway.

  • (cs) in reply to John Galt
    John Galt:
    Won't that Java snippet run forever in an infinite loop if you supply it with a string that's more than 1 character long? It looks like all it's doing is moving the first character to the end of the submitted string over and over again.
    Is this the John Galt from Stack Overflow?
  • bob (unregistered) in reply to Not a Java programmer

    "I looked it up and it doesn't anyway"

    Not suprising, when would that ever come in useful for anything useful?

  • WC (unregistered) in reply to hoodaticus

    No, it's the John Galt from Atlas Shrugged.

    I read that code snippet and thought, "Is that really a recursive function to reverse a string?" ... Yup, apparently it is. Wow.

  • bencoder (unregistered) in reply to bob
    bob:
    "I looked it up and it doesn't anyway"

    Not suprising, when would that ever come in useful for anything useful?

    Have you seen Java?

  • (cs) in reply to WC
    WC:
    No, it's the John Galt from Atlas Shrugged.

    I read that code snippet and thought, "Is that really a recursive function to reverse a string?" ... Yup, apparently it is. Wow.

    Reversing a string is a simple analogy for describing recursive functions. It's an easy concept to understand, and just as simple to implement, and it demonstrates recursion in an easy to understand way. Usually this sort of exercise is done in a beginner programming class (at least, it was for me back when I took beginning programming in college).

  • resmoker10 (unregistered) in reply to bob

    Actually that's something that bugs me about C# that it doesn't have a string reverse function. For some reason Microsoft didn't see fit to add a string.Reverse() method and I have had to roll my own.

    Password reversal is a useful when storing passwords in a database to obscure them from potential attackers. More recently what with all the hacking stories in the news I have increased my precautions by reversing the strings two times before inserting them into the password table so they are double encrypted.

  • (cs)

    We're stuck on 1.5, so:

    return s==null || s.length()<2 ? s : new StringBuilder(s).reverse().toString();

    Though I once got: what if you couldn't use StringBuilder?

    I didn't want to work for the guy so I said I'd hire a junior programmer to handle the piddle work so I could get on with solving the company's real problems.

  • (cs) in reply to resmoker10
    resmoker10:
    Actually that's something that bugs me about C# that it doesn't have a string reverse function. For some reason Microsoft didn't see fit to add a string.Reverse() method and I have had to roll my own.

    Password reversal is a useful when storing passwords in a database to obscure them from potential attackers. More recently what with all the hacking stories in the news I have increased my precautions by reversing the strings two times before inserting them into the password table so they are double encrypted.

    I hope that you don't mean that you do String.encrypt(String.reverse(String.reverse)), and I'm just reading your post wrong!

  • (cs) in reply to hoodaticus
    hoodaticus:
    I once interviewed a "C++ programmer" who couldn't pass FizzBuzz. He didn't even know how to do logical negation (!).

    Less amusing, I had an assembly programmer who did pass it, but without using the mod operator or even attempting to roll his own. He had to use string conversion and tested for the decimal point.

    I am trying to think how you would do fizzbuzz with strings and chars in asm?

  • (cs) in reply to Mason Wheeler
    Mason Wheeler:
    Re: Wrong Answer, this sounds a lot like the original Inner-Platform Effect story. Same company?
    Sadly, I doubt it. This anti-pattern is all too frequent in IT, as so many developers see it as a fun and challenging way to avoid the boring task of thinking about data structures.
  • (cs) in reply to dohpaz42
    dohpaz42:
    resmoker10:
    Actually that's something that bugs me about C# that it doesn't have a string reverse function. For some reason Microsoft didn't see fit to add a string.Reverse() method and I have had to roll my own.

    Password reversal is a useful when storing passwords in a database to obscure them from potential attackers. More recently what with all the hacking stories in the news I have increased my precautions by reversing the strings two times before inserting them into the password table so they are double encrypted.

    I hope that you don't mean that you do String.encrypt(String.reverse(String.reverse)), and I'm just reading your post wrong!

    That's exactly what he meant - you missed the implied "</wink>"

  • somechick (unregistered) in reply to hoodaticus
    hoodaticus:
    I once interviewed a "C++ programmer" who couldn't pass FizzBuzz. He didn't even know how to do logical negation (!).

    I see what you did there ...

    I still say my favorite interview question I was ever asked was "What is this '|' symbol?" 'A Pipe' "What is it used for?" 'It's a pipe.' My brain went blank for a couple seconds there and then I explained what pipes do on the unix command line (in more detail than was necessary, from what my boss said afterwards, as they weren't looking for the term FIFO, oddly enough).

  • NickS (unregistered)

    Oh, that idea's floating around? Here's what you should do: Shoot it down, take it outside, put it on the hood of whoever thought it up, light it on fire, and leave it as a warning to others who attempt to have similar "ideas".

  • (cs)

    Re Wrong Answer: I think I used to work there. Running away, screaming in terror, would indeed be the sane course of action - the founder used to program, way back in the 1990s, and most of such brillant inventions were his. (And yes, you were right, that inner platform turned into a Lovecraftian nightmare no-one dared disturb)

  • Anon (unregistered)

    Other than this being a reverse function, since I am not a java developer what would be the proper way to reverse a string since the interview question explicitly asks how you would improve on the function.

  • (cs)

    How come there isn't a caffeinated soft drink called FizzBuzz?

    Maybe the name is TOO clever. Self-identifying geeks are content to suck down a half-dozen Bawls per day.

  • Machtyn (unregistered) in reply to dohpaz42
    dohpaz42:
    resmoker10:
    Actually that's something that bugs me about C# that it doesn't have a string reverse function. For some reason Microsoft didn't see fit to add a string.Reverse() method and I have had to roll my own.

    Password reversal is a useful when storing passwords in a database to obscure them from potential attackers. More recently what with all the hacking stories in the news I have increased my precautions by reversing the strings two times before inserting them into the password table so they are double encrypted.

    I hope that you don't mean that you do String.encrypt(String.reverse(String.reverse)), and I'm just reading your post wrong!

    Actually, I think he means String.reverse(String.reverse). He didn't mention anything about an encrypt in "Password reversal is a useful when storing passwords..."

    String.reverse(String.reverse("I then had a good laugh because they are now double encrypted")). (They'll never guess what I said now!)

  • Abso (unregistered) in reply to Anon
    Anon:
    Other than this being a reverse function, since I am not a java developer what *would* be the proper way to reverse a string since the interview question explicitly asks how you would improve on the function.
    I'm not a java developer either, but I suspect the answer is to use a loop instead of recursion.
  • (cs)

    I'm currently working on an "enterprise" application with such a meta-database.

    I just had to write a query that had a dozen table joins in it. The join criteria is a bunch of strings. It is slow as hell, but there is nothing I can do about it.

    At least a few of the joins are on the same table with different criteria. They store the relations in a single column of a table. A lot of the tables have columns with names like ATTRIB_001 up to ATTRIB_100+.

    Fortunately, I don't have to work at this low of a level in this application much.

  • Hanoi 4 ever (unregistered) in reply to dohpaz42
    dohpaz42:
    WC:
    No, it's the John Galt from Atlas Shrugged.

    I read that code snippet and thought, "Is that really a recursive function to reverse a string?" ... Yup, apparently it is. Wow.

    Reversing a string is a simple analogy for describing recursive functions. It's an easy concept to understand, and just as simple to implement, and it demonstrates recursion in an easy to understand way. Usually this sort of exercise is done in a beginner programming class (at least, it was for me back when I took beginning programming in college).

    Reversing a string is a poor example of recursion, as it's so obviously easier to do with a loop. Use something like quicksort or a tree-traversal.

  • (cs) in reply to Machtyn

    I think you forgot to run ROT13 on that. Twice.

  • (cs) in reply to Helix
    Helix:
    hoodaticus:
    I once interviewed a "C++ programmer" who couldn't pass FizzBuzz. He didn't even know how to do logical negation (!).

    Less amusing, I had an assembly programmer who did pass it, but without using the mod operator or even attempting to roll his own. He had to use string conversion and tested for the decimal point.

    I am trying to think how you would do fizzbuzz with strings and chars in asm?

    It wasn't a machine coder's position. He was using .NET.

  • Anon (unregistered) in reply to resmoker10

    "storing passwords in a database". And that's TRWTF.

    Reversing them won't help you. Specially when the hackers begin eikooc as a password.

  • Anon (unregistered) in reply to Hanoi 4 ever
    Hanoi 4 ever:
    dohpaz42:
    WC:
    No, it's the John Galt from Atlas Shrugged.

    I read that code snippet and thought, "Is that really a recursive function to reverse a string?" ... Yup, apparently it is. Wow.

    Reversing a string is a simple analogy for describing recursive functions. It's an easy concept to understand, and just as simple to implement, and it demonstrates recursion in an easy to understand way. Usually this sort of exercise is done in a beginner programming class (at least, it was for me back when I took beginning programming in college).

    Reversing a string is a poor example of recursion, as it's so obviously easier to do with a loop. Use something like quicksort or a tree-traversal.

    Or calculating factorial. I always thought that was the canonical example.

  • (cs) in reply to Anon
    Anon:
    Other than this being a reverse function, since I am not a java developer what *would* be the proper way to reverse a string since the interview question explicitly asks how you would improve on the function.
    Psuedocode:

    foreach(letter in string) StringBuilder.AppendFront(letter)

  • Jeff (unregistered)

    What about improvements to the recursive string reversal code?

    I'm thinking:

    1. First choice, use any built in library functions since they're already coded, tested, and optimized.

    2. Don't use recursion since that's a lot of overhead and you could get a possible stack overflow if the string was long. (Can you even get stack overflows in C#? I honestly haven't had one in many many years).

    3. As a coding exercise, off the top of my head I'd probably use a one character buffer and swap characters from the outside to the inside. Ala:

    strToRev="CodeTest";

    for(int i=0; i< strToRev.length() / 2; i++) { int farCharPosition = strToRev.length()-i-1; char buf = strToRev[farCharPosition]; strToRev[farCharPosition] = strToRev[i]; strToRev[i] = buf; }

    Thoughts?

  • (cs) in reply to Abso
    Abso:
    Anon:
    Other than this being a reverse function, since I am not a java developer what *would* be the proper way to reverse a string since the interview question explicitly asks how you would improve on the function.
    I'm not a java developer either, but I suspect the answer is to use a loop instead of recursion.
    That's what I would've done.
  • Abso (unregistered) in reply to Hanoi 4 ever
    Hanoi 4 ever:
    dohpaz42:
    WC:
    No, it's the John Galt from Atlas Shrugged.

    I read that code snippet and thought, "Is that really a recursive function to reverse a string?" ... Yup, apparently it is. Wow.

    Reversing a string is a simple analogy for describing recursive functions. It's an easy concept to understand, and just as simple to implement, and it demonstrates recursion in an easy to understand way. Usually this sort of exercise is done in a beginner programming class (at least, it was for me back when I took beginning programming in college).

    Reversing a string is a poor example of recursion, as it's so obviously easier to do with a loop. Use something like quicksort or a tree-traversal.

    This wasn't meant as an example, though. It makes sense for them to use something that would be easier to do with a loop, because then they can look for people whose answer to the second question is "use a loop".

  • Hortical (unregistered) in reply to Sutherlands
    Sutherlands:
    Psuedocode:

    foreach(letter in string) StringBuilder.AppendFront(letter)

    Consider the possibility that the StringBuilder uses a char[] internally.

    Consider the possibility that every time you insert a char at the beginning, all the other chars that have been added have to be moved over a space. Every time.

  • Dank (unregistered) in reply to Anon
    Anon:
    "storing passwords in a database". And that's TRWTF.

    Reversing them won't help you. Specially when the hackers begin eikooc as a password.

    Failing to comprehend sarcasm. That's TRWTF. Unfortunately this won't help you. Specially when the jokers begin to mock you too.

  • (cs)

    EAV (Entity, Attribute Value) data structures have real uses in many application, unfortunately they seem to be abused much more often than used properly.

    There are a complete set of transparent optimizations that can be done in this environment, that are much harder to implement with table/column fixed formats.

  • resmoker10 (unregistered) in reply to Dank

    no the RWTF is this comment in which I comment on the fact that your comment was the RWTF

  • Jay (unregistered)

    There are basically two reasons why someone might ask your opinion.

    1. On rare occasions, it may be because the asker has not made up his mind and believes that insights or suggestions that you have may help him to arrive at a better decision.

    2. Most of the time, the asker has already made up his mind and is looking for someone else to validate his decision.

    I regularly have conversations with my boss where he asks, "What do you think we should do about X?" Then I say what I think we should do. Then he explains to me why he's already decided to do something else.

    Still, it's better then the way we used to work. That was, he would make a decision about something. Then he would tell me to come up with a solution to whatever problem, without telling me what his idea was. I would spend days writing up a design document or coding a program or whatever. Then he would yell at me because I hadn't done it the way he wanted. I thought of it as "the I'm-thinking-of-a-number management style".

  • Dank (unregistered) in reply to Dank

    String reverseString(String input) { if (input == null || input.length < 2) return input;

    char[] inp = input.toCharArray(); StringBuilder output = new StringBuilder();

    for (int i = inp.length - 1; i >=0 i--) { output.append(inp[i]); } return inp.toString(); }

  • Hortical (unregistered) in reply to Dank
    Dank:
    String reverseString(String input) { if (input == null || input.length < 2) return input;

    char[] inp = input.toCharArray(); StringBuilder output = new StringBuilder();

    for (int i = inp.length - 1; i >=0 i--) { output.append(inp[i]); } return inp.toString(); }

    You should have read all the comments. Someone already did this better than you.

  • (cs) in reply to Hanoi 4 ever
    Hanoi 4 ever:
    dohpaz42:
    WC:
    No, it's the John Galt from Atlas Shrugged.

    I read that code snippet and thought, "Is that really a recursive function to reverse a string?" ... Yup, apparently it is. Wow.

    Reversing a string is a simple analogy for describing recursive functions. It's an easy concept to understand, and just as simple to implement, and it demonstrates recursion in an easy to understand way. Usually this sort of exercise is done in a beginner programming class (at least, it was for me back when I took beginning programming in college).

    Reversing a string is a poor example of recursion, as it's so obviously easier to do with a loop. Use something like quicksort or a tree-traversal.

    Recursion is usually a precursor to larger algorithms, such as sorting. If you can't understand recursion, you have no hope of quick sort or tree traversal.

  • (cs) in reply to resmoker10
    resmoker10:
    More recently what with all the hacking stories in the news I have increased my precautions by reversing the strings two times before inserting them into the password table so they are double encrypted.
    +5
  • (cs) in reply to hoodaticus
    hoodaticus:
    resmoker10:
    More recently what with all the hacking stories in the news I have increased my precautions by reversing the strings two times before inserting them into the password table so they are double encrypted.
    +5
    Here, here! They should add this to the OWASP secure development guide.
  • (cs)

    I have encountered "meta-databases" at least four times in my career. I will never understand why everybody thinks they're such a wonderful, revolutionary idea. I know there are some legitimate applications for EAV but these are not them.

    One project I worked on had to do so many JOINs just to get a single record out of their database that they exceeded MySQL's JOIN limit (61). Twice. They had to write code to keep track of the # of joins while building the query, and break the query into separate pieces when necessary. It goes without saying that the queries also took about 100 times longer than necessary, and data integrity was a complete nightmare.

Leave a comment on “Three for Three, Recursion Threads, and Wrong Answer”

Log In or post as a guest

Replying to comment #:

« Return to Article