KittyCAD / modeling-app

The KittyCAD modeling app.
https://kittycad.io/modeling-app/download
MIT License
422 stars 35 forks source link

Remove declaration keywords #3985

Closed adamchalmers closed 1 month ago

adamchalmers commented 1 month ago

Many languages, like Rust, JavaScript, Java, etc have a variable declaration keyword, maybe let or const or var 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 preceding let or var or const keywords.

Currently KCL supports let, const and var (they all do the same thing for various historical reasons). According to @jgomez720 the Python-style x = 3 is a more natural syntax for him, as a mechanical engineer. He prefers it to let x = 3 or const 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 or const if possible. Here's a plan for that:

This way, old code (let x = 3) will be accepted and run just fine, but be converted to x = 3 when executed.

adamchalmers commented 1 month ago

Replaces https://github.com/KittyCAD/modeling-app/issues/439

yeroca commented 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.

jtran commented 1 month ago

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.