Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. let, var, val - Swift, Kotlin, JavaScript

let, var, val - Swift, Kotlin, JavaScript

Scheduled Pinned Locked Moved The Weird and The Wonderful
androidc++javascriptswiftios
24 Posts 11 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D den2k88

    Remember the old times of Basic and VisualBasic, where Let assigned the result of an arithmetical expression (luckily became optional) but if you needed to set a reference in VB you'd better remember it wanted the Set...To keyword or it would crash at the first execution.

    GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

    R Offline
    R Offline
    raddevus
    wrote on last edited by
    #14

    den2k88 wrote:

    Let assigned the result of an arithmetical expression

    Yeah, that's a good one. I first saw let coming back with JavaScript and thought it was a weird throwback. Then Swift brought it back too. Let is taking over again. :)

    1 Reply Last reply
    0
    • D den2k88

      C++/30 will consist entirely of keywords and variables will be inferred by the context.

      GCS d--(d+) s-/++ a C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

      R Offline
      R Offline
      raddevus
      wrote on last edited by
      #15

      den2k88 wrote:

      C++/30 will consist entirely of keywords and variables will be inferred by the context.

      :thumbsup: This is the new movement on the Serverless front and will be referred to as Codeless code. :laugh:

      1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Wait until you see VB.NET's array declarations. They still use the upper bound instead of the length because that's what VB6 did, despite the fact that the reason it did that no longer applies to VB.NET! :-D


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        O Offline
        O Offline
        obermd
        wrote on last edited by
        #16

        Richard Deeming wrote:

        Wait until you see VB.NET's array declarations. They still use the upper bound instead of the length because that's what VB6 did, despite the fact that the reason it did that no longer applies to VB.NET! :-D

        I haven't used an upper bound in a VB.Net array declaration for several years. The upper bound is optional and only really useful if you know ahead of time how big your array will be. Almost all the dotNet framework collection classes support this feature as well. There are times when it's useful but generally you don't need this feature.

        1 Reply Last reply
        0
        • R raddevus

          If you do native iOS (Swift) and native Android (Kotlin now) and web dev (JavaScript), you will find that Swift, Kotlin and JavaScript will have you going crazy in their choice of usage of : let, var, and val They use similar keywords all in different ways. Swift

          let pi = 3.14 // defines constant
          var randValue = 55; // defines variable

          Of course, let does something different in JavaScript. Of course... :sigh: JavaScript

          let x = 1; // outer scope
          var y = 7; // (global scope)

          if (x === 1) {
          let x = 2; // DIFFERENT x (local scope)
          var y = 107; // SAME Y (global scope)

          console.log(x); // expected output: 2
          console.log(y); // expected output : 107
          }
          console.log(x) // expected output: 1
          console.log(y); // expected output: 107

          Kotlin Note: CP doesn't have a choice for Kotlin yet, so val keyword isn't blue.

          val pi = 3.14 // defines constant
          var randValue = 55; // defines variable

          var is used by all three. let is used by Swift and JavaScript differently. val is only used by Kotlin. Language Design Ideas We know everyone steals design ideas from each other, so why didn't the designers of these languages steal from each other and make let and var mean the same darn things?!? X|

          M Offline
          M Offline
          MSBassSinger
          wrote on last edited by
          #17

          Which is why using C# for native iOS and Android apps, as well as MacOS, tvOS, Linux, and web apps (with webassembly) makes so much sense. No Java, no Kotlin, no Swift, no JavaScript (or the myriad of JS libraries). Just C# for them all.

          1 Reply Last reply
          0
          • M Member 9167057

            Recently, I stumbled over C# and C++ meaning rather different concepts with their "array". While I may seem rather snarky here, I think that language designers more often than not explicitly try to remain different from the existing stuff for the sake of, I guess, differentiation for the sake of it.

            K Offline
            K Offline
            kalberts
            wrote on last edited by
            #18

            When I learned the way C# understands arrays, it gave me a deja-vu to Algol 68. In those days (the language definition was published in 1968), hardware wasn't fast enough to make such complex language very useful. Experience with optimizing such constructs were limited, too. So Algol 68 never made it into the mainstream. When I learned about it 10-12 years later (we didn't have a compiler, but studied its concepts, in the university compiler course) we saw it as a collection of great ideas that couldn't be realized in practice, in any useful way. So when I saw C# actually realizing those array concepts, it was sort of like a dream from my student days coming true.

            M 1 Reply Last reply
            0
            • R raddevus

              If you do native iOS (Swift) and native Android (Kotlin now) and web dev (JavaScript), you will find that Swift, Kotlin and JavaScript will have you going crazy in their choice of usage of : let, var, and val They use similar keywords all in different ways. Swift

              let pi = 3.14 // defines constant
              var randValue = 55; // defines variable

              Of course, let does something different in JavaScript. Of course... :sigh: JavaScript

              let x = 1; // outer scope
              var y = 7; // (global scope)

              if (x === 1) {
              let x = 2; // DIFFERENT x (local scope)
              var y = 107; // SAME Y (global scope)

              console.log(x); // expected output: 2
              console.log(y); // expected output : 107
              }
              console.log(x) // expected output: 1
              console.log(y); // expected output: 107

              Kotlin Note: CP doesn't have a choice for Kotlin yet, so val keyword isn't blue.

              val pi = 3.14 // defines constant
              var randValue = 55; // defines variable

              var is used by all three. let is used by Swift and JavaScript differently. val is only used by Kotlin. Language Design Ideas We know everyone steals design ideas from each other, so why didn't the designers of these languages steal from each other and make let and var mean the same darn things?!? X|

              R Offline
              R Offline
              Rick York
              wrote on last edited by
              #19

              The first thing that popped into my head was a line from the movie, "Bull Durham" when Nuke's father says, "let's say a prayer" and Susan Sarandon's character says, "oh, let's not."

              "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

              1 Reply Last reply
              0
              • R raddevus

                If you do native iOS (Swift) and native Android (Kotlin now) and web dev (JavaScript), you will find that Swift, Kotlin and JavaScript will have you going crazy in their choice of usage of : let, var, and val They use similar keywords all in different ways. Swift

                let pi = 3.14 // defines constant
                var randValue = 55; // defines variable

                Of course, let does something different in JavaScript. Of course... :sigh: JavaScript

                let x = 1; // outer scope
                var y = 7; // (global scope)

                if (x === 1) {
                let x = 2; // DIFFERENT x (local scope)
                var y = 107; // SAME Y (global scope)

                console.log(x); // expected output: 2
                console.log(y); // expected output : 107
                }
                console.log(x) // expected output: 1
                console.log(y); // expected output: 107

                Kotlin Note: CP doesn't have a choice for Kotlin yet, so val keyword isn't blue.

                val pi = 3.14 // defines constant
                var randValue = 55; // defines variable

                var is used by all three. let is used by Swift and JavaScript differently. val is only used by Kotlin. Language Design Ideas We know everyone steals design ideas from each other, so why didn't the designers of these languages steal from each other and make let and var mean the same darn things?!? X|

                M Offline
                M Offline
                Maximilien
                wrote on last edited by
                #20

                [obligatory XKCD](https://xkcd.com/927/)

                I'd rather be phishing!

                R 1 Reply Last reply
                0
                • K kalberts

                  When I learned the way C# understands arrays, it gave me a deja-vu to Algol 68. In those days (the language definition was published in 1968), hardware wasn't fast enough to make such complex language very useful. Experience with optimizing such constructs were limited, too. So Algol 68 never made it into the mainstream. When I learned about it 10-12 years later (we didn't have a compiler, but studied its concepts, in the university compiler course) we saw it as a collection of great ideas that couldn't be realized in practice, in any useful way. So when I saw C# actually realizing those array concepts, it was sort of like a dream from my student days coming true.

                  M Offline
                  M Offline
                  Member 9167057
                  wrote on last edited by
                  #21

                  What concepts are those? Because automatically managed dynamic generic type-safe arrays by themselves don't wow me as much, I've been using them extensively in Delphi as well and they're just as comfortable as in C#.

                  K 1 Reply Last reply
                  0
                  • M Member 9167057

                    What concepts are those? Because automatically managed dynamic generic type-safe arrays by themselves don't wow me as much, I've been using them extensively in Delphi as well and they're just as comfortable as in C#.

                    K Offline
                    K Offline
                    kalberts
                    wrote on last edited by
                    #22

                    First and foremost, ragged arrays - a vector of vectors (of vectors of ...), each of a different size. That requires a radically different memory allocation strategy and address calculation strategy. (Algol 68 also allowed arbitrary lower bounds, which unfortunately has not been carried over to C#.) Also, a function argument could be an array of any dimension; it was transferred by a descriptor stating the dimension of the actual argument. I am not sure if the actual argument could be dimensioned at runtime - with all the other mechanisms required for array handling, dynamic sizing woudln't add that much extra :-). Lots of the things you see in Algol 68 (in addition to ragged, dynamically sized arrays) are present / common in languages of today. But Algol 68 preceeded Pascal by two years, it appeared at roughly the same time as Fortran IV. While we were using named COMMON in Fortran, Algol 68 offered dynamic, ragged arrays, with index checks. And pointers. And user defined operators. And threads with semaphore synchronization. And ... It was like a brainstorming language. All the crazy ideas thrown out on the table at the same time. It took quite a few years to mold those ideas into something useful, and learn how they could be realized efficiently. Today we know how. But fifty plus years ago, the ideas seemed rather crazy to those who worried about the different address calculation whether you lay out fixed size, rectangular arrays by row (Pascal) or by column (Fortran). Algol 68 was in a completely different world, at that time.

                    M 1 Reply Last reply
                    0
                    • K kalberts

                      First and foremost, ragged arrays - a vector of vectors (of vectors of ...), each of a different size. That requires a radically different memory allocation strategy and address calculation strategy. (Algol 68 also allowed arbitrary lower bounds, which unfortunately has not been carried over to C#.) Also, a function argument could be an array of any dimension; it was transferred by a descriptor stating the dimension of the actual argument. I am not sure if the actual argument could be dimensioned at runtime - with all the other mechanisms required for array handling, dynamic sizing woudln't add that much extra :-). Lots of the things you see in Algol 68 (in addition to ragged, dynamically sized arrays) are present / common in languages of today. But Algol 68 preceeded Pascal by two years, it appeared at roughly the same time as Fortran IV. While we were using named COMMON in Fortran, Algol 68 offered dynamic, ragged arrays, with index checks. And pointers. And user defined operators. And threads with semaphore synchronization. And ... It was like a brainstorming language. All the crazy ideas thrown out on the table at the same time. It took quite a few years to mold those ideas into something useful, and learn how they could be realized efficiently. Today we know how. But fifty plus years ago, the ideas seemed rather crazy to those who worried about the different address calculation whether you lay out fixed size, rectangular arrays by row (Pascal) or by column (Fortran). Algol 68 was in a completely different world, at that time.

                      M Offline
                      M Offline
                      Member 9167057
                      wrote on last edited by
                      #23

                      Thank you for the explanation.

                      1 Reply Last reply
                      0
                      • M Maximilien

                        [obligatory XKCD](https://xkcd.com/927/)

                        I'd rather be phishing!

                        R Offline
                        R Offline
                        raddevus
                        wrote on last edited by
                        #24

                        That really is the best explanation of the proliferation of programming languages.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups