• (nodebb)

    I may barf.

  • Prime Mover (unregistered)

    So ... TRWTF is the magic number 52, yes?

  • Industrial Automation Engineer (unregistered)

    TRWTF is ageism. Apperantly, one cannot be insured under 18 and over 70 years old.

  • (nodebb)

    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.

  • (nodebb) in reply to Industrial Automation Engineer

    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.

  • Sauron (unregistered)

    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).

  • An Old Fart (unregistered) in reply to Industrial Automation Engineer

    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.

  • (nodebb) in reply to An Old Fart

    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.

  • TooSpecific (unregistered)

    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 a number. 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.

    type SmallInts = 1 | 2 | 3 | 4
    declare const x: SmallInts;
    if (x > 5) {
       // x is still of the type of SmallInts here even though it _can't_ be
       let y =  x + 7; 
  • (nodebb) in reply to Mr. TA

    Why would they take the age, subtract 18, then check 0-52?

    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.

  • (nodebb) in reply to Bim Zively

    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.

  • (nodebb)

    I'm sad that there isn't a missing and a duplicated number.

  • Erik (unregistered)

    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? ;)

  • WTFGuy (unregistered)

    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.

  • Nick (unregistered)

    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…

  • Prime Mover (unregistered) in reply to Industrial Automation Engineer
    Comment held for moderation.
  • Ralf (unregistered)
    Comment held for moderation.
  • nunya business (unregistered)
    Comment held for moderation.
  • Argle (unregistered)

    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).

  • (nodebb) in reply to Erik

    TRWTF is this comment, as seemingly every English dictionary seems to agree "indices" and "indexes" are both correct plurals of "index".

  • (nodebb)

    Pretty sure English is TRWTF.

Leave a comment on “Literal Type Checking”

Log In or post as a guest

Replying to comment #:

« Return to Article