How to organize your programming code !

Hohow 

Your program code should be written as a step-by-step instruction using commands that understands your choice of programming language. This means that you are reading your programming manual to know which program you want to use for your program. In the example "Hello World" you will first need a command that prints "Hello World" on the screen, and after that you will need a second command to print several times without writing several print statements.


See this example. To simplify things, I'm using old school roots with line numbers - perhaps because I'm a retro-freak.

10 Print "Hello World"
20 goto 10

The best structure to write any program code is to make it clear and easy to follow. Some programmers put many commands on one line that can make it harder to follow your code if you are trying to get the bug out of iron. By spreading your code on many codes, the program actually works better and becomes more readable.

Another recommended exercise is to separate each part of its program code using the REME statement. REM (small for comment) allows you to first comment on each section of the code so that you can be reminded about what each part does. This is particularly useful if you want to edit your code later.

Set 10 ream variables
20 A = 1: B = 2
30 rim *******
40 RIM Print Variables on Screen
50 Rim *******
60 print a, b

After the REM command anything is ignored by the computer and you can use many REME statements because you want to make a big difference in your code for easy reading. Other programming languages ​​allow you to use blank lines or indent the first line of routines.

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

Code generation


Set up screen resolutions and variables: The first part of your program will set the screen resolution and the variable.

Read the information in the array: If you have the information that you want to keep in the array using the DIM command, then you can use Four / Next Loop and Read command. It's best to keep the data details of the array in order to read at the end of your program.

Set the main screen: This is the section where you will use a subarroutine (GOSUB command) to set up the main screen. In the shoot-a-you type game you will have a routine that draws sprites and game screens, and then comes back to the next line of the incoming code.

Main Event Loop: Once the program is activated and the main program runs the loop, it uses the subroutine to jump into different routines and then returns to the next line in the loop.

Program routines: It is a good structure to keep all programming routines after the main loop. You will have different routines that update the screen, check the joystick input, check to see the collision and so on. After each check you return to the main loop.

Data Statements: Finally you can list all the data statements at the end of the program, which makes it easy to find and correct when needed.

Conclusion

Making your code with lots of REME statements and short lines makes it easy to clean and follow your code. There may be times when you want to improve the program or want to use regularly for another program.

Post a Comment

0 Comments