3 ms·
I understand that you can announce variable, but to be save, you'll have to announce it in every scope you want to declare it, so why not just use "var" or ":="
by dchest 11y ago
I understand that you can announce variable, but to be save, you'll have to announce it in every scope you want to declare it, so why not just use "var" or ":=" to declare and assign?
- yosbelms 11y agoLooking for simplicity. One of the goals of Cor is to have few keywords, to make it easy to learn, to get involved, and to work with. I had three possible solutions to solve the variable scoping problem. 1- `var` keyword. Like javascript. It assumes all variables are global if not declared with `var`. 2- `global` keyword. Like PHP. It assumes all variables are local unlike that is annotated with `global`. 3- Ruby-like, Coffeescript-like. A mixing of options number 1 and 3 was chosen. I will open an issue regarding this subject, considering your proposal for future versions.
- dchest 11y agoThank you. Actually, what I think the best way is to make it an error to use undeclared variable, unlike in JavaScript. If it's a global, is should be declared in global scope. I really like this way of declaring variables, so please consider it: someVar := 123 //declared and assigned someVar = 456 // reassigned anotherVar = 777 // error: undeclared variable