So Here are Some Steps through which you can easily structure your Programming Code

By ridhigrg |Email | Apr 22, 2019 | 1413 Views

Programming a code seems like you are reading a dictionary where one could learn certain words and their meanings with limited information on how one could construct them into entire sentences to write a document. Every programmer who has dabbled in basic has probably come across the famous "Hello Word" routine which consists of a two-line program that prints this phrase unlimited times on the screen.

Your program code needs to be written as step-by-step instructions using the commands that your choice of programming language understands. It means reading your programming manual to learn which commands you need to use for what you want your program to do. In the "Hello World" example you would first need a command that prints "Hello World" onto the screen, and then you would need a second command to print it again multiple times, without writing multiple print statements.

The best structure for writing any program code is to make it clear and easy to follow. Some programmers put multiple commands on one line which can make your code difficult to follow if you are trying to iron out bugs. Spreading your code over multiple lines actually makes the program work better and becomes more readable.

Another recommended practice is to separate each part of your program code using REM Statements. REM allows you to put comments before each section of code to remind you what each part does. This is especially useful if you wish to edit your code at a later date.

10 rem Set Up Variables 
20 let A=1: let B=2 
30 rem ******* 
40 rem Print Variables to Screen 
50 rem ******* 
60 print A,B

Anything after the REM command is ignored by the computer and you can use as many REM statements as you want to make bigger gaps in your code for easy reading. Other programming languages allow you to use blank lines or indent the first line of the routine.

Now here you will see how you how to structure the entire program code. Remember that the computer needs to follow step-by-step instructions so you need to write each instruction in the order you want it to run.

Code Construction
Set up screen resolution and variables: The first section of your program would set the screen resolution and the variables.
Read information into arrays: If you have the information you want to put into an array using the DIM command then you can use a For/Next loop and the READ command. It is best to place the data statements for the array to read from at the end of your program.
Set up the main screen: This is the section where you would use a subroutine to set up the main screen. In a shoot-em-up type game, you would have a routine that draws the sprites and game screen and then returns to the next line of the code it came from.
Main Program Loop: Once the program is up and running the main program loop jumps to various routines using subroutines and then returns to the next line in the loop.
Program Routines: It is a good structure to place all the programming routines after the main loop. You would have separate routines that update the screen, check for joystick input, check for collision detection and so on. 
Data Statements: Finally you can list all the data statements at the end of the program which makes it easier to find and correct if need be.

Creating your code with plenty of REM Statements and short lines makes your code look cleaner and easier to follow. There may be a time you want to improve the program or use a routine for another program.

Source: HOB