Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:10 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Why is the not allowed?

Author Message
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 328
Posted: 03:02pm 26 Oct 2015
Copy link to clipboard 
Print this post

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 Zealand
Posts: 9610
Posted: 03:20pm 26 Oct 2015
Copy link to clipboard 
Print this post

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 States
Posts: 328
Posted: 03:52pm 26 Oct 2015
Copy link to clipboard 
Print this post

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: Germany
Posts: 1593
Posted: 03:54pm 26 Oct 2015
Copy link to clipboard 
Print this post

  Grogster said   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.


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: Germany
Posts: 1593
Posted: 04:15pm 26 Oct 2015
Copy link to clipboard 
Print this post

  Justplayin said   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.


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 Zealand
Posts: 9610
Posted: 04:21pm 26 Oct 2015
Copy link to clipboard 
Print this post

  Justplayin said  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.


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: Australia
Posts: 6283
Posted: 05:34pm 26 Oct 2015
Copy link to clipboard 
Print this post

  Justplayin said   In BASIC, if you need a variable, use what ever you want, whenever you want, as long as it's not a reserved word.

--Curtis

And a simple typo will give you a variable which always stays at zero and very hard to debug.

Jim
VK7JH
MMedit
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025