- 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
[quote user="danixdefcon5Same I thought. Finally blocks always execute, the only way they wouldn't execute would be in situations where no code will get executed, like kill -9'ing the process, or on power down. Anyway, any critical transactions should be inside a transaction block themselves, so these two cases would cause an auto-rollback anyway!
Note: finally blocks will run even if the exception thrown is an unchecked one (i.e. RuntimeException).[/quote]
Yes, but it pays to be aware of the situations in which they will not execute.
Just last week, I wasted half a day debugging a production issue where an app, despite checking all error codes, wrapping all pertinent calls in try/catch blocks was failing silently. No error, not log, no non-zero exit status. As it turns out, a 3rd party library was graciously calling exit_group for me. Only way I was even able to find that was by doing an strace.
Admin
Thanks, I really appreciate this explanation.
Twice the benefit from today's visit!
Admin
Sorry, that's incorrect. If you call "return" from within the "try" block, "finally" is still executed - that's the point!
Admin
Is that a subtle FILE_NOT_FOUND joke?
Admin
Good idea to talk like her to really get the point across. Very effective. My big brother does that to pick up women at Chinese restaurants. With hands in the praying position he says, "Prease to be going out on date with me? I rike you."
Admin
Holy crap, DON'T catch the general exception type!
Admin
As long as you rethrow its not the end of the world.
Admin
TRWTF is this article has more sloppy typos than Min's resume's bad Engrish.
Admin
Usually databases use journaling, so the change is logged in the journal before it actually happens. When the database starts, it checks the end of the journal to make sure it wasn't killed abnormally, and rolls back or commits whatever it needs to based on the journal to make the actual database consistent
Admin
if(Virus == Very Yes)
You won, but that's not a good prize.
Admin
I've only had one bad interview experience. The lead was called in to handle the technical portion of the interview, which was made up of a few questions.
One of the questions was 'How would you detect if you had a circular reference in a linked list?' I responded that you'd have to use some type of a hash table and iterate over the list - at each element, you'd need to check the hash table to see if you'd ever seen that element before - if you had, there is a circular reference, if not, add it to the hash and continue.
The interviewer kinda smirked at me and said something along the lines of 'Well that is not efficient - is there a more efficient way to do it' to which I responded 'Not that I can think of...'
In a condescending way he suggested that there was a much better way to check, that was quicker, less memory intensive, etc etc, and gave me the hint 'What about the first item in the list??? - what can you do with it that would make this easier?' I should have seen that the solution he was driving at, even though I thought it was wrong. After a while he gave me his answer which was to just compare the first element to each additional element in the list, if you ever get back to it you have a circular reference, still smirking like he was the smartest guy that I'd ever meet.
At this point, I suggested that his solution was flawed - what if the circular reference did not point back to the first element, it would fail to detect it, such as:
A points to B which Points to C which points back to B. In this case you'll never get back to 'A'.
He ended the interview at this point and I never heard from them. Not sure if this was the reason why they did not call back or if it was just due to other reasons... or my solution was shitty... I guess I don't really care, the job was downtown, which I try to avoid like the plague.
Admin
Admin
I hope your employer is not reading this, as MS SQL Server and Sybase SQL Server parted completely in... 1998 with the introduction of SQL Server 7.0
Admin
I am good at interviews, I have gotten the last 5 interviews I went for. I can talk the talk, and have some good experience in a variety of positions. I used to really bad at interviews, didn't get a job offer after about 30 or 40 tries.
The thing is, I was a much better programmer in those days. I cared a lot about learning new stuff, would go home and program for fun. Would learn new languages for fun, and write some interesting applications. Now I don't care about it that much, don't program much outside of work, don't work as hard. But because I am good at interviews, I can get the job. Brillant!
Admin
Personally I'd give someone the benefit of the doubt on "Microsoft Solaris". I'd chalk it up to clumsy wording. Sun has a version of Solaris that runs on Intel platforms. Someone who installed Solaris on their Wintel box might carelessly refer to it as "Microsoft Solaris". Wrong? Yes. A lie? Not necessarily.
In general, I'm always cautious about ridiculing someone for making a dumb statement for fear that maybe it will turn out that their statement is correct and I only thought it was wrong because they know something that I don't. I don't want to laugh at someone and call him an idiot ... and then find out that he's right and I'm wrong. I prefer to ask for clarification before deciding someone's an idiot. A little humility can save you a lot of embarassment.
Admin
Also a finally gets executed no matter what Exception hits.
Consider:
Your code is probably wrong (not cxhecking for null), but it doesn't chew up your db handles.
kthxbye.
Admin
There is no hard and fast rule to the "Who is better, the college taught or self taught programmer?", because no 2 job candidates are exactly alike.
I've seen individuals with degrees and without who could program. I've seen individuals with degrees and without who couldn't program.
Oftentimes the best team can be a mix of those with and without degrees, assuming everyone involved can program.
Which was the point of the article. The lady in question COULD NOT program, she simply knew how to use applications that had been developed in the languages that appeared on her resume.
I once had a resume cross my desk that listed the following under programming languages: Word, Office, Excel. The gentlemen involved seemed like a nice guy, stated his love for computers over and over, and couldn't stress enough how fast of a learner he was. Did he get the job?
No, he didn't even get to interview. If he loved programming that much, he would have taken the time to learn enough to be an asset to the company.
This isn't a hero's quest, and I'm not your grandfatherly mentor who is going to peer deep down into your soul looking for all of your hidden potential that is just waiting to come out.
In fantasy, heroes emerge at the moment of crisis and somehow seem to have all the skills they need. In the real world, the men and women who have committed themselves to years of preparation and training carry the day.
Admin
You could give all of them numbered marathon jerseys, and refer to them by number instead of name. And when one screws up, you fire him on the spot. Last person standing gets the job.
Admin
If he was clairvoyant then you'd think he would have seen it coming...
Admin
I've had occasions where an interviewer has asked me a flawed question like that, and I always struggle with what to do about it. If you concede the point, then you're "admitting" that you didn't know the right answer, and presumably you're going to lose points. But if you point out the interviewer's error, there's the likelihood that he's then going to resent you and not want to give you the job.
Of course, one could argue that you wouldn't want to work for someone who refuses to admit his own mistakes and demands that everyone who works for him treat every stray remark he makes like a pronouncement from God. It all depends whether you're looking for the perfect job, or if you're currently unemployed and will take ANYTHING that pays the bills.
Admin
It claims succinctly with the example that the code always runs: http://msdn.microsoft.com/en-us/library/ke0zf0f5(VS.71).aspx
Of course the documentation does suggest you run resource clean up in there, but who reads between the lines anyway?
Admin
Admin
Requirements:
Preferences:
Then again, these places tend to be University upstarts that last for a couple of years and go bust (IMNSHO, due to a lack of perspective that you can only get from seasoned employees) so perhaps it's best they give me the warning up front.
Every single place I've ever snagged an interview with has offered me a job. The thing is, even after having others in the industry review my resume several times, I get perhaps one interview out of two dozen applications. Usually due to the above requirements... sigh Luckily, I don't plan to leave my present job any time soon! Yay decent jobs! :-P Speaking of that, back to work...
Admin
Logic doesn't work on HR types.
Admin
"Someone please educate me a bit: How does a database survive a power cycle in the middle of writing a transaction?"
Any decent database has a transaction log. When the database comes back up it checks the log and rolls back any incomplete transactions.
You're welcome.
Admin
Transactions don't mean jack until they're committed. That's the whole point. If it fails in the middle, the database will just toss the info as a bad write. If it fails the commit, same thing. If the commit succeeds, then there is no problem.
Transactional databases can't have bad or incomplete writes. That's just the way it works.
Admin
This will probably be said by several people before I finish typing this, but a "finally" block is always executed before the program continues -- even if you return or break from a loop from inside a "try" block.
For example:
In this case, conn.close() will be called whether conn.getStatus() succeeds or throws an exception. Since there is no catch clause, the exception will be propogated to the caller.
Admin
its drum n bass but...... ok was chatting with this girl 2nyt right, she was with her mum. her mom was yuck but damn she was hawt/ super sexy/ damn. shit fuck. JUNGLIST forever bitches. so hawt was her not het mom
Admin
I still work with both every day, and they're enough alike that I occasionally get confused. Compared with Oracle, mySQL, or Postgres, they're extremely close.
Admin
Depends on what you mean by efficient. This is more memory efficient:
but doesn't have the greatest worst-case execution time. If the list kept an internal record of size, this would be a lot easier.
I'd guess that the best solution would be a special case of checking a graph for cycles. And I'd also guess your solution would be the best for a typical programmer to be expected to know.
Admin
Admin
Admin
Admin
Environment.FailFast is a method implemented on the C# runtime environment object and is specifically designed to fail without executing try-finally blocks (or finalizers, for that matter). That makes it a special case.
Besides: as far as I can tell the method only came into being with the .NET 2.0 framework, whereas the article reflects on the .NET 1.0 days...
Admin
I'm not grokking this. Is there an explanation somewhere of how that would work?
Admin
Admin
Admin
Wait a second ... "Min" ... "Min"... Minuet?!
This is just an elaborate holodeck fantasy!
Admin
There's nothing better than a hash table? How about the tortoise-and-hare algorithm?
int hasCycle(node *first) { node *t = first; node *h = first; do { if (!h) return 0; h = h->next; if (!h) return 0; h = h->next; t = t->next; } while (t != h); return 1; }
Admin
I migrated all my stuff back to PostgreSQL after reading that. Mind you, there was already Sleepycat BDB and InnoDB support, but I just couldn't bear with the idea of using a DBMS built by people who think transactions are not critical. Kind of like building a big ship with no life-rafts because "we don't need them" ... oh wait, somebody did that already.
Admin
If your close() function can fail, you're doing it wrong. Any "finalising" actions, such as destructors are not supposed to ever fail. Just call close() in finally {}.
Admin
Does Min know Max?
Admin
I believe their faces turned white after continuing to argue when they asked you to move on. I don't see how arguing with an interviewer is very productive and might be a good time to let trivialities slide.
Admin
Ok:
Is that 1.0 enough for ya? Point is, unless you write it, you can't be sure what your call will do.
And special case(s) or not, it still invalidates the assertion that the final block always executes.
Admin
Admin
Well duh... finalize is for cleaning up objects before you kill them. I'd use it too, for network connections and stuff, but it isn't guaranteed to run.
Admin
try { StartTransaction(); DoStuff(); CommitTransaction(); } catch { /* handle the exception */ } finally { RollBackIfNotCommitted(); }
since you only need one commit and one rollback in total - usually in C# I just set the variable I used for the transaction object to null and call it's rollback method in the finally block only if it isn't null.
np: Meat Beat Manifesto - Radio Babylon (Beach Blanket Bimboland Mix) (Auntie Aubrey's Excursions Beyond The Call Of Duty Part 2 (Disc 2))
Admin
1.) Hire Min. 2.) ??????? 3.) Profit!
Admin
Easy now. If that's how it works when the library re-throws, they're not really re-throwing, they're creating a new exception.
It sounds like you're using .NET, so you should use: try {...} catch (Exception) { ...; throw; }
Not: try {...} catch (Exception e) { ...; throw e; }
Admin
I agree with you. Finally should be used to do things that need to get done after either your try or your catch finished. Something like this:
SqlConnection sql = new SqlConnection(); try{ sql.Open(); SqlCommand crapCommand = new SqlCommand("THIS IS A CRAP SQL CALL", sql); crapCommand.ExecuteReader(); //fails return 1; } catch{ return 0; //this ends up happening } finally{ sql.Close(); //this is what finally is for. otherwise your connection stays open foreverz }
finally happens after the return statement. You should never have a return statement in your finally, as that's just weird. I'm sure it works somehow, but it's just not right.