Jump to content
  • Advertisement
Sign in to follow this  
dave j

BASIC

This topic is 2109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Many many years ago I was asked to alter a program written in BASIC by someone who had been learning to program as they went along. It was obvious that they only discovered subroutines part way through when I found the equivalent of the following in several places throughout the code:

10 REM early bit of code
20 GOSUB 40
30 GOTO 60
40 REM stuff they later decided they wanted to use in several places
50 RETURN
60 REM some more program
70 GOSUB 40
80 REM rest of program
90 END

Share this post


Link to post
Share on other sites
Advertisement

Now i understand where the "dont use goto" come from lol. Using lines numbers to jump is such a dumb idea. I sometime use 1 when i need to jump to the same place from multiples location inside a function, but that about it, and try to avoid them at all cost.

Edited by Vortez

Share this post


Link to post
Share on other sites

The procedural equivalent happens all the time too (where function calls become wrappers to other calls, etc.). It's probably a good way to save time.

 

Want something bad? On some code I worked not long ago somebody didn't figure out how to call subroutines yet, so he resorted to using an IRQ for the job instead... To give you an idea, that's like spawning a new thread just to call a function. Yuck.

Share this post


Link to post
Share on other sites

There are some neat tricks you can do in a similar way to save code-space, for example if you have reoutines to calculate sine and cosine, you can write the function for sine, and instead of writing a very similar function for cosine, you just add an instruction or two ahead of the sine function that shifts the cosine period to align with the sine period, and then continue through the sine function. There's not much reason to use this exact structure where code-space isn't a concern, but its common to see similar things where code-space is limited, such as in microcontrollers.

Share this post


Link to post
Share on other sites

Want something bad? On some code I worked not long ago somebody didn't figure out how to call subroutines yet, so he resorted to using an IRQ for the job instead... To give you an idea, that's like spawning a new thread just to call a function. Yuck.

 

lol

Edited by Vortez

Share this post


Link to post
Share on other sites


Want something bad? On some code I worked not long ago somebody didn't figure out how to call subroutines yet, so he resorted to using an IRQ for the job instead... To give you an idea, that's like spawning a new thread just to call a function. Yuck.


lol

I think that's more of an aaaargh! than a LOL.

Share this post


Link to post
Share on other sites

There are some neat tricks you can do in a similar way to save code-space, for example if you have reoutines to calculate sine and cosine, you can write the function for sine, and instead of writing a very similar function for cosine, you just add an instruction or two ahead of the sine function that shifts the cosine period to align with the sine period, and then continue through the sine function. There's not much reason to use this exact structure where code-space isn't a concern, but its common to see similar things where code-space is limited, such as in microcontrollers.

Compilers will do it for you these days anyway.

 


I think that's more of an aaaargh! than a LOL.

That's an understatement (took me a while to figure out how to deal with that thing...).

Share this post


Link to post
Share on other sites

For those of you who are feeling particularly sadistic, try baysick. It's essentially a BASIC subset in Scala so you can write BASIC in your Scala code. And for those of you who aren't familiar with Scala, Scala is nothing like BASIC.

Share this post


Link to post
Share on other sites

Many many years ago I was asked to alter a program written in BASIC by someone who had been learning to program as they went along. It was obvious that they only discovered subroutines part way through when I found the equivalent of the following in several places throughout the code:
 

10 REM early bit of code
20 GOSUB 40
30 GOTO 60
40 REM stuff they later decided they wanted to use in several places
50 RETURN
60 REM some more program
70 GOSUB 40
80 REM rest of program
90 END

 

 

The horrors of  GOTO  (jumps with index number labels)  would have started in early FORTRANs

 

Any instructor who says "NEVER" use GOTO  may never have done much serious programming  (where they are very useful for abnormal exiting of complex subroutines,  and the horrors of number goto labels are long gone)

Edited by wodinoneeye

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!