The cost of code…

Chris made a pretty map widget thing and threw down the gauntlet

I’m expecting a libjana-gtk/gypsy mash-up from a certain Mr. Burton (no pressure)

Given that Gypsy is my baby, I felt obligated to beat Ross to it :) And so I present

And a massive 87 line program to how how fun and easy it can be to find out your location and then draw it on a map.

#include <gtk/gtk.h>

#include <libjana-gtk/jana-gtk-world-map.h>

#include <gypsy/gypsy-control.h>
#include <gypsy/gypsy-device.h>
#include <gypsy/gypsy-position.h>

GypsyControl *control;
GypsyDevice *device;

static void
destroyed_cb (GtkWidget *window, gpointer data)
{
gypsy_device_stop (device);
g_object_unref (control);

    gtk_main_quit ();
}

static void
position_changed (GypsyPosition *position, GypsyPositionFields fields_set, int timestamp, double latitude, double longitude, double altitude, JanaGtkWorldMap *map)
{
if ((fields_set & GYPSY_POSITION_FIELDS_LATITUDE) &&
(fields_set & GYPSY_POSITION_FIELDS_LONGITUDE)) {
jana_gtk_world_map_add_mark (map, latitude, longitude);
}
}

int
main (int argc, char **argv)
{
GtkWidget *window, *map;
GypsyPosition *position;
GError *error = NULL;
char *path;

    gtk_init (&argc, &argv);

    if (argc < 2) {
g_print ("Usage: %s <device\n", argv[0]);
return 1;
}

    control = gypsy_control_get_default ();
path = gypsy_control_create (control, argv[1], &error);
if (path == NULL) {
g_warning ("Error creating client for %s: %s", argv[1], error->message);
g_error_free (error);
return 1;
}

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy", G_CALLBACK (destroyed_cb), NULL);

    map = jana_gtk_world_map_new ();

    gtk_container_add (GTK_CONTAINER (window), map);
gtk_widget_show_all (window);

    device = gypsy_device_new (path);
position = gypsy_position_new (path);
g_signal_connect (position, "position-changed", G_CALLBACK (position_changed), map);

    gypsy_device_start (device, &error);
if (error != NULL) {
g_warning ("Error starting %s: %s", argv[1], error->message);
g_error_free (error);
return 1;
}

    gtk_main ();
return 0;
}

As you can see, its really not a lot of code. I also added 10 lines to libjana-gtk to draw the marker. Total time taken, about 40minutes, including testing, debugging and discussing a few bugs with Chris. So lets see what sloccount says about it:

Total Physical Source Lines of Code (SLOC) = 80
Development Effort Estimate, Person-Years (Person-Months) = 0.01 (0.17)
Schedule Estimate, Years (Months) = 0.11 (1.27)
Estimated Average Number of Developers (Effort/Schedule) = 0.13
Total Estimated Cost to Develop = $ 1,905

Hmm, we should have scheduled 1.27 months for it and I should have earned 2grand? (not including the code I added to libjana-gtk which would have increased the line count to 90)
Oh, whoops, almost forgot this:

Please credit this data as “generated by pulling numbers out of David A. Wheeler’s ass”

sloccount – for when you need to over estimate EVERYTHING.

4 thoughts on “The cost of code…”

Comments are closed.

Leave a Reply

Your email address will not be published. Required fields are marked *