Coding styles of our kids

Sep 10, 2019 01:00

I have been teaching a bit of C-coding to our kids (K, 10 years and J, 9 years). They have made a couple of small exercise programs and now I looked their coding style to see if it reveals anything about how things are going.

J's code is very tight packed, everything clutched together, with minimal number of empty lines and other whitespaces in it. Reading the code you can sense how he has been a bit uncomfortable writing it - he feels this still to be a bit too hard for him. I need to make things easier for him.

#include
#include
int main(int argc, char *argv[])
{
  if (argc !=2) {
    printf("Anna ohjelmalle nimesi komentorivillä.\n");
    return EXIT_FAILURE;
  }
  printf(" hauska tavata %s .\n", argv[1]);
  return EXIT_SUCCESS;
}

When K has faintest clue about what some part of the code does, she tends to experiment with it. Her coding ends aesthetically a bit weird, and maybe a bit confused where she has not been paying attention. I've been two minds about if I should force her to follow more pedantic style as she is only learning things and the style I prefer is there to make things clearer and easier to learn. I've ended letting her to enjoy her experiments. She'll learn the best practices in due time and now it's important not to kill her joy. It's also interesting how she lets the history of the code show through. In below example block of handling ages above 150 is the latest addition to the program, and it shows.

#include
#include

int main(int argc,char *argv[])
{

int ika;
  int seuraava;

if (argc != 2) {

printf("anna ohjelmalle ikäsi komentorivillä.\n");
    return EXIT_FAILURE;
  }

ika = atoi(argv[1]);

if  (ika < 0) {

return EXIT_FAILURE;
    }
    if (ika > 150) {
      printf("et voi olla niin vanha.\n");
      return EXIT_FAILURE; }

seuraava = ika + 1;

printf("nyt olet %d.\n", ika);

printf("seuraavaksi täytät %d.\n", seuraava);

return EXIT_SUCCESS;

}
Previous post
Up