Good programmers don't write their programs as a long command sequence, but they split them to smaller parts - methods.
A method is a named part of the program. Its definition begins with a header containing a name of the method. The method body follows the header and contains a prescript how the method should perform the assigned task.
  You can create a new method by pressing the Methods button. When you press this button a dialog with the same name appears. Here you press the button with a pen and a sheet of paper in the left bottom corner. After then, B4 inserts a new header of the method named MethodN, where N is a sequence number of the method being created.
You can change this name anytime by simply clicking on the header. Then you can specify a name, which better describes a purpose of the method.
A method definition if finished either by a header of the next method, or by the end of file.
If you want to execute an action provided by the method, you must call it. You can achieve it by opening the Methods window. Here you must click on the header of the method which you want to call. The window is closed and you must put the call method command to the desired position. The program will execute the command sequence defined in the method body, whenever it reaches the command.
You can see a real method usage in the picture. The first line of the program calls a method, which lets Baltie to perform a few movements. It lets Baltie go up after then, and eventually it forces him to make the same movements again. The method declaration occupies the next lines.
This notation is equal to the following program:
Example (For mode 3D)
Set Baltie visible. Baltie takes a step, turns left, takes a step, hikes up, turns right, takes a step, flies down, takes step, turns left, takes step, hikes up and all of this again without the last command.
The methods are used to increase a lucidity and a possibility of the program maintenance. A good programmer never writes the same code twice. They define a method instead. The method body contains the necessary command sequence, which is called from various parts of the program. If you need to change the code later, you don't have to go through the whole program looking for all occurrences of the code, but it's enough to change the method body only.
Consider the experience of the top programmers who know that the methods should be as short as possible. Each method should perform just a one simple thing. If your methods are longer, you are probably trying to do more then one thing inside. Be sure that you will have to pay for it during future modifications.


Did you find this information useful?
Documentation of SGP Baltie 4 C#
Send us comments on this topic by this form ©1978-2010 SGP Systems

Parent page | Previous page | Next page