What is better practice in big projects? Have all the flow in the main or functions which call to others functions?
I show better with two examples (in a invented language to be more legible).
Example 1 (all the flow in main):
function menu1
{
print "Select an option."
print "1. Cake."
print "2. Water."
var option
read(option)
if (number == 1)
{
return 1; // return cake
}
}
cake()
{
print "Select an option."
...
}
main()
{
integer optionSelected = menu1()
if (optionSelect == 1)
{
integer optionSelected2 = cake()
...
}
}
Example 2 (the function has the flow):
function menu1
{
print "Select an option."
print "1. Cake."
print "2. Water."
var option
read(option)
if (number == 1)
{
cake();
}
}
cake()
{
print "Select an option."
...
menu15()
}
main()
{
menu1()
}
Aucun commentaire:
Enregistrer un commentaire