Modular

From Linuxintro

Modular software is software that can be divided into blocks. A block can be everything, a file, a package or a group of lines. The term modular is sometimes used synonymously to structured. In this article, modular means the building of blocks and structured means the building of procedures and using them several times. Writing software modular also discourages the use of block-breakers such as goto.

Example

Spaghetti code:

$name=input "what is your name"
if ($name="shut up") goto end
if ($name="Thorsten") goto output
$birthdate=input "when is your birthday"
output:
print "your name is $name and your birthday is "
if ($name="Thorsten") $birthdate="07/18"
print $birthdate
ende:
print "bye"

Modular code:

$name=input "what is your name"
if ($name!="shut up")
{
  if ($name="Thorsten") $birthdate="07/18"
  else $birthdate=input "when is your birthday"
  print "your name is $name and your birthday is $birthdate"
}
print "bye"

Structured code:

sub datainput()
{
  $name=input "what is your name"
  if ($name!="shut up")
  {
    if ($name="Thorsten") $birthdate="07/18"
    else $birthdate=input "when is your birthday"
  }
}
sub answer()
{
  if ($name!="shut up") print "your name is $name and your birthday is $birthdate"
  print "bye"
}
datainput()
answer()