- 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
Oh this is beautiful... there is beauty in madness, right?
Admin
var self = document.querySelectorAll("frist")
Admin
at least its indented
Admin
This is one of those rare occasions where it would be better if it weren't indented.
Admin
Meh. Looking at the variable names, this is clearly minified JavaScript that went through the browser's built-in formatter. Nothing particularly egregious...
Admin
Nothing particularly egregious? You're kidding, right? You could stuff the data into an associative array at half the character count and (assuming a bad optimizer) twice the performance. You could keep the data separately and call back to get it. You could derive it from the <options> to a <select>. I know there are worse ways to write this code, but is there a worse one that's plausible?
Admin
Ba!
Admin
Someone got paid by the line.
Admin
I can't see performance being an issue with a weedy little thing like that, and I'm not utterly convinced you'll get something better with an array versus having it fully unrolled. Mind you if the coder (or auto code generator, which I suspect it could be) was going to do that with it, it really should have gone with a switch statement!
Admin
TRWTF is that there is no default value being returned.
Admin
See, this is exactly how you make secure, maintainable and reliable software. Fire the programmer and use an auto code generator. Software for things like car engines, airplanes, spacecraft are written this way.
You make a model and a spec that's high level, often GUI, and that is written in engineering terms. Then you test the heck out of the model, say simulating sensor failures and running real-world data through it. Now you have a very reliable model, how do you translate it to executable code on the device without errors? Use a completely automated process.
The resulting code may look awful, but you never deal with it at that level, and in fact, the generated code may be faster. Even if it isn't, just throw a faster processor at it.
It's just like saying that compiler generated machine code is ugly and potentially inefficient compared to hand generated assembly.
Admin
Hmm, is that not the final } else { return "" }
Admin
It's like they've never heard of a case/switch statement. I work with code like this except instead of nested if/else it's stacked ifs. Performance dies a death of a thousand cuts.
Admin
There are better ways to write it, for sure, but again, this is not particularly egregious.
“Assuming a bad optimizer”? Chained if statements over integers are trivial for today’s JS runtimes. The compiled output would be the same as a switch statement, and they would inline it if this function got called enough. But this point is moot anyway, because there are no realistic situations where this would ever be a performance problem, so even talking about “twice the performance” is absolutely needless premature optimization.
Admin
Performance of nested/stacked if's vs. an array vs. a table may have been an issue with Firefox 3.0. I suggest you upgrade to something more modern.
Admin
function a6(ba) { return (function (chosen) { return typeof chosen === 'function' ? chosen() : chosen; })(([ function () {return ad.find("#wireless-channel-auto").text();}, "1 - 2.412 GHz", "2 - 2.417 GHz", // ... ])[parseInt(ba)]); }
Fixed the indentations, but made it weird...
Just like my relationships.
Admin
What part of "death of a thousand cuts" did you miss? This could be happening all over a 60K-line script. At some point, the developer has to do some thinking, because renting more processor/storage/bandwidth and/or lurching your entire stack through an update treadmill isn't acceptable.
Admin
Apparently the coder did not twig to the realization that the channels are 50KHz apart. Knowing that the function becomes: return ba + " - " + ba * 0.05 + 2.415 + "GHz"
Admin
This code was generated by a tool.
Admin
That's true of most of the code featured on this site.
Admin
Lets not resort to name-calling
Admin
Admin
I agree. Most tools transform
switch
statements into nestedif
s. So the only decision here was to populate the UI using hard coded values, or look-up from a file/db. I think for something lightweight and immutable the best course of action is switch statement. Granted if there is a formula (like 50kHz steps) that would make more sense to use, but in this case "good enough = product shipped".Admin
"Chained if statements over integers"
I guess you didn't notice the quotes around the tested numbers....
Admin
Isn't that more of a performance WTF, cause now the JS engine has to deal with a float? Watch some crappy platform populate the list with "1 - 2.4119999999999999999999999 GHz"
Admin
Eh, that's just an if statement, easy peasy. They probably didn't read out the whole list to see there was a jump.
... Huh. Two jumps.
Okay, I think TRWTF if happening off-screen, as there is a cluster of values on the end that belong in the middle. I mean, it doesn't need to be in ascending numerical order the way they have it, but it just seems very odd. My money is on 'oops, we forgot those and now we can't adjust accordingly, we'll tack it on the end of the list and hope nobody notices'.
Admin
<select><option>hoi</option></select>
why would you want to end <select> tags when they don't do anything?
Admin
Indeed! My bad.
Admin
How do you know the code generator is better than a human? After all, it was written by a human.
Admin
Two reasons: first is the code generator can be split up into much smaller blocks that can be individually validated. This is like a compiler. You implement and test arithmetic functions independently, then you can put them together to form arbitrary equations at a high level of certainty.
Second is a cost issue. The code generator and libraries can be reused over multiple projects, platforms and companies, thus the cost of validation is amortized. The overall validation can be more comprehensive and cross-domain (aerospace, automotive, medical, industrial) compared to starting from scratch every single project. This is important due to the fact that many of these systems run on bare metal: no operating system.
Admin
If people keep writing code like this, there will soon be a worldwide shortage of curly braces [it was the shortage of parenthesis a few years ago that killed Lisp -Right?]
Admin
I'd say this kind of code would work better as a switch, but since this is for a router...
Admin
This isn't even the worst I have seen when it comes to a routers web-config sourcecode.
A lot of el-cheapo modern routers still do the stupid thing (I was kinda hoping it had of died off years ago) where they store the default login details in the sourcecode, a simple 'view source' shows that the JS does validation to make sure what you entered and what it is expecting are the same.
Admin
This is why I use OpenWRT.
There are two things that I'm sick of in consumer routers: arbitrarily limiting the capabilities of the device when the hardware is capable of more just to make people pay for a more expensive model with extra features (e.g. firewall, VPN, extra WLANs, etc.) and devices that don't actually do half of the advertised features properly in the first place (or feature slow/bloated/badly-written code that makes them difficult to configure or use).
Admin
Anyone care to elaborate which router this is?
Admin
all of them.
Admin
WTF? Spambots at TDWTF? Oh my. Seems like that CAPTCHA of yours has been beaten.
Admin
Problems with your approach:
Admin
I had to stop using MS Paint because my monitor was running out of red pixels.