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

    • @pivot_root@lemmy.world
      link
      fedilink
      6
      edit-2
      3 hours ago

      Rust is verbose, but C++ might still take the cake with its standard library templates. Especially when using fully-qualified type names…

      auto a = ::std::make_shared<::std::basic_string<char, ::std::char_traits<char>, MyAllocator<char>>>();

      A reference-counted shared pointer to a string of unspecified character encoding and using a non-default memory allocator.

        • @pivot_root@lemmy.world
          link
          fedilink
          2
          edit-2
          2 hours ago

          std::string doesn’t have a template type for the allocator. You are stuck using the verbose basic_string type if you need a special allocator.

          But, of course, nobody sane would write that by hand every time. They would use a typedef, like how std::string is just a typedef for std::basic_string<char, std::char_traits<char>, std::allocator<char>>. Regardless, the C++ standard library is insanely verbose when you start dropping down into template types and using features at an intermediate level. SFINAE in older versions of C++ was mindfuck on the best of days, for example.

          Don’t get me wrong, though. I’m not saying Rust is much better. Its saving grace is its type inference in let expressions. Without it, chaining functional operations on iterators would be an unfathomable hellscape of Collect<Skip<Map<vec::Iter<Item = &'a str>>>>

          • @Ajen@sh.itjust.works
            link
            fedilink
            31 hour ago

            Yeah, I missed the custom allocator at first. I thought I deleted my comment fast enough, but I guess you were faster. :)

  • @marcos@lemmy.world
    link
    fedilink
    338 hours ago

    Good, now invent a keyword for variables you don’t want to declare the type. And now that you have a mix of keywords and identifiers on the same place, you can never update your language again.

    Also, make the function declarations not use a keyword too, so you get the full C-style madness of code that changes meaning depending on what libraries you import.

    • @stingpie@lemmy.world
      link
      fedilink
      107 hours ago

      I don’t understand how not using a keyword to define a function causes the meaning to change depending on imports. I’ve never run into an issue like that before. Can you give an example?

      • @marcos@lemmy.world
        link
        fedilink
        26 hours ago

        Some declarations terminate on the name, other declarations go one requiring more tokens. In C, the only thing that differentiates them is the type.

        Parenthesis in particular are completely ambiguous. But asterisks and square brackets also create problems.

    • Voytrekk
      link
      fedilink
      English
      6
      edit-2
      7 hours ago

      C++ has auto, which determines the type automatically.

        • @sus@programming.dev
          link
          fedilink
          8
          edit-2
          7 hours ago

          So I think it’s still probably unclear to people why “mix of keywords and identifiers” is bad: it means any new keyword could break backwards compatibility because someone could have already named a type the same thing as that new keyword.

          This syntax puts type identifiers in the very prominent position of “generic fresh statement after semicolon or newline”

          …though I’ve spent like 10 minutes thinking about this and now it’s again not making sense to me. Isn’t the very common plain “already_existing_variable = 5” also causing the same problem? We’d have to go back to cobol style “SET foo = 5” for everything to actually make it not an issue

          • @AnotherPenguin@programming.dev
            link
            fedilink
            English
            13 hours ago

            At least in C#, you can define variables with keyword names like this:

            var @struct = “abc”

            I think in Kotlin you can do the same, and even include spaces with backticks like val abstract class = “abc”

            I’m not sure if other languages allow that, regardless it should be rarely used.

            • @pivot_root@lemmy.world
              link
              fedilink
              23 hours ago

              Swift also uses backticks and Rust has a dumb one in the form of r#thekeyword. Still much better than introducing a async as a new keyword in a minor version of a language and breaking a bunch of libraries.

          • @piccolo@sh.itjust.works
            link
            fedilink
            37 hours ago

            Ah I was misunderstanding the problem. And learned something new about C#, seems in order to avoid breaking existing code they introduce “contextual keywords” var being added later, it is a contextual. You can create a class ‘var’ and the compiler will prefer it.

  • DreamButt
    link
    fedilink
    English
    13
    edit-2
    8 hours ago

    Because sometimes that let can be replaced by other things like const. Which can be managed statically by the machine and not by my (imperfect) ability to know if it’s mutated or not

    • @Scoopta@programming.dev
      link
      fedilink
      18 hours ago

      Ok but, in the second example you typically just put final or const in front of the type to denote immutability. I still don’t see the advantage to the first declaration.

      • DreamButt
        link
        fedilink
        English
        18 hours ago

        oh for sure, but I think that’s the rarer case for language implementions. Having a consistent structure with alternative keywords in static positions is just easier to develop an AST for. Personally my favorite language doesn’t even allow for const values (except by convention) so it’s really just a matter of preference

        • @Scoopta@programming.dev
          link
          fedilink
          17 hours ago

          Is it rarer? I think a lot of modern languages go for the first option but pretty much all C style languages use the latter. It’s probably a wash for which is more popular I’d think.

          • DreamButt
            link
            fedilink
            English
            17 hours ago

            I’m talking about quantity not the popularity of a given language. There are certainly a number of popular languages that follow that convention

  • GreatRam
    link
    fedilink
    3710 hours ago

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

    • @Hotzilla@sopuli.xyz
      link
      fedilink
      14 hours ago

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

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

    • @masterspace@lemmy.ca
      link
      fedilink
      English
      269 hours 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.

      • Psaldorn
        link
        fedilink
        79 hours ago

        If there’s only two options you only need one keyword

        • @Hotzilla@sopuli.xyz
          link
          fedilink
          1
          edit-2
          4 hours 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
      159 hours 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.

  • @JakenVeina@midwest.social
    link
    fedilink
    7
    edit-2
    7 hours ago

    Not to short-circuit the joke, but in this case, it’s because the valid JavaScript version is…

    let a
    

    …and one of TypeScript’s main design goals is to be a superset of JavaScript, that only adds syntax, and doesn’t re-write it.

    Beyond that, it’s probably a case of some new language just using what the designer is familiar with.

  • tisktisk
    link
    fedilink
    English
    139 hours ago

    I’ve always wondered where all this ‘let’ business started

    • @HiddenLayer555@lemmy.mlOP
      link
      fedilink
      English
      22
      edit-2
      9 hours ago

      It’s commonly used in math to declare variables so I assume programming languages borrowed it from there.

      • @chaos@beehaw.org
        link
        fedilink
        53 hours ago

        More specifically, they’re borrowing the more mathematical meaning of variables, where if you say x equals 5, you can’t later say x is 6, and where a statement like “x = x + 1” is nonsense. Using “let” means you’re setting the value once and that’s what it’s going to remain as long as it exists, while “var” variables can be changed later. Functional languages, which are usually made by very math-y people, will often protest the way programmers use operators by saying that = is strictly for equality and variable assignment is := instead of == and = in most C-style languages.

      • @bandwidthcrisis@lemmy.world
        link
        fedilink
        59 hours ago

        BASIC uses (used?) it to declare variables. (I don’t know if earlier languages did.)

        Not that that’s a reason for other languages to copy it.

          • @dan@upvote.au
            link
            fedilink
            8
            edit-2
            9 hours ago

            Older variants used DIM for arrays and LET for other variables. DIM was originally called that because it was setting the dimensions of the array.

            In modern BASIC variants, DIM has become a backronym: “declare in memory”.

            • tisktisk
              link
              fedilink
              English
              49 hours ago

              TIL Backronyms and cuil BASIC technicalities Much obliged all

            • @marcos@lemmy.world
              link
              fedilink
              28 hours ago

              Even older variants required both a let to declare the variable and a dim to set its size.

              I remember a REDIM command, but I really can’t remember what basic it’s from.

              • @dan@upvote.au
                link
                fedilink
                27 hours ago

                The first programming language I used was Visual Basic (both VBA in Excel, and VB3 then VB6). I think it used redim to resize arrays.

      • tisktisk
        link
        fedilink
        English
        38 hours ago

        I doubted you until I got about halfway through this whole page. I concede tho–you are most correct lol Still a decent read and for that I thank you

  • @dan@upvote.au
    link
    fedilink
    79 hours ago

    Can we talk about PHP functions with typehints too?

    public static function foo(): string {
    

    Practically every other language with similar syntax does this instead:

    public static string foo() {
    
    • @HiddenLayer555@lemmy.mlOP
      link
      fedilink
      English
      69 hours ago

      TIL PHP has statics.

      Also, does PHP actually enforce the type declarations? I’d assume it would but knowing PHP…

    • @calcopiritus@lemmy.world
      link
      fedilink
      27 hours ago

      JavaScript (Typescript for the type part) and python, the most popular scripting languages, use the same order as PHP.

      It’s usually compiled languages that do the other one.

      • @dan@upvote.au
        link
        fedilink
        16 hours ago

        TypeScript doesn’t need the “function” keyword for a method in an object or on a class though.

        const foo = {
          bar(): string {
           ... 
          } 
        }
        

        which I assume is doable because the syntax is unambiguous.

        In PHP’s case, the method syntax should also be unambiguous.

  • @Oisteink@feddit.nl
    link
    fedilink
    28 hours ago

    First time i used let it was to inline variable declaration with assignment . Can’t remember the language.