![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I am not sure why BASIC needs to have unassigned variables. What is the benefit of asking the user to assign each variable rather than setting by default all variables to NULL. There is the CLEAR and CLEARCOMMON commands that set all variables to zero not NULL which is a problem when you deal with strings instead of numbers. The space for variables is anyhow allocated and a value of NULL would make the variable work as a number as well as a string. Maybe someone knows the reasons for this BASIC choice. Lucian |
#3
| |||
| |||
|
|
"x" wrote I am not sure why BASIC needs to have unassigned variables. *What is the benefit of asking the user to assign each variable rather than setting by default all variables to NULL. *There is the CLEAR and CLEARCOMMON commands that set all variables to zero not NULL which is a problem when you deal with strings instead of numbers. The space for variables is anyhow allocated and a value of NULL would make the variable work as a number as well as a string. Maybe someone knows the reasons for this BASIC choice. Lucian Well, if you prefer your variables to default to empty strings I guess you could just start using shell variables... * *at TCL if you do * * * * * * set * foo=tom dick harry * then later in a basic program do * * * *crt *'shell variable foo was ':@foo ;execute 'unset foo'capturing bucket * * * *crt *'shell variable bar is ':@bar * *where either you had never *done any * set *bar=stuff * * * * * * * * * *or had most recently done * unset * bar * then your basic program will happily assume bar exists but has * * * * empty string as the contents. Oh, and *in D3 * assigned(@bar) * *is invalid syntax, yet * * * *assigned(bar) * *presumes your interest was in a regular variable I like to use them to pass temporary debugging info down / up a string of * * subroutine calls; * much tidier than adding an additional subroutine arg * * or a new entry in COMMON *or arranging a temporary disk file / item... |
#4
| |||
| |||
|
|
I am not sure why BASIC needs to have unassigned variables. |
#5
| |||
| |||
|
|
On 2010-11-11 21:22:09 -0500, x <lucian_p... (AT) yahoo (DOT) com> said: I am not sure why BASIC needs to have unassigned variables. I believe that it prevents subtle errors, such as typos in variable names. *Automatically setting every new variable to NULL would mask such errors, leading to more difficult debugging. -- Kevin Powick |
#6
| |||
| |||
|
|
On Nov 12, 7:39 am, Kevin Powick <nos... (AT) spamless (DOT) com> wrote: On 2010-11-11 21:22:09 -0500, x <lucian_p... (AT) yahoo (DOT) com> said: I am not sure why BASIC needs to have unassigned variables. I believe that it prevents subtle errors, such as typos in variable names. Automatically setting every new variable to NULL would mask such errors, leading to more difficult debugging. Kevin beat me to it. Once you've had to work on nine thousand line programs, trust me, you will love the idea that it tells you when you have a variable typo. |
#7
| |||
| |||
|
|
Don't rely on the compiler to catch unassigned variables! Just because you've seen the compiler point it out: Warning: Variable 'X' never assigned a value Doesn't mean that it will catch something at compile time that doesn't happen until run time. Here's a program that compiles cleanly, yet fails when run: CRT X X = "YO!" |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
Should the compiler restrict variable usage ? |
|
Once you have a file handle "A" you should not use the name "A" for anything else. Once you have used "B" as a number you should not be able to build "B" as a string. What do you think ? |
#10
| |||
| |||
|
|
A = 22 CRT 'The temperature is ':IntToStr(A):' degrees.' |
![]() |
| Thread Tools | |
| Display Modes | |
| |