devicefuture / atto

The new BASIC computer that runs in your browser!
https://atto.devicefuture.org
MIT License
47 stars 8 forks source link

editor detects and breaks program when reserved words are within variables #14

Open carloshm opened 3 years ago

carloshm commented 3 years ago

when part of a variable includes a reserved word it breaks: 10 cls 20 radius=10 30 print radius run Unexpected = at line 20 Ready

James-Livesey commented 3 years ago

This is an interesting behaviour of many BASICs, including BBC BASIC (which is one of the main BASICs I was considering when researching the mechanics of atto). See what happens in BBC BASIC:

BBC BASIC Keyword-Variable Conflict

The syntax highlighting of the bbcmic.ro editor demonstrates the conflict: image

The main rationale behind this behaviour is to enable the ability to collapse spaces in code, making lines shorter (which is particularly useful for fitting code in Tweets to send to our Twitter bot).

I might consider preventing this behavour, though — I agree that it's a bit counter-intuitive in some situations! There might be a few issues with regards to backward compatibility, but to be honest, there aren't going to be many programs that will suffer from this issue.

There are cases in documentation where the reference to conflicting variable names has been avoided (eg. see pi - atto guide), so I have been aware about this problem for some time! I think that there's two things to think about before fixing this issue though — how frequent conflicting variable identifiers appear (eg. how many frequently-used variable names will start with rad or to?), and whether freedom will be lost in making projects that are designed to fit in a tight character space (eg. Twitter's 280 char limit).

Thankfully, keywords for constants don't cause conflicting variable names — not being able to start a variable name with e (Euler's number) would be frustrating to many! It could be possible to add some smart variable name vs keyword detection system, though behaviour might be hard to predict as a user.

Thanks for the issue, though. I'll have to have a think about it, and I'd love to know what others think about conflicting variables!