Programming Tips
Document Sample


Programming Tips
If you declare an array as a global variable then there is no reason to pass it
to a function.
Printing the array and message might best be done in the same function
(assignment 1).
Might be best to simplify the code by writing one function to move and one
function to check if blocked (assignment 1).
Make it obvious where a function begins:
/*********************************************
* function description ….
* function description ….
********************************************/
You should not have any warning messages after a compile (build). For
example, if you leave out #include <stdio.h> and use the printf function you
would get a warning message.
If you write a function that returns a value then you better be using the value
returned. Why else would you be returning the value.
Never pass a #define variable to a function. They are automatically available
to all functions within the same file.
Get help from anyone or myself if you get stuck. I’ll ‘guide’ you through the
program but you still need to do it.
One-word descriptions for a function like ‘Down’ does NOT describe the
function well.
After a program is working fine, and thoroughly tested, go back and fine-tune
it for structure, comments, etc..
Divide and conquer: build and test each function as you go before building the
next function.
It is more efficient, if a variable can have only one of 2 values, to code it as:
if variable == 1 if variable == 1
…….. instead of ……..
else
…….. if variable = 2
………
Program should have main function first followed by all other functions listed
in order called.
I do not need your sample output.
Avoid functions that simply call another function.
Keep main function simple.
Remove testing statements before turning in assignment.
Use standard library functions instead of writing your own.
printarray(); //Prints the array this is a redundant comment
No one statement functions.
Place prototypes at beginning of program and outside of main.
Avoid too may spaces and comments
Get documents about "