Subentry of
Code Abuse
Sat9Dec2006
Goal.
Build and compile three versions of the same application, one implemented in C and the other in C++. Even though it cannot be compiled, also implement this same application in PHP.
Description.
Build and compile a GTK2 application which consists of a main window, a text label displaying a message and a button to close the application. The application should also handle the destruction of the application from the users "close button" of the window manager. These applications should also have a simple way to check for a command line parameter that if valid adds a hook to terminate the program the moment it becomes idle for purpose of noting load times.
Result.
Both the C and C++ ended up being about the same line count, formatted to be pretty. However both applications could have had some lines concatenated for simplicity. In fact the C version is overly complex to simulate a class based structure. The PHP one hit 40 lines and does not get too much simpler than that.
I spent about 6 minutes on the C version and about an hour on the C++ version as I wasted time trying to research a way to simulate connect_simple() instead of having to have a unique function for the delete event and another for the click event. The PHP one took me no time at all.
Each application if receiving the command line "quit" will terminate itself as soon as it has become idle, as far as the application is concerned it is ready for user input.
Conclusion.
C++ makes for neater organization if provisions for neat structure are made however the implementation of Glib signal connections, in my new experiences with gtkmm, complicate simple matters of driving the event based application model that are non-issues in both C and PHP. Out of all three PHP has the best looking, easiest to read, clear cutting syntax for this type of operation however the trade off is definitely speed.
Included here is the Makefile, the C application, the C++ application, the PHP application, and a quick application I wrote to time the compile times of this.
cgtk2.c: http://p.opsat.net/v/62oupg
cppgtk2.cpp: http://p.opsat.net/v/angroe
phpgtk2.php: http://p.opsat.net/v/8wzqce
Makefile: http://p.opsat.net/v/e3yw2q
timer.c: http://p.opsat.net/v/89qb7r
Timing Compile
//. bob@elenothar [testing]$ make
timing 'make c'
./timer make -s c
0.461579 sec
timing 'make cpp'
./timer make -s cpp
3.331595 sec
Timing Load Times
//. bob@elenothar [testing]$ ./timer cgtk2 quit
0.155316 sec
//. bob@elenothar [testing]$ ./timer cppgtk2 quit
0.215634 sec
//. bob@elenothar [testing]$ ./timer phpgtk2.php quit
0.253848 sec
File Size (in Bytes)
//. bob@elenothar [testing]$ stat -c %s cgtk2
9508
//. bob@elenothar [testing]$ stat -c %s cppgtk2
30306
//. bob@elenothar [testing]$ stat -c %s phpgtk2.php
942