• stevecrox@kbin.social
    link
    fedilink
    arrow-up
    8
    ·
    2 years ago

    I am currently teaching python and JavaScript devs Typescript. Everytime they hit a problem they switch to any

    Sigh

      • OsrsNeedsF2P@lemmy.ml
        link
        fedilink
        arrow-up
        3
        ·
        2 years ago

        “Your crappy tests are failing again on my branch. I’ve commented them out until you fix them.”

        • Hudell@lemmy.dbzer0.com
          link
          fedilink
          arrow-up
          1
          ·
          2 years ago

          Sadly that sort of thing got so common where I work that I’ll run the tests three times before considering looking into the error message to see if it is something I broke.

          From time to time we take some days just to fix tests with inconsistent results, but there’s always more popping up.

    • Uplink@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      2 years ago

      That’s why I kinda don’t like Python and JavaScript anymore. Every time I want types for a library it’s gonna take me time to get it working. For every serious project I do, I use a strongly typed language.

    • jflorez@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      Just create a al Inter rule that rejects Any types and a pre-commit hook that refuses the commit if the linter fails. Sometimes the brute force approach is the best way to teach

      • TheCee@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        2 years ago

        Indeed, and just as my old team fell for consultants, my new team also went ahead and let them add some overcomplex garbage into their codebases. And crap still keeps piling up. It’s just like it’s impossible for them to understand that from an average consultants perspective the only way to go forward is to keep adding complexity, wether they are aware of it or not.

        • OsrsNeedsF2P@lemmy.ml
          link
          fedilink
          arrow-up
          2
          ·
          2 years ago

          Oh, the consultants know, but they get paid, don’t complain about “risks” and “code debt”, and management only sees their delivery on time without increasing operation costs

          • TheCee@programming.dev
            link
            fedilink
            arrow-up
            1
            ·
            2 years ago

            This. However, in our specific scenario dynamics were even slightly worse. In a first meeting said consultants apparently met some resistance but management decided to go through with it anyway. So in a later meeting, if I was the consultant, would I go and claim “Alright, I fucked up, got paid and got you gaslighted, but now we have to refactor to clean up our codebase with no immediate tangible benefit for your bosses” in front of everyone? Honestly, I don’t think so.

  • jdeath@lemm.ee
    link
    fedilink
    arrow-up
    2
    ·
    2 years ago

    i like when my strongly typed language can type itself, why should i have to type extra words because the compiler is stupid?

    • Wats0ns@sh.itjust.worksOP
      link
      fedilink
      arrow-up
      7
      arrow-down
      1
      ·
      edit-2
      2 years ago

      So that next time your coworker uses the wrong type, the compiler can scream at him: “NO I WONT COMPILE THIS YOU DUMBASS, LOOK JOHN SAID ON LINE 863 THAT IT SHOULD BE A DOUBLE, NOT A FLOAT FOR FUCK SAKE”

    • tgv@programming.dev
      link
      fedilink
      arrow-up
      1
      arrow-down
      1
      ·
      2 years ago

      So what’s the type of x in

      x = 1;
      x = x + "1";
      

      number? string? string|number? any?

      The ts compiler can make a fair amount of inferences, but at some points you need to nail down the type. Is that so bad?

      • Gecko@lemmy.world
        link
        fedilink
        English
        arrow-up
        4
        arrow-down
        1
        ·
        2 years ago

        Type error unless there’s an implementation of + that specifies adding together and integer and a string.

        • jdeath@lemm.ee
          link
          fedilink
          English
          arrow-up
          5
          arrow-down
          1
          ·
          2 years ago

          💯% accurate. funny how the typescript developer thinks this is some kind of “gotcha!”… like maybe just try a language besides typescript and find out for yourself 😆

          • tgv@programming.dev
            link
            fedilink
            English
            arrow-up
            1
            arrow-down
            1
            ·
            2 years ago

            That’s such a weird take. Who cares what another language does? Your complaint was about typescript. Which lets the programmer decide what this should be. As you could have known.

            But most likely it was just trolling. On the plus side, at least now I know that the rigid minded devs came here too, and took their righteousness with them.

        • nyan@lemmy.cafe
          link
          fedilink
          English
          arrow-up
          2
          arrow-down
          2
          ·
          2 years ago

          Exactly. Most languages I know of that allow this at all will coerce the “1” to an integer and give x = 2. They get away with this because they define the “+” operator as taking numbers only as arguments, so if you hand them x = x + "cheese" they’ll error out.

      • sweeny@sh.itjust.works
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        2 years ago

        I’m not sure if you’re being rhetorical or not, but “string|number” is definitely correct here. A computer could definitely figure this out, but typing is for the benefit of the coders more than the code itself. It’s basically functional documentation

        • tgv@programming.dev
          link
          fedilink
          arrow-up
          2
          ·
          2 years ago

          That’s TypeScript’s whole point. It’s not for the computer, it’s for the programmer. It’s to avoid you assigning a string to something you elsewhere assume to contain a number. In Typescript, there’s just no solution for this, except requiring the programmer to specify the type. It can’t be inferred flawlessly.

          • sweeny@sh.itjust.works
            link
            fedilink
            arrow-up
            1
            ·
            2 years ago

            Yeah that’s what I’m saying, I hate it when coworkers will assign everything as “any” just to avoid the scary red squigglies. Oh well I guess that’s what code reviews are for 🙃

  • Pika@lemmy.world
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    2 years ago

    I’m in this post and I don’t like it.

    That being said I try to have specific types in my typescript but coming from working without typescript, there’s so much more words involved using typescript and for what I use it for I don’t really see the use case. Sure it helps you realize what part of the script needs what data types but it adds so much more complexity in the code that I’m not really sure it’s worth in the first place.

    • noli@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      2 years ago

      Typescript saves ridiculous amounts of time in bugfixes and is IMO a lot more readable than JS.

      I don’t know how many times TS has complained about some type mismatch in my code that made me scratch my head for 2 seconds to only then realize I was doing something stupid. With plain JS that would’ve been no issue, until I have some obscure bug 30 minutes later and have to figure out it’s source.

      Also, whatever piece of code you are working on, to do anything you have to have the types of your variables/functions in mind. If you have to keep track of all of them in your head, you will definitely mess it up at some point or have to look through a bunch of different methods/files to track down the source of some piece of data to be certain what’s contained in it.

      So yeah, TS might take slightly longer to type out, but it saves you a lot of dev time.

      • Pika@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        2 years ago

        I mean I guess that could be helpful, I’ve never really had that issue so I have yet to see the benefit of it. I just find it useless work that you’re typing out for something that the engine itself isn’t going to be able to see anyway, which means you’re going to have to have unit tests coded in regardless. And I wouldn’t say just a little more coding, typescript when implemented into my project doubled the amount of code provided, I’m trying to use it because I do understand it’s a standard, but I really don’t understand why it’s a universal standard, considering that everything it does is completely syntax sugar/coder side and it doesn’t actually interact with the underlying engine. I feel the same way about coffee script honestly.

        • jflorez@sh.itjust.works
          link
          fedilink
          arrow-up
          2
          ·
          2 years ago

          Just wait until you have to work as part of a team on a big project. The lack of types will murder the team’s productivity

  • vithigar@lemmy.ca
    link
    fedilink
    arrow-up
    1
    ·
    2 years ago

    And if you have linter rules preventing any as a boundary type you just use Record<String, any>.

    • mark@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      2 years ago

      Hmmm a more reasonable first step would be to just not even type anything until you’re ready. But TS makes it hard to iteratively type parts of your codebase over time. One could type using JSDoc syntax for these cases, though.

  • ZILtoid1991@kbin.social
    link
    fedilink
    arrow-up
    1
    ·
    2 years ago

    Well, you can always just add the type definitions later on.

    I did port some C code to D, by just pasting it in a D file, then fixing the differences (changing type names, rewriting precompiler macros with D metaprogramming and inline functions, etc.).