- 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 comment blindly swallowed, so I've no idea what it was.
Admin
non-usage-warnings are useful so you don't want to deactivate them and some exceptions can be ignored so without context it's hard to say if this particular line is actually a WTF or not. Before Java added annotations that allow to deactivate a particular warning at a particular place in the code (here you would add a @SuppressWarning("unused")) I've solved these kind of warning in a quite similar way (just used if (e != e) {} instead) which might be another reason why I don't see this as a "full WTF" ;-)
Admin
It's hard to say if this particular line is a WTF. But if similar (or even identical) lines occur all over the code, that's definitely a WTF.
Admin
Any one exception that you ignore is possibly OK, although blindly ignoring them is rarely a good idea. At least understand why the exception doesn't merit any special handling, and put a comment to explain why.
If it's a recurring pattern that developer X just puts these in out of blind habit, malfeasance, indifference, or whatever, then it's a high-tier WTF, well worth visiting the chap (or chapette) with a top tier clue bat - probably in shape, size and manner of operation similar to a GAU-8 - in your back pocket in case of need.(1)
Especially if Developers Y, Z, and W just blindly follow the pattern set up by X.
(1) Y'all do keep a GUA-8 in your back pocket for emergencies, right?
Admin
About the only nice thing we can say about the 2 lines of code is:
// @PRAGMA flamesuit = on
As Steve said, it's the do it everywhere for no understood reason feature that elevates the whole codebase to a stenching WTF. And the whole staff to bovine idjits.
As to Lothar's good point, this is another way in which "self-documenting code" isn't. If you need something like that de facto no-op to fool the linter, then it needs a comment like:
// this is a deliberate no-op to fool the linter into thinking $e is not an unused variable
And as well the catch block needs documentation as to why it's OK to swallow these specific type(s) of exceptions here and which logical failure conditions you are expecting to swallow. If you can't show "proof of work" for the intellectual rigor behind your decision, your code can safely be removed as random and thoughtless. Along with removing you from your job as random and thoughtless. When you (any you, including me) do code-smell crap like this you really need to thoroughly justify your decisions to the future maintenance dev, even if that somebody is you.
Admin
In C and C++, the way to tell the compiler or a linter to ignore an unused variable is to cast it to void (or in the case of exception handlers and function parameters, you can omit the variable name and write only its type in the declaration).
PHP intentionally doesn't have this feature, and according to that feature request, the convention for unused variables is to name them
$_
and configure your linter to ignore that. (Without more details it's obviously unknown if the submitter's linter supports that feature.)But as the previous commenters said, TRWTF isn't so much the way that the warning is being ignored but that fact that the exception is being swallowed aimlessly by know-nothing cargo cult programmers.
Admin
Whenever my credit card comes back with insufficient funds, I just silently walk away from the cashier.
Admin
TRWTF is PHP for not having a warning for useless self assignment.
Admin
Xcode has some interesting warning behaviour. Say you have code “if (condition) statement;” and for debugging you don’t want this statement to be executed with minimal changes: if (false && condition) gives you a warning about dead code. So you write “if ((false) && condition)”. The parantheses tell the compiler “yes, I mean it”. The code is still optimised away but no warning.
Admin
I would have thought (and I've given it caffeine-free, minimal thought) that a short-circuit operator ('&' rather than '&&') would negate the implicit requirement for parentheses and the resultant non-obvious compiler behaviour.
But then again I need more coffee and a modicum of thought.
Admin
Inherited from C, although lint in it's many-splendored varieties will warn you. Perhaps.
One of the little-observed problems with PHP is that it was built on top of the assumption that C semantics were the way to go. Which was actually not unreasonable at the time.
Unfortunately PHP then accreted various conflict resolutions between C semantics (as here) and object semantics (as per the === operator). It's a mess, but it's understandable how it got there.
Admin
At least they enforce the linter rules. I've worked on software that had 10,000 warnings in 20,000 lines of code... anything is preferable to that, even $e = $e.
Admin
However, PHP just added (November 2020) the ability to catch without declaring a local to hold the exception reference... which is the correct pattern to use in this situation. So kudos to them for at least addressing the problem head on and not giving in to pressure to introduce a work around that might do more harm than good.
Admin
You'd kinda hafta qualify what "linter rules" are. I started work 35 years ago with C, and for the entirety of those 35 years, everybody I know has switched off lint.
Why? Because (and you may correct me with some whizzy new implementation) lint was yer basic hacky *nix tool with very little in the way of an AST or semantic checks (compare and contrast to Roslyn, or whatever the equivalent is on the JVM). You want 25+% false negatives? Sure. Be my guest. Trawl through those 10,000 warnings and try not to die of despair.
Admin
So basically lint was more of a wtf than anything it detected? Sounds... fun (and fanboys being what they are, there's probably still someone swearing by rather than at it).
Lint being terrible in a "what's an AST" sort of way is a great example of why "text is a universal format" is wrong. It's universal in that one-off hacks can use string processing but if you need something that actually understands the data, text vs binary is the least of your worries.
And the best way to do that in this context is to reuse the compiler itself! Why it took so long for compiler-as-library to catch on I don't know.
Admin
Writing code either to succeed against the odds or fail catastrophically and restart is the PHP way
Admin
Or it was a debugging catch to have a breakpoint for a debugger in the catch block?
Admin
Lazy fix: can't you just
catch(ZendException) {}
? I'm pretty sure I've done that, in PHP. Don't hate me.