- 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
Admin
Ineptitude times 2 - for one, not knowing what
raise
does. For two, not knowingraise
is a statement, not a commandAdmin
Why do I see unicorns after double click on " whatchacallits"?
Admin
Unicorns and Rainbows! That's hilarious!!
Admin
This kind of error happens if you forget the last branch in an if-else-filenotfound block.
Admin
Finally, it dawns on me. The REAL WTF is the developer not sniffing this out during the interview. How many times have we seen "dev gets hired by by small business with a 1 rock star/genius/Ten X developer whose code is a pile of WTFs". Now that's a skill you don't get taught in school!
Admin
Dev-Burt. Haha. Did CTO-Burt have pointy hair?
Admin
There are far too many people in the world who don't understand that going for a job interview is just as much your chance to interview the company as it is for them to interview you.
Admin
It's "chimed in" not "timed in" -- I've never seen that mixup before! :)
Admin
Because Remy wrote it, and he likes to cornify the story.
Admin
Did Dev-Burt go by another name and live in Asia? I worked with a guy just like him.
Admin
Why am I reminded of that old sitcom Soap? :-P
Admin
Try double-clicking "Cold fusion" in "Cold fusion became synonymous with junk science" sentence in yesterdays article "Coldly fused", or "undocumented" in the last paragraph in the "Just in case" article two days ago.
Admin
Confused? You won't be, after...
Oh, who am I kidding. You'll still be confused. You'll always be confused.
Admin
Missed opportunity to name this "A Tale of Two Burts"
Admin
Maybe so, but there is also the: "This job meets my minimum salary requirements while I determine if I really want to work here and if there may be potential for growth" aspect of many of these jobs.
Unemployment is a bitch. -nB
Admin
Just out of curiosity, what DOES that construct do in Python? What's the actual effect? A naive analysis would be that it would enter an infinite loop. I'd assume that Python has a built-in check to prevent that. Is it the same as simply not handling the exception?
Admin
It's the equivalent of "throw" in most other languages.
Addendum 2016-11-17 12:41: So he's just catching and re-throwing it.
Admin
Let me fix that casing for you: AlwaySlowerCase
Admin
It causes a SyntaxError: invalid syntax for the raise statement, pointing at the comma after Exception.
Rewritten as "except Exception as e:", the actual effect is to raise the error in the line with the except statement, and the traceback pointing to the line that actualy caused it originally in the try block.
Addendum 2016-11-17 13:28: The line with the raise statement, I mean — not the one with the except statement.
Admin
Not very familiar with Python but, for most languages, exceptions that occur inside the catch are not handled by the try/catch block. If you have the potential for exceptions inside a "catch", then you need another try/catch block inside the catch. If you find yourself building that, though, I would ask yourself if you really understand what you're doing and why ;)
Admin
Actually it happens to work majority of cases, incorrect as it is. except Exception, e: --> except (Exception, e): This would be construct for catching exceptions of types: Exception and e. But e is probably unbound/undefined. Since Exception is very broad it catches almost everything (including KeyboardException 'ctrl-c') So in that context it is similar-ish to the c/c++ if (TRUE || foobar) {}, foobar doesn't get checked most of the time.
The better way is to be more specific, and use the 'as' keyword as Gurth mentioned if needed to log/inspect the exception. Such as: except (ValueError, TypeError) as e:
Admin
Everyone knows that 'raise' makes a toast notification.
Admin
Never work for a non-developer manager, if you are a dev. Your life is worth more than that. There are some nondev managers, but they are really rare, almost non-existent. That person won't be able to understand what you do, they won't be able to make choices correctly, they won't be able to evaluate 10x programmers.
Admin
I am ashamed to say I fell for it. During the interview they kept asking me these Computer Science 101 questions I've largely forgotten, and I thought it was a Google-style interview and I was failing.
It happened that the "Software Architect" ONLY knew that stuff, and, after a non-standard inducement period where me and the other hire weren't induced much, he proudly presented to us the product of one year of (hard?) coding his crowning achievement... a pretty standard boilerplate 3-tier application framework with NO logic (the kind you can download for free or build in a day).
Needless to say the project failed spectacularly.
Admin
The unexpected indent in the 5 lines of python is TRWTF.
Admin
The catch syntax in the article is very likely from older Python 2.x versions. The last 2.x versions started to support the “as” keyword and the current 3.x requires it.
Admin
"What does the raise command do?”
"Here? Nothing. In my next job? Gets what I'm worth."
Admin
It should have been CTO-Ray and Dev-Ray so he could catch a few Rays.
Admin
It's not "Ten-X", it's "ID-Ten-T"...
Admin
It probably worked in older versions, I’d guess. When I tried it in Python 3, it threw an error, but I don’t have a version 2 to check if it’s any different there — though the documentation for the two on the Python site seems to be much the same so I wouldn’t expect them to behave differently.
Admin
"So he's just catching and re-throwing it"
Not exactly. He's catching it and throwing it again. The distinction between "re-throwing" and "throwing again" is minimal in Python, but in, say, C++, to simply throw the exception you are handling on to the next exception handler, you
throw;
, while youthrow e;
to throw something that is sort of maybe like the exception you were handling. (At best it will throw a copy of it, while at worst it will change the type of exception that it is, if you caught a derived-class exception in a base-class handler. Unless the original throw wasn't even an exception, for example,throw 7;
(1))(1) Although this is accepted by the compiler, and at run-time it will, as you might expect, be caught by
catch(int e)
orcatch(...)
, anyone using this ability in C++ code should be shot repeatedly using a small-calibre pop-gun, like this GAU-8 I keep in my back pocket for just that sort of occasion.Admin
Just as interviewees lie, so do interviewers.
After working with more than a few WTF factories and non-programming programmers, "let me see your typing guidelines" rocketed to the top of my list. I was just fucking tired of with being hauled into "counseling sessions" over bracket placement by people who would have to improve, markedly, to be featured on this site. So far, the response has been to either feign ignorance or guard that information as if it were launch codes. What they expect to gain from that is beyond me but I know what I hear: "It's a trap!"
Admin
No,
catches any exception of type Exception and sets e to the current exception
This is what you describe, where it catches an exception of type Exception or e. The syntax used by the Burt is correct, although it doesn't really do anything.
Admin
Yeah. The old sytax used the comma, before the
as
keyword was added to exception statements. It's been deprecated because it looked too much like the syntax for catching multiple exception types.Admin
To be honest, I'd be pretty annoyed if a new developer started to refactor my code if they hadn't been asked to, and wasn't required in order to resolve a ticket. You don't just start changing code because you think its better. It has to be deliberate and agreed upon.
Admin
This is true but a lot of companies are adept at putting on an amazing show in the interview. For instance, it's extremely rare to ever be able to view a company's source code in an interview, so you'll never know if it's all spaghetti code or they are clueless about how to use source control or they've reinvented the standard libraries poorly. In my experience, the worse a company is, the better they'll be able to lie out their ass to present themselves as cutting-edge, with brilliant developers and using best practices. Only once you've started working there do you see past the veil but by then it's too late unless you can afford to just up and quit.
Admin
Exactly. They hide this stuff to trap people.
What I've never figured out is the logic behind that. If I sit there in an interview and say, point blank, that I don't like to be micromanaged, why do micromanagers hire me? Do they think I was lying? That I'd just spin my wheels while some incompetent with a broken project fixates on where I put brackets, how many parentheses I use, what notes I make in comments, etc? That after being dragged through skill/experience hoops at interview time, I'd play dumb (withhold solutions, ignore bugs, etc) to spare their feelings and quietly accept blame for a mounting pile of CANT_FIX/WONT_FIX?
I actually did get a meaningful answer to a similar interview question once though. An interviewer had told me that I wouldn't be allowed to use IIF(). I asked why. Incredibly, they gave a mostly correct answer (that the 2nd and 3rd parameters are executed before the comparison to the 1st is done - though it probably never dawned on them that this applies any time you pass function results into any function). And then wouldn't give the recruiter any feedback on why they passed. More than likely they were upset that I asked for an explanation.
Admin
To me, this sounds a lot like "because it's a function instead of a real ternary operator, people keep forgetting that part and getting burned with IIF(something IsNot nothing, something.someField, ""), so we're banning it."
Admin
I think it's mainly an air of superiority. Companies, the type to engage in this behavior in particular, seem to think they are doing the candidate a favor by even offering them a job (as opposed to viewing it as "This person is knowledgeable and can benefit us as much, if not more, than we can benefit them"), so they figure you'll shut up and deal with it and be grateful that you're being given the chance to work there.
Again, it seems directly proportional to the level of WTFery at a company, and it's typically the WTFiest of companies that always pull this "holier than thou" approach, as though you're some beggar who is desperate for work and you should thank them for even thinking about you. Very plantation-ish mentality.
Admin
Yes, yes, I see the WTF... but is it really worth the "last straw" before you walk out of the building being a catch-rethrow...? I mean, yeah, it really doesn't serve a purpose.. I guess you could argue a small purpose when people don't want to put a bunch of filters on debug breaks on exceptions and simply want to place break points in a few particular places where they also simply want to throw the exception back up or perhaps they want to log at those various levels and throw the exception back up (which actually has negative consequences dependent on the language you are using and how you go about using it... in c#, catch (exception ex) { throw ex; })
I guess I wouldn't walk out of a job because of a catch-rethrow... Not really an "end-of-the-world" scenario imo.. Perhaps onion architecture, or layered spaghetti, or just spaghetti, which it sounds like the OP was dealing with already... or perhaps piss poor database design decisions... But a catch-rethrow? :|
Not quitting my day job, I suppose... :)
Admin
The WTF is not the catch-rethrow: It's that the head dev, the 10X guru whom you're expected to obey, put it there without even knowing what it does.
Addendum 2016-11-22 04:13: ...or looking it up.
Admin
ETA: Or looking it up.
Admin
"What I've never figured out is the logic behind that. If I sit there in an interview and say, point blank, that I don't like to be micromanaged, why do micromanagers hire me?"
Because nobody thinks they're a micromanager. Just like nobody thinks they've got no sense of humor, and nobody thinks they've got bad taste in music.
Admin
"But a catch-rethrow? :|"
I know the article mentions Python but in C# the difference between "throw e;" and "throw;" is that the former resets the stack trace and now you have little to no idea where the exception really started. My first two real programming jobs were a system with well-designed exception logging and a small self-contained application that could get by without it so I didn't really appreciate that until I worked on some real basket cases where I had only a debugger or "oops, try again later" to work with. It's absolutely incredible to me how many developers think it's acceptable to play games with suppressing or obscuring exceptions in a production environment.
Admin
Fortunately, in Python, "raise e" doesn't erase the stack information from e. It does add itself to the stack trace though - you can see the line where the exception was thrown in that method, as well as "raise e" line. "raise" just re-throws the exception and doesn't add itself to the stacktrace, which is arguably worse - there's no way to tell that exception was caught at all.
Admin
Well, something else threw it, so he's re-throwing it.
Admin
Dev-Burt used the
raise
statement exactly 9 times, which his why he's now a 10x developer.Admin