Made with KolourPaint and screenshots from Kate (with the GitHub theme).

  • GreatRam@lemmy.world
    link
    fedilink
    arrow-up
    49
    ·
    2 days ago

    You’re encoding more information in the typescript one. You’re saying it’s a string that will get updated.

    • masterspace@lemmy.ca
      link
      fedilink
      English
      arrow-up
      31
      ·
      2 days ago

      Yeah, it’s explicitly distinct from const a: String which says it won’t change, and var a: String, which means this is legacy code that needs fixing.

        • Lemminary@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          1 hour ago

          Ah, but this is JS, so there are three options! And they all function entirely differently. And your assumptions don’t apply, either. :D

        • Hotzilla@sopuli.xyz
          link
          fedilink
          arrow-up
          5
          ·
          edit-2
          2 days ago

          True, but var and let are not same in js, so there is three.

          if(true) {

          var a = "dumdum"

          }

          console.log(a)

          Is valid and functioning javascript. With let it is not.

    • Scoopta@programming.dev
      link
      fedilink
      arrow-up
      17
      ·
      2 days ago

      You aren’t though. In most languages that use the latter declaration you would prefix the declaration with final or const or the like to specify it won’t be updated.

      • calcopiritus@lemmy.world
        link
        fedilink
        arrow-up
        13
        ·
        2 days ago

        It’s also valid rust syntax.

        But if it were rust, this meme would not make sense, since you would just type let a and type inference would do its thing. Which is much more ergonomic.

            • nebeker@programming.dev
              link
              fedilink
              English
              arrow-up
              3
              ·
              18 hours ago

              And bow to the compiler’s whims? I think not!

              This shouldn’t compile, because .into needs the type from the left side and let needs the type from the right side.

        • Victor@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          1 day ago

          Type inference is a pretty big thing in TypeScript as well though. In fact it’s probably the biggest thing about it, IMO.

          • calcopiritus@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            1 day ago

            I don’t know typescript. But if that’s the case, this meme doesn’t make much sense.

            Who writes the types of variables in a language with type inference unless forced by the compiler?

            • Victor@lemmy.world
              link
              fedilink
              arrow-up
              1
              ·
              1 day ago

              Maybe it’s a language without type interference?

              Either way, it sometimes makes sense in TypeScript to help the type system out a little bit.

              let array: string[] = [];
              

              In this situation, the type system can’t infer that the empty array should be a string array, because there are no items to go by.

            • Victor@lemmy.world
              link
              fedilink
              arrow-up
              1
              ·
              2 hours ago

              Probably would still use TypeScript, because I use that for work. 🤷‍♂️ Rust just seems like… a lot. Regarding Rust, I’ve seen a lot of praises and a not so insignificant amount of complaints that make me very hesitant to take the plunge. Can’t remember off the top of my head what it was, specifically, but it was enough for me to write it off, that much I remember.

              • porous_grey_matter@lemmy.ml
                link
                fedilink
                arrow-up
                1
                ·
                57 minutes ago

                People really overstate it, it’s not that hard. It has a reputation of being difficult because people use it for difficult, low-level tasks, OS stuff, parsers, cryptography, highly optimised serialisation, but those things would be hard in any language. For a newcomer it’s, IMO, way easier than say C++, because it doesn’t have a mindbogglingly huge std lib with decades of changing best practices to try to figure out. To do simpler things in it is really pretty straightforward, especially if you’re already comfortable with a robust type system.

    • Hotzilla@sopuli.xyz
      link
      fedilink
      arrow-up
      3
      ·
      2 days ago

      C# has const string a = “Hello, World”;

      var in js is legacy, and default should be let, but changing that would break everything