- 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
Bonus: you can not right click and open in new tab.
Admin
Was he given enough hours to put it together? I think 32 hours would be needed, what with development, testing, documentation, release prep and go live.
Admin
I am amazed that onclick="javascript:window.open('https://example.org')" actually works. I always write event listeners in HTML without the javascript: part.
Admin
You can't possibly expect us to believe that this code was not used, nor that the contractor was dismissed.
I mean, come on, this is TDWTF-land here, such sanity is unheard of.
Admin
Don't worry. Now that it's been put online someone will find it and use it as a code sample to copy paste into production. That's just how the universe corrects sanity.
Admin
Yep, that's one of many added bonuses from the "I'll use an anchor tag for my button" antipattern, to go with completely failing on accessibility. That's a massive WTF all of its own, the more so as it's perplexingly common.
Admin
Actually no, the JavaScript really does just open a new page. So a link is the correct element - why not leave off the JS and just use the href tag the way it's meant to??
Admin
A successful contractor would have not used a loop to maximize the number of lines of code, then packaged it up as a framework on Github, depended on about 100 other javascript libraries, grew the market to 100,000 a week downloads, then added support for mining cryptocurrency in people's browsers. Clearly this contractor was not that good.
Admin
I love the way that there's an empty
<tr>
instead of a closing</tr>
.Admin
Back in my day... web sites were a collection of static pages (at least from the client perspective; PHP was a whole other ball of WTF), and the prevailing guidance was to make sure your site worked, even if in a degraded state, should the user choose to turn off Javascript. And we liked it!
Then somebody came up with AJAX, and then Node.js, and things have been going downhill ever since.
Admin
I don't believe it. I worked with bonehead contractors who'd hard-code things, never make anything variable or extensible, and they were never fired.
Admin
Plus the closing
Admin
I am SO on the fence here. I do work with people who reject garbage like this. I've done some recent oversight of a junior programmer just to avoid things like this ("no, don't create a new drawing surface; just handle OnPaint"). OTOH, I submitted a story here about some code dropped on my company where a humble bit-test was expanded to a function that involved creating, appending and reversing a string, then converting that back to a numeric value. That's live in the wild somewhere.
Admin
I don't think for-case is an antipattern in general. Suppose you have housekeeping PRE and POST which you want to do for every pass and some TASK-# which has a different codepath for each of N passes. Your unrolled task order is PRE, TASK-1, POST; PRE, TASK-2, POST; ...; PRE, TASK-N, POST. It's convenient to write this as a for-case loop, as the author's done here, with PRE followed by a big case statement to sort out the codepath, followed by POST. You might make the code slightly tidier by wrapping the case statement up as a function TASK(PASS), but you're just moving complexity around, not eliminating it; and depending on what the various TASKs require, it might even be uglier if you have giant parameter lists to pass in all the state you might need.
For-case is specifically an antipattern in the degenerate case when PRE and POST are nonexistent. Then you might as well just write out all the cases sequentially. Of course, here they're present but so trivial as to not really be worth it; but then, the whole idea of writing a function instead of a static string sets the bar for "trivial" pretty low.
Admin
It is static HTML. There is no need for constructing a string in the first place which has no repeating features. That is the real WTF, overengineeringbthat only wastes resources ... not uncommon in JavaScript files.
Admin
That's because you've been doing it right. The event listener attributes are supposed to contain plain JavaScript code, not URLs. The reason the “javascript:” part doesn't cause a syntax error is because in that context it becomes a label.
The website of the Spanish railway company RENFE is infamous for the amount of WTFs in it, including the Useless Use of OnClick antipattern showcased here. It's amazing how the simplicity of just putting the link in the href how it's supposed to be is somehow too difficult to grasp for some people.
Admin
That is only correct if you restrict yourself to HTML5, because this version of HTML requires the script parser to be exclusively an JavaScript parser.
The HTML standard has always considered those attributes being passed directly to the script engine. And before HTML5 this meant that browsers often had script engines, which supported multiple script languages like text/jscript, text/tcl, text/vbscript etc. depending on the browser. Netscapes script engine suffixed in attributes the name of the language followed by colon; other browsers followed that syntax. So if you wanted to write your script code in jscript instead of javascript, you wrote jscript:. Because Netscapes default language was javascript, the label syntax was perfect for it, to allow it as default without the language nominator.
Admin
What you describe sounds more like a for loop over tasks. Just like the code in the article could have been a for loop over an array of links
There should not be a need to check i for exact values as that completely removes the concept of flexibility of the loop. Usually you want to be able to add or remove elements from the array you loop over without changing the code of the loop
Admin
This was not a loop with pre and post conditions. It was a simple sequence of three statements that some utterly incompetent coder forced into a loop form, to no effect except wasting a little time and memory and making the code harder to read. Or else the coder was padding the LOC, but in either case I'd never give him any more work.