![]() |
Forum Index : Microcontroller and PC projects : Why is the not allowed?
Author | Message | ||||
Justplayin![]() Guru ![]() Joined: 31/01/2014 Location: United StatesPosts: 328 |
I have run into this at least half a dozen times today where I have related numerical and string data that I wish to use the same names for for easy reference. In every version of BASIC I have ever used, DAY$ and DAY, year and year$, Colors and Colors$ are valid and unique variables. Why doesn't it work in MMBASIC? I believe it use to work. It is driving me absolutely crazy! --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
This is a recent change, so I understand, which is why it would have worked OK for you in a previous version. As I understand things, this is a lightweight forced syntax change - other more rock-solid changed are via the OPTION EXPLICIT command. I too have run into this, and it throws me for exactly the same reasons as you. I think the idea behind having this change is to promote good coding practise by not allowing variables of different type with the same name, to help prevent obscure bugs and make debugging easier for all, as there is no way for DAY$ and DAY to be confused - they are simply not allowed to start with. You could use something like DAY_S$ and DAY_V - for DAY_S(tring) and DAY_V(ariable) Time to get inventive with your variable names! ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
Justplayin![]() Guru ![]() Joined: 31/01/2014 Location: United StatesPosts: 328 |
Looks more like a C programmers idea of what BASIC should be like. Same for "Option Explicit". In BASIC you should not have to define your variables ahead of time! In BASIC, if you need a variable, use what ever you want, whenever you want, as long as it's not a reserved word. Enough of my griping about language "modifications". --Curtis I am not a Mad Scientist... It makes me happy inventing new ways to take over the world!! |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
Yes! But there is one point more: Since you can use "Dim as string day" you (and your Mite) can't distinguish day as string and day as a numeric variable. I think it makes sense not allow identical names. Regards Michael causality ≠ correlation ≠ coincidence |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
Hi Curtis, it depends on which Basic dialect you mean. The old ZX80, PET, Acorn Basic or the more modern MS VB Basic from 1991-.... for exanple. There are pros and cons ... As you can see here. Readability and maintenance-friendliness are important things. Especially for large programs. Just my 2c ![]() Michael causality ≠ correlation ≠ coincidence |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9610 |
You have a point there, and that is one thing about BASIC I did like. However, that being said, I do see the merits of not allowing duplicate names, and MMBASIC must be considered a high-level BASIC language by these days - what with all the things it can do, and Cfunctions/Csubs etc - it is not your average BASIC anymore. ![]() ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
And a simple typo will give you a variable which always stays at zero and very hard to debug. Jim VK7JH MMedit |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |