Computer languages, like natural languages, have both nouns and verbs. You have already learned about variables, which are the nouns of a computer language. What are the verbs?
#define HASH_MULTIPLIER 11
#define HASH_MODULUS 1000
/* A very trivial function. */
int add(int first, int second)
{
return first + second;
}
/* Basically slices and dices a number for no good reason. */
int hash(int seed)
{
int temp;
temp = seed * HASH_MULTIPLIER;
temp = temp % HASH_MODULUS;
return temp;
}
/* This function calls another function. */
void print_hash(int seed)
{
int hashed = hash(seed);
printf("%d", hashed);
}
/* main, Lord Of All Functions. */
int main(void)
{
int a, b, seed; /* Bad names, but for our purposes it's ok */
/* Test the most trivial function, addition. */
a = 282;
b = 6343;
printf("a + b returns: %d\n", a + b);
printf("add(a,b) returns: %d\n", add(a,b));
/* See what hash does. */
seed = hash(b);
printf("hash() returns: %d\n", seed);
/* Try the last function. */
print_hash(seed);
return 0;
}
Two styles of student development:
Guess which one works better? Unfortunately, in practice, most students use a hybrid, compiling incrementally but testing only at the end, adding greatly to their suffering.