Allow words "int", "string", "double" and equal them to "let"

Sometimes I automatically type "int variable = 3" instead of "let variable = 3" and then get frustrated why my program is not working.

I would suggest to equal the words "int", "string", "double" and "float" to the word "let".

int var = 3; // exactly the same as "let var = 3;"

That way we achieve two results:

  1. It would be easier to program for those who are naturally inclined to strongly typed languages.
  2. This is some kind of "descriptive static typing" - the language remains static typed, but you can still show the types of the variables to programmer.

int number1 = 3;
string text = number1.toString();
console.log(text); // That would compile smoothly

If int foo = 'bar' is allowed, that would be far more confusing than the "oops, i'm writing a different language" one you describe.

If it isn't allowed, then you're talking about adding a type system, which is a vastly more complex ask than "let's add some aliases for let" (not to mention, what about const? both variants? pick one?)

2 Likes

I can certainly feel your pain. Switching between languages is always a little difficult. The amount of times I forget semicolongs in Java, and yet try to add them in code in other languages that don't need them is astronomical. But, trying to unify the syntax between languages, even when it conceptually doesn't make sense doesn't seem like a great solution. In fact, I don't think there's a good solution to this problem, the problem is at the very heart of the idea of having different languages.

5 Likes

You can already do that

// JSDoc
/** @type {number} */
let i = 0

// or wait for this
// https://github.com/tc39/proposal-type-annotations
let j: number = 0

Also, JS is dynamic, not static-typed