Closed adamchalmers closed 1 month ago
Some folks may wonder why they keyword disappears when auto-formatting their code. Do you have a method of highlighting code to show a warning? If so you can call the keywords out as deprecated.
Sorry for the trouble this may have caused. In the future, we'll try to do things like have auto-migration and lint auto-fix. But it's a lot of work. We're still in the pre-1.0 phase where we're making breaking changes.
Many languages, like Rust, JavaScript, Java, etc have a variable declaration keyword, maybe
let
orconst
orvar
or something else (like the variable's type).Not all languages have a declaration keyword! Python and Matlab both declare variables via
x = 3
with no precedinglet
orvar
orconst
keywords.Currently KCL supports
let
,const
andvar
(they all do the same thing for various historical reasons). According to @jgomez720 the Python-stylex = 3
is a more natural syntax for him, as a mechanical engineer. He prefers it tolet x = 3
orconst x = 3
.So, KCL should probably imitate Python, and remove the variable declaration keywords.
Justification
If KCL had mutation, it'd be important to have an explicit declaration keyword. That way users could tell when a variable comes into being and when it is/is not in scope or is redefined. Without mutation, that isn't as big of a problem for KCL.
Implementation
We want to avoid breaking existing code that uses
let
orconst
if possible. Here's a plan for that:VariableDeclaration
to make the keyword (let/const/var) optional.This way, old code (
let x = 3
) will be accepted and run just fine, but be converted tox = 3
when executed.