I have spent the last weeks trying to improve some parts of GHangtux.  One of the improvements (the more obvious and complicated one), came  with the code restructuring.
BEFORE, all the code  was divided in three different files:
- main.c: all  code for the program except for the keyboard widget.
- keyboard.c/.h:  keyboard widget code.
This structure made the code easy to read at the very  beginning, but was obviously a bad idea for the long term. Actually, you  should always divide your program in small modules although you think  is going to be a very tiny one. It might be now, but who knows what is  going to happen in the future. Also, you help to make this code reusable  for other programs or programmers. So, mental note: always use  modular code from the beginning!.
NOW, the  code is divided in ten different files:
- ghangtux.c/.h:  main program and definition of main structures.
- ghangtux_ui.c/.h:  user interface.
- ghangtux_management.c/.h: functions for  game management.
- ghangtux_utils.c/.h: auxiliary  functions.
- ghangtux_keyboard.c/.h: keyboard widget.
After all the new code structure was ready, I decided to set up GTK-Doc to document GHangtux  in a proper way (still need to finish commenting the functions), which  brought me to the eternal discussion "recursive or non recursive  Makefiles?". GTK-Doc documentation gave me the impression that I HAD  to use recursive make with no explanation and no other chance. After  some research and discussing about it with Dave, we found the way to do  it "my way", that means: non recursive. You can read  Peter Miller's excellent paper to learn why recursive make  invocations are both slow and error-prone.
Happy with the  results so far, I moved on to "convert GHangtux"  to gtkmm, so now I am busy  reading "Accelerated C++"  and "Effective C++".  Let's wait for the magic to happen soon ;).
Take care!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment