let, var, val - Swift, Kotlin, JavaScript
-
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
, andval
They use similar keywords all in different ways. Swiftlet pi = 3.14 // defines constant
var randValue = 55; // defines variableOf 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: 107Kotlin 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 variablevar
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 makelet
andvar
mean the same darn things?!? X| -
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
, andval
They use similar keywords all in different ways. Swiftlet pi = 3.14 // defines constant
var randValue = 55; // defines variableOf 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: 107Kotlin 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 variablevar
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 makelet
andvar
mean the same darn things?!? X|raddevus wrote:
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
andvar
mean the same darn things?!? X|Because, according to marketing-ideas, the language needs its own "identity". In a few years, C# will have more keywords than those three languages combined :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
raddevus wrote:
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
andvar
mean the same darn things?!? X|Because, according to marketing-ideas, the language needs its own "identity". In a few years, C# will have more keywords than those three languages combined :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Eddy Vluggen wrote:
Because, according to marketing-ideas, the language needs its own "identity".
Yeah, I guess so. Everyone says, "Our let is the best let of all." :)
Eddy Vluggen wrote:
In a few years, C# will have more keywords than those three languages combined
:thumbsup: :laugh:
-
Eddy Vluggen wrote:
Because, according to marketing-ideas, the language needs its own "identity".
Yeah, I guess so. Everyone says, "Our let is the best let of all." :)
Eddy Vluggen wrote:
In a few years, C# will have more keywords than those three languages combined
:thumbsup: :laugh:
-
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
, andval
They use similar keywords all in different ways. Swiftlet pi = 3.14 // defines constant
var randValue = 55; // defines variableOf 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: 107Kotlin 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 variablevar
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 makelet
andvar
mean the same darn things?!? X|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.
-
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
, andval
They use similar keywords all in different ways. Swiftlet pi = 3.14 // defines constant
var randValue = 55; // defines variableOf 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: 107Kotlin 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 variablevar
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 makelet
andvar
mean the same darn things?!? X| -
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
, andval
They use similar keywords all in different ways. Swiftlet pi = 3.14 // defines constant
var randValue = 55; // defines variableOf 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: 107Kotlin 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 variablevar
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 makelet
andvar
mean the same darn things?!? X|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 theSet...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
-
raddevus wrote:
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
andvar
mean the same darn things?!? X|Because, according to marketing-ideas, the language needs its own "identity". In a few years, C# will have more keywords than those three languages combined :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
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
-
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.
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
-
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 theSet...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
VB6 and earlier needed
Set
andLet
because of non-indexed default properties, which thankfully went away when .NET was first released. For example:Dim rst As ADODB.Recordset
Set rst = ...Dim foo As Variant
foo = rst["Bar"]- The
Recordset
class doesn't have an indexer, but it has a default property calledFields
which does. - The indexer returns an
ADODB.Field
object, with a non-indexed default property calledValue
. - At this point, the compiler wouldn't know whether you want the variable to contain the field object or the field's value.
- Therefore you have to use
Set
if you want the field object, andLet
(or nothing) if you want the value.
Fun times! X|
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
- The
-
VB6 and earlier needed
Set
andLet
because of non-indexed default properties, which thankfully went away when .NET was first released. For example:Dim rst As ADODB.Recordset
Set rst = ...Dim foo As Variant
foo = rst["Bar"]- The
Recordset
class doesn't have an indexer, but it has a default property calledFields
which does. - The indexer returns an
ADODB.Field
object, with a non-indexed default property calledValue
. - At this point, the compiler wouldn't know whether you want the variable to contain the field object or the field's value.
- Therefore you have to use
Set
if you want the field object, andLet
(or nothing) if you want the value.
Fun times! X|
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
It was also needed with custom VB classes and objects with no default property. A "nice" syntactic requirements in a langauge that did not have references or pointers (but then the hidden VarPtr, StrPtr and another function whose name I forgot came to help).
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
- The
-
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.
Member 9167057 wrote:
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.
I think you may be correct. The two languages which are extremely similar are Java & C#. I wrote an app as a C# desktop app and then wrote it as a Android app (Java) and there was a lot of code that translated without any changes -- the pure language stuff / syntax.
-
-
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 theSet...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
-
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
-
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
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.
-
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
, andval
They use similar keywords all in different ways. Swiftlet pi = 3.14 // defines constant
var randValue = 55; // defines variableOf 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: 107Kotlin 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 variablevar
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 makelet
andvar
mean the same darn things?!? X|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.
-
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.
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.
-
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
, andval
They use similar keywords all in different ways. Swiftlet pi = 3.14 // defines constant
var randValue = 55; // defines variableOf 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: 107Kotlin 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 variablevar
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 makelet
andvar
mean the same darn things?!? X|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?"
-
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
, andval
They use similar keywords all in different ways. Swiftlet pi = 3.14 // defines constant
var randValue = 55; // defines variableOf 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: 107Kotlin 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 variablevar
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 makelet
andvar
mean the same darn things?!? X|[obligatory XKCD](https://xkcd.com/927/)
I'd rather be phishing!