Programming consists of instruction commands, instruction is divided into 2 ie :
Indeed both are instructions, look alike but not the same, Procedure is a code of directional instruction, ordered without having to know how it goes. See the picture below:
From the picture above looks a photo of a teacher telling her female students to open the book page 23. The disciple obediently carry out the command.
Now let's compare with Function, note the picture below:
From the picture above looks a picture of a teacher asking something to his male students, then his students respond to questions from the teacher earlier.
In conclusion, although both provide instructions, but Function has advantages that there is a feature called "Return value".
What is Procedure and Function when written into programming code? See the example below:
// Procedure
void Kerja(){
Print("Lahir tahun 1985, umur anda =" + (2017-1985) );
Print("Lahir tahun 1990, umur anda =" + (2017-1990) );
}
// Function
void Kerja(){
Print("Lahir tahun 1985, umur anda =" + HitungUmur(1985) );
Print("Lahir tahun 1990, umur anda =" + HitungUmur(1990) );
}
int HitungUmur(int tahunLahir){
return 2017 - tahunLahir;
}
From both of the above programming examples we can see that Functions are reusable, in addition to energy savings, reusable codes also shorten the time when source code need to be revised (the effect will be global).
Well, for a while the first material introduction Procedure and Function, see you again on the next articles. Regards!