- 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 may barf.
Admin
So ... TRWTF is the magic number 52, yes?
Admin
TRWTF is ageism. Apperantly, one cannot be insured under 18 and over 70 years old.
Admin
It's just a tiny bit more excusable, because it's using a library and not the built language features. Maybe they missed the existence of that other method. But only a tiny bit. Reading the documentation of the library you're using is the developer's job, period.
Admin
I interpreted it as validating the "week of year". Why would they take the age, subtract 18, then check 0-52? Seems to be a weird solution.
On the other hand, this is TDWTF, so everything is possible.
Admin
Wait, it's supposed to check if the field contains a number, right?
With stuffs like
Literal('23'),
, will it try to check for the number 23 or the string "23"?That could be a WTF in itself (aside from the mere repetition of tons of hard-coded values with no concept of range whatsoever, of course).
Admin
If it's the age you get the contract at, the 18 may be explicable by the contract being issued for a guardian if it's for a minor.
Depending on the kind of insurance, it might also be totally feasible to not give new contracts to people over 70 - maybe it is the kind that pays your heirs if you die before age X or it is for something that you can not even obtain after the age of 70.
Admin
If you're not 100% or even say 80% healthy -- i.e. if you have more than one major condition such as diabetes -- good luck getting life insurance even after age 45.
Admin
The issue here is that they want to tell the type checker more than it cares about. If this was Idris then the implementation of
withConstraints
would produce a constrained type (T extends number & T >= 18 & T <= 70
). But because this is TypeScript the constrained type will just produce anumber
. So the writer of this code thought "I'll make sure that it's clear what the valid values are in the type" ... and wound up here. Unfortunately, they never asked the critical question ... "what will TS DO with this information?" - because if they had they would have realized this is useless because as far as TS is concerned.Admin
My guess is that they have a 'term' variable containing the number of years the contract covers.
About the time I have to duplicate the same line of code fifty times, I assume there has to be a better way that I should look for.
Admin
My fault, I just noticed the comment at the end of the code snippet, previously I was surprised as to why the age question even came up.
If this is life insurance, the age check can be explained. For the lower bound, it may have to do with being able to legally enter into an agreement. For the upper bound, it's probably the risk profile for age groups, why would the insurance company sell policies, where the chance of payout is exponentially more than with other age groups.
Admin
I'm sad that there isn't a missing and a duplicated number.
Admin
TRWTF is that the correct plural of "index" is "indices". How is anyone supposed to understand your code if you don't name the variables correctly? ;)
Admin
You don't have to spell things correctly. You just have to spell them the way your audience expects them to be spelled.
When all the devs in your shop are illiterates who like the word "indexes", then "indexes" is the (locally) "right" way to spell it. The wtF isn't the spelling, it's the roster of devs.
Admin
I don’t use either this particular library, nor TypeScript itself. However, the proposed solution looks flawed.
The valid values are integers 0 through 52, inclusive. The proposed solution restricts valid values to “a number that is greater than or equal to 0, and less than or equal to 52”. I’d guess that this would be quite happy with a term of 13.7 - which is not supposed to be allowed.
TRWTF is the hard-coded “0 to 52”. As many other commenters have pointed out, this is probably related to the idea that an insurance policy is only available for clients over the age of 18, and must expire at age 70 - sadly, common enough in the industry. However, surely the correct solution would be to take the customer’s current age into account - if I’m already 68, the valid values should be 0, 1 or 2.
Also… who buys a policy with a term of zero years? Maybe there’s a separate months field… but offering 6 months of insurance to a 69-an-a-half year old sounds unlikely…
Admin
When I got into programming, I thought it was something anyone could do. That idea persists to this day ("they can learn to code"). Today, my company has a junior programmer who generally knows what he's doing. Naturally, he's still learning things, but after [mumble mumble] years of programming, I'm still learning things. At the same time, some people never seem to grasp the basics. Some veteran programmers I've met will write code like in today's WTF. Our junior programmer wouldn't write something like this. Now if we could just weed out the programmers out there that don't get it, the rest of our lives would be easier (though finding good stories for this website would become a lot harder).
Admin
TRWTF is this comment, as seemingly every English dictionary seems to agree "indices" and "indexes" are both correct plurals of "index".
Admin
Pretty sure English is TRWTF.