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.
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4044
Posted: 09:03am 17 Nov 2020
Copy link to clipboard
Print this post
That quote wasn't mine, but no worries.
It's not something I ever took away from Petzold, either, but again no worries - the underlying point is good enough if you read it as "avoid interrupts if at all possible or at least until you grasp how and when/if to use them".
To a fair extent hardware / external things can sometimes force interrupts on a program, but often you're not forced and then can avoid using them (and should, probably).
Yes many low level things may force interrupts on some code somewhere - the OS ideally. It's one job of a good OS to allow most programs to be uncaring and unaware of interrupts, thus making it easier to write most programs AND they're more likely to work right.
When you use interrupts you risk such things as races. Also, ISRs are so easy to get only nearly right and then the debugging is horrid.
John
Cyber Senior Member Joined: 13/01/2019 Location: UkrainePosts: 161
Posted: 06:54am 19 Nov 2020
Copy link to clipboard
Print this post
Changing variables unexpectedly is a common trap. For example: n is a scratchpad number. You use it as a temporary counter in your main code (eg:n=n+1 every time someone touches the touch screen), but the ISR also uses it for looping (eg: FOR n=1 TO 5). Main code is counting presses... interrupt happens... and now your main count is wrong.
Not topic related, but this particular issue could be easily solved by adding LOCAL N at the beginning of ISR.
Even better is adding OPTION EXPLICIT at the beginning of program - this approach saved me a lot from accidently changing variable values.
Cyber Senior Member Joined: 13/01/2019 Location: UkrainePosts: 161
Posted: 06:56am 19 Nov 2020
Copy link to clipboard
Print this post
It's not something I ever took away from Petzold, either, but again no worries - the underlying point is good enough if you read it as "avoid interrupts if at all possible or at least until you grasp how and when/if to use them".
This is a very good interpretation. Thank you.
MustardMan Senior Member Joined: 30/08/2019 Location: AustraliaPosts: 175
Posted: 09:21am 19 Nov 2020
Copy link to clipboard
Print this post
Even better is adding OPTION EXPLICIT at the beginning of program - this approach saved me a lot from accidentally changing variable values.
It should be mandatory!
It is one of the few things (maybe the only thing?) that can save you from misspelling a1 (one) as al (ell) or b0 (zero) as bO (cap oh). With select fonts, they look exactly the same.
Despite what nay-sayers say, BASIC is quite a capable language (especially MM-BASIC). It is a pity BASIC has gained such a bad reputation over the years, has to hold onto legacy compatibility, and won't stop you from doing horrible things.
Then again, C will let you do even horribler things (just different horribler things).