Author |
Topic: BEGINNER (Read 1053 times) |
|
Ken Down
Guest
|
 |
Re: BEGINNER
« Reply #6 on: Mar 31st, 2010, 04:04am » |
|
For the sake of readability, use upper case for BASIC keywords and lower case for variables. Did you realise that you can have more than one DIM statement on a line? eg: DIMx%(5),a$(3),z%50 Integer variables run just slightly faster than real variables, so numeric variables of the form x% or draw%(20) are better where speed may be important.
|
|
Logged
|
|
|
|
David Williams
Developer
member is offline

meh

Gender: 
Posts: 452
|
 |
Re: BEGINNER
« Reply #7 on: Mar 31st, 2010, 04:10am » |
|
on Mar 31st, 2010, 04:04am, Guest-Ken Down wrote:| Integer variables run just slightly faster than real variables, so numeric variables of the form x% ... are better where speed may be important. |
|
And the (capital letter) static integer variables (A%, B%, C%, ..., Z%) may be even better in that case.
David.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BEGINNER
« Reply #8 on: Mar 31st, 2010, 08:38am » |
|
on Mar 30th, 2010, 11:44pm, Guest-L GRIFFIN wrote:| I could not see how your prog. checked for duplicates |
|
It works exactly like a lottery machine: it picks the first number from the full set of 49, then it picks the second number from the remaining 48, then it picks the third number from the remaining 47, etc. Hence it doesn't generate duplicates.
Quote:| Put the code in a loop and it churned out duplicates at random. |
|
You're right - there was a bug in the code! The line:
Code: should be:
Code: Sorry about that.
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BEGINNER
« Reply #9 on: Mar 31st, 2010, 09:01am » |
|
on Mar 31st, 2010, 04:04am, Guest-Ken Down wrote:| Integer variables run just slightly faster than real variables, so numeric variables of the form x% or draw%(20) are better where speed may be important. |
|
Integer variables may run faster than real variables, but that is not a relevant comparison in this case because the OP is not using real variables but variant variables (he is storing integer values in the variables). Integer variables do not run significantly faster than variant variables (and they make the program longer):
Code: i = 123456
i% = 123456
TIME = 0
FOR I% = 1 TO 1000000
j = i + i + i + i + i + i + i + i + i + i : NEXT
PRINT TIME
TIME = 0
FOR I% = 1 TO 1000000
j% = i% + i% + i% + i% + i% + i% + i% + i% + i% + i% : NEXT
PRINT TIME It's true that the static integer variables do run faster, but that's a separate issue.
Note that Acorn versions of BBC BASIC don't have variant variables, so with those there may well be a speed advantage in using integer variables rather than real variables. However this group is specific to BBC BASIC for Windows which, like BBC BASIC (Z80) and BBC BASIC (86) has variant variables.
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: BEGINNER
« Reply #10 on: Mar 31st, 2010, 09:10am » |
|
on Mar 31st, 2010, 04:04am, Guest-Ken Down wrote:| For the sake of readability, use upper case for BASIC keywords and lower case for variables. |
|
The preferred naming convention is lower case for local (and private) variables, capitals for constants and a mixture of lower and upper case for global variables.
Because BBC BASIC for Windows supports asynchronous interrupts (e.g. ON SYS and ON TIME) it is important that global and local variables never share the same name. Because you don't (in principle) know what variable names are used in libraries and other CALLed or INSTALLed modules, adhering to a strict naming convention is the only guarantee of that.
Richard.
|
|
Logged
|
|
|
|
|