The GNOME OPW for Summer 2012 is approaching to the end. By working with the code of GUPnP through the internship, I have learned a lot about C programming with GLib/GObject. I think it is a great time to share some from what I learned to everyone, especially the beginners.
Here I collect five small suggestions focusing on coding:
-
Avoid the trailing white space in your code and patch. Set your editor to be aware of the unnecessary white spaces at the end of line. Git doesn’t like them nor your mentor. If you use Vim, you can look at this page.
-
Use
--enable-shared=no
during theconfigure
phase to disable the build of shared library. This makes the test programs undertests
directory statically linked to the target library. Otherwise the test programs will be Bash wrapper scripts. Doing so make it easier when you usegdb
to load the test programs. -
Use
CFLAGS=-g
in theconfigure
phase to generate the debugging info. Even though you may findconfigure --help
shows you an option called--enable-debug
, it basically will convert to-g -O3
forgcc
. This-O3
will optimize your code and make it hard to track the execution ingdb
. -
Combine your local commits into a single patch. After finishing a specific feature or fixing a particular bug, you may have many local commits in your Git commit tree. You may also have merges from the upstream repository. I find this link is extremely helpful to form a single patch from the mess.
-
Use DevHelp. Even though you might prefer to the online documentation, you should give DevHelp a try. It is more convenient and faster. It can only show the documentation you are interested.
All right. That is it. Hopefully you will find them helpful.