- 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
I'm suspecting this code comes from a German speaking country and the "von" and "bis" fields indicate the start resp. end of a range.
Admin
Yup. "Von" meaning "from" and "bis" meaning "until", this filters out everything which is several kinds of empty: null, the empty string, 'undefined', and objects intended to be a range, but for which both ends are null, empty string, or 'undefined'. Ranges with one open end are left, but ranges with both ends open are removed. An idiosyncratic definition of "empty", but not necessarily a WTF with the right kind of expected objects.
Except for the 'undefined's. That is a WTF.
Admin
Most likely this is from a data model that stores historical changes to values, hence the 'from' and 'until' fields. If these are not filled, the data would be (rightly) considered corrupted.
For those that are wondering why you would use this: auditing, either internal or external, is the answer.
Admin
As to the string value 'undefined' I'm going to bet this is the typing/null-checking equivalent of a doubly-escaped stringly value.
Somebody does a type check or null check or an IsMemberDefined() check on something which later gets checked again and eventually the typevalue
undefined
gets turned into string "undefined".Or it's the result of an inner JSON server roundtrip. Gaah but there's a lot of that going on these days. Layer upon layer of roundtrips caused by layer upon layer of library code. And each one with a string<->object conversion at each end getting onto or off the wire.
And if the origin of the double-escaping is inside some library you're using, well, you're stuck with it. Or, more precisely, you're stuck trying to filter them out wherever they may have arisen beyond your control. Like this little example is doing.
Or if, in the usual case of monstrous tangled codebases, half your code does it right and half does it wrong so no matter which direction you choose to clean it up your stuck reworking (and re-testing wo unit tests of course) a vast swatch of your codebase. And until ever possible generator of "undefined" is found and eliminated, you can't even begin phase 2 which is to remove the filtering and checking code from the other umpteen hundred places it exists.
There's hard, and then there's Undisciplined Technical Debt-hard.
[The CAPTCHA asked me to identify pictures of tractors. First time I've seen that one.
Unfortunately, it thought that a boom manlift painted green with offroad tires was a tractor. At least it got the two traditional farm vehicles correct.
Maybe we should turn in screwed up TDWTF CAPTCHAs and some day Remy can run a Friday bad-UI special on how well those (don't) work.]
Admin
Undefined is what a native German-speaker comes up with in English to describe people whose fines haven't been cancelled...
Admin
The thing about the captcha problem reminds me of userinyerface.com...
Admin
My favorite is the one where it's asking for traffic lights or crosswalks or something, and the objects span multiple squares. Do I click a square that has only a little bit of the object? What's the minimum amount of coverage needed to consider the object as being in the square? I still haven't figured that one out, and usually wind up getting it wrong.
Admin
Or whether the poles count, especially for American traffic lights. But yeah, I'm not a fan of ReCAPTCHAs of traffic lights, or crosswalks, or buses, or bicycles. Is that dark pixel on the road back there a bicycle?
Admin
Does it bother anyone else that we're using traffic lights to tell whether it's person or a computer doing the typing at the same time they are teaching computers to drive cars?
Admin
There's a ton of runtime type checking libraries. Use one of those.
There's also Record libraries. A ton of those too. Record.filter(compare)(data) . You don't need the keys. If you do, like looking up an associated object, there's Record.filterWithIndex
Admin
Javascript just keeps getting harder to read. Not sure I know what the :any is anymore.
Admin
The worst are when it's WRONG and it insists you click on a square which most definitely does not have a traffic light, or part of one. Unless maybe it's hidden behind a tree and not visible.
Admin
I really hate the ones that are plural. Should you click on the one with a single car when it asks for cars?
Admin
Interesting to use "von" and "bis" but not "undefiniert" (courtesy Google translate)
Admin
I'm certain that von/bis is German and definitely implies that this value is a range type, e.g.
{von:16.7.2020 bis:17.7.2020}
for today and tomorrow.It's really the least WTF in TypeScript that could be using
Object.entries()
,Array.reduce()
, and declares theany
type.Admin
Me, I just don't like the signature.
If you have to pass a non-typed thingie into a method, and then spend time figuring out what the thingie is, you've probably picked a sub-optimal language.
I leave this as an exercise for the reader: you could probably write this in about five lines of PHP (PHP!) and it would make more sense. And yes, I know, Typescript isn't actually JavaScript, but don't kiss a pig just because it has a particularly mauve colour of lipstick.
Admin
I think this is a routine to clean up data that's been corrupted elsewhere. Corrupt external data is a fact of life and the programmers dealing with it shouldn't be blamed.
Admin
As a non native English speaker, I often mix up French and English in the code I write, especially if it is for my one use only (but you know that some day it will be end up being shared).
Admin
@Brian: ref
Yeah. Me too.
For objects spanning tiles I've decided a cutoff of about 10% of the tile being the query object is about right; any tile with less than 10% coverage is not part of the object. And as to traffic lights they only want the tiles that contain the lamp part, not the background plate and certainly not the stanchions.
Since machines can't make up CAPTCHAs or else they'd be able to solve them too, ultimately we/you are matching wits with some poor schlub on Mechanical Turk et al who's paid $1 for a day's work categorizing the tiles that go into CAPTCHAs. So consistency isn't going to be a standout feature here. Sucks to be him/her a lot more than it sux to be us.
Admin
Why do you think these are always related to driving? It's crowd-sourced training data.
Admin
I just got the Crosswalk captcha ... and felt a strong sense of urgency to answer https://xkcd.com/1897/
Admin
You don't seem to remember the old Google captchas. They used to give you words from a book that their system had trouble recognizing. So, obviously, they have experience using unknown images.
The way it works.... Google first make a guess on how much it thinks your human. They have a lot of data points, this isn't hard. If they're pretty sure your human, then you either bypass the captcha, or you are shown a captcha and your response goes into the training data. They don't arrive at an "answer", instead each tile is scored on how likely a human is to pick it.
If Google needs to know if you are human, they shown you a captcha that they have already gathered training data for. When you get these "iffy" tiles, like the traffic light poles, the training data says reals humans sometimes pick it and sometimes they don't, so your response to that tile is irrelevant.
Admin
Or undefined is what you get for wearing illegal pants.
Admin
The real WTF is they missed a conditional. I fixed it:
function _filterTest(prop: any): any { return (prop !== null && prop !== undefined && prop !== 'undefined' && prop !== '' && prop !== 'file not found'); }
function _filterEmptyValues(value: any): any { const filteredValue = {};
}
Admin
It could also be a typo. If you are or were targeting browsers older than about 2012, the correct way to check for undefined was if (typeof foo === "undefined").
That was preferred over simply checking if(foo === undefined), because in JavaScript, undefined is not a keyword, it is a global variable, and in earlier browsers, you could actually write a new value to the variable undefined, and break all comparisons with it. Nowadays it is read-only, but a large corpus of code will still use the old pattern, which for many years was the correct way to do things. It looks like someone may have accidentally omitted the typeof operators.
Admin
I'm pretty sure you can get Typescript to complain if you use an object which it doesn't think has the property that the code is trying to access.