I believe that the constants are replaced with actual values during the pre-compile, so it compiles because the compiler sees this instead of your original code:
I'm saying the compiler/precompiler shouldn't allow constants and variables to have the same name. Try this in any other BASIC compiler:
const my_number = 123
my_number = 666
For that matter, try this is PB:
my_number.l = 123
my_number.f = 3.14159
Why should like-named variables and constants be allowed but not like-named variables of different types? No "maximum flexibility" there.
Because PureBasic is "special", people sometimes forget to prepend the # character to the constant name, leaving them with a stray like-named variable.
---------------------------
PureBasic
---------------------------
Line 2: Variable already declared with another type: my_number
---------------------------
OK
---------------------------
So what's the problem?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Nothing leaps out and says "constant". good discipline suggests prefixing to give clues, you would probably want to call it
const constIntervalValue = 123 ' or even constIntIntervalValue
so you know it is a constant (and an integer).
Just MHO, but the PB way is pretty good. It is instantly clear when you are dealing with constants because of the leading #, which is also part of the name.
---------------------------
PureBasic
---------------------------
Line 2: Variable already declared with another type: my_number
---------------------------
OK
---------------------------
So what's the problem?
The problem is that this code does not generate an error:
> The problem is that this code does not generate an error
Well, I was actually replying to your invitation to run the .l and .f example,
which does in fact give an error about duplicate variable names.
> people sometimes forget to prepend the # character to the constant name
Not PureBasic's problem. The # character is part of the name, so what you're
saying is no different to someone using two variables called "boo" and "boot"
and then forgetting to add the "t" when referring to the second one. Should
PureBasic not allow both these names too?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Or writing a word starting with c when they should write the word meaning the wife of the uncle.
*ducks and runs away*
Edit: The #, as opposed to the t, is not really pronounced, that's the difference. On the other hand, I think we need to disallow "aunt" then, until we start pronouncing the other word also.