- 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
frist ! with aliquam
Admin
Re: Wrong Answer, this sounds a lot like the original Inner-Platform Effect story. Same company?
Admin
"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.
Admin
And I'm sure they were told that they were being fired because they aren't "team players".
Admin
To clarify, that second one just reverses the string right? Does the Java string type not have a method to do that?
Admin
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.
Admin
Ah - never mind, didn't see the parenthesis in the last line.
Admin
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. :)
Admin
That's what I thought at first, but look closer at the parenthesis. It will reverse the string.
Admin
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.
Admin
I looked it up and it doesn't anyway.
Admin
Admin
"I looked it up and it doesn't anyway"
Not suprising, when would that ever come in useful for anything useful?
Admin
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.
Admin
Have you seen Java?
Admin
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).
Admin
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.
Admin
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.
Admin
I hope that you don't mean that you do String.encrypt(String.reverse(String.reverse)), and I'm just reading your post wrong!
Admin
I am trying to think how you would do fizzbuzz with strings and chars in asm?
Admin
Admin
Admin
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).
Admin
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".
Admin
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)
Admin
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.
Admin
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.
Admin
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!)
Admin
Admin
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.
Admin
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.
Admin
I think you forgot to run ROT13 on that. Twice.
Admin
Admin
"storing passwords in a database". And that's TRWTF.
Reversing them won't help you. Specially when the hackers begin eikooc as a password.
Admin
Or calculating factorial. I always thought that was the canonical example.
Admin
foreach(letter in string) StringBuilder.AppendFront(letter)
Admin
What about improvements to the recursive string reversal code?
I'm thinking:
First choice, use any built in library functions since they're already coded, tested, and optimized.
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).
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?
Admin
Admin
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".
Admin
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.
Admin
Failing to comprehend sarcasm. That's TRWTF. Unfortunately this won't help you. Specially when the jokers begin to mock you too.
Admin
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.
Admin
no the RWTF is this comment in which I comment on the fact that your comment was the RWTF
Admin
There are basically two reasons why someone might ask your opinion.
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.
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".
Admin
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(); }
Admin
You should have read all the comments. Someone already did this better than you.
Admin
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.
Admin
Admin
Admin
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.