excellence.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head lang="en">
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="Author" content="Eric S. Raymond">
  6. <meta name="Description" content="Essay for the Alliance for Code Excellence.">
  7. <meta name="Keywords" content="GPS, gpsd, code, excellence">
  8. <meta name="Revised" content="9 April 2015">
  9. <meta name="robots" content="index,follow">
  10. <link rel="stylesheet" href="main.css" type="text/css">
  11. <title>GPSD and Code Excellence</title>
  12. </head>
  13. <body>
  14. <div id="Header">
  15. GPSD and Code Excellence
  16. </div>
  17. <div id="Menu">
  18. <img src="gpsd-logo-small.png" alt="Small gpsd Logo" height="126"
  19. width="105"><br>
  20. <a href="index.html">Home</a><br>
  21. <a href="index.html#news">News</a><br>
  22. <a href="index.html#downloads">Downloads</a><br>
  23. <a href="index.html#mailing-lists">Mailing lists</a><br>
  24. <a href="index.html#documentation">Documentation</a><br>
  25. <a href="faq.html">FAQ</a><br>
  26. <a href="xgps-sample.html">Screenshots</a><br>
  27. <a href="index.html#recipes">Recipes</a><br>
  28. <a href="index.html#others">Other GPSDs</a><br>
  29. <a href="hardware.html">Hardware</a><br>
  30. <a href="for-vendors.html">For GPS Vendors</a><br>
  31. <a href="wishlist.html">Wish List</a><br>
  32. <a href="hall-of-shame.html">Hall of Shame</a><br>
  33. <a href="troubleshooting.html">Troubleshooting Guide</a><br>
  34. <a href="hacking.html">Hacker's Guide</a><br>
  35. <a href="protocol-transition.html">Application Compatibility</a>
  36. <a href="references.html">References</a><br>
  37. <a href="history.html">History</a><br>
  38. <a href="future.html">Future</a><br>
  39. <div>&nbsp;</div>
  40. <a href='http://www.catb.org/hacker-emblem/'><img
  41. src='glider.png' alt='hacker emblem' height="55" width="55"></a><br>
  42. <script src="https://www.openhub.net/p/3944/widgets/project_thin_badge.js"></script>
  43. <hr>
  44. <script><!--
  45. google_ad_client = "pub-1458586455084261";
  46. google_ad_width = 160;
  47. google_ad_height = 600;
  48. google_ad_format = "160x600_as";
  49. google_ad_type = "text";
  50. google_ad_channel = "";
  51. //--></script>
  52. <script src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
  53. </script>
  54. <hr>
  55. <a href="https://validator.w3.org/check/referer"><img
  56. src="https://www.w3.org/Icons/valid-html401"
  57. alt="Valid HTML 4.01!" height="31" width="88"></a>
  58. </div>
  59. <div id="Content">
  60. <p>There's a wonderfully tongue-in-cheek project called the The Alliance
  61. for Code Excellence ("Building a better tomorrow &mdash; one line of
  62. code at a time.") that sells Bad Code Offset certificates. They fund
  63. open source projects to produce good code that will, in theory, offset
  64. all the bad code out there and mitigate the environmental harm it does.
  65. They've asked software authors to write essays on how their projects
  66. drive out bad code, offering $500 dollar prizes.</p>
  67. <p>I sat down to write an essay about GPSD in the same vein of high
  68. drollery as the Alliance's site, then realized that GPSD actually has
  69. a serious case to make. We really do drive out bad code, in both
  70. direct and indirect ways, and we supply examples of good practice for
  71. emulation.</p>
  72. <p>GPSD is a service daemon and device multiplexer that is the
  73. open-source world's basic piece of infrastructure for communicating
  74. with GPS receivers, and it's everywhere Linux is - running on PCs, on
  75. embedded systems, and on both OpenMoko and the entire line of Maemo
  76. cellphones. We're directly relied on by dozens of applications,
  77. including pyGPS, <a
  78. href="https://www.kismetwireless.net/">Kismet</a>, <a
  79. href="https://sourceforge.net/projects/gpsdrive/">GPSdrive</a>, <a
  80. href="http://qpegps.sourceforge.net/">gpeGPS</a>, <a
  81. href="http://www.gnustep.it/enrico/position/">position</a>,
  82. roadmap, <a
  83. href="http://roadnav.sourceforge.net/">roadnav</a>, <a
  84. href="https://www.navit-project.org/">navit</a>, <a
  85. href="https://sourceforge.net/p/viking/wikiallura/Main_Page">viking</a>, and <a
  86. href="http://gaia.serezhkin.com/">gaia</a>. If you're doing anything
  87. with GPSes on an open-source operating system, GPSD is your
  88. indispensable tool.</p>
  89. <p>GPSD's quality is up to the standard required when you're that
  90. ubiquitous. In March 2007 a <a
  91. href='https://www.synopsys.com/software-integrity/security-testing/static-analysis-sast.html'
  92. >Coverity</a>
  93. scan turned up only two errors in over 22,000 LLOC. In more detail: it
  94. flagged only 4 potential problems, and two of those were false
  95. positives. This is <a href='http://lwn.net/Articles/115530/'>three
  96. orders of magnitude cleaner</a> than typical commercial software, and
  97. about half the defect density of the Linux kernel itself at the
  98. time.</p>
  99. <p>We get, on average, about one defect report every 90 days, and
  100. there are just five on our tracker as I write. Given what we know
  101. about the size of our user base, our low rate of incoming bug reports
  102. tells us we've maintained a similar level of code quality since the
  103. Coverity audit. This hasn't happened by accident. Good practice
  104. matters, and I'll describe how we systematize ours in a bit.</p>
  105. <p>First, though, I want to explain how we drive out bad code. The
  106. reporting protocols used by GPS sensors are a <a
  107. href="http://esr.ibiblio.org/?p=801">hideous mess</a> &mdash; the kind
  108. of mess that tends to nucleate layers of bad code around it as
  109. programmers with insufficient domain knowledge try to compensate for
  110. the deficiencies at application level and wind up snarling themselves
  111. up in ever-nastier hairballs. Part of what GPSD does is firewall all
  112. this stuff away; we know everything about the mess so you don't have
  113. to, and we present clean data on a well-known port in a
  114. well-documented wire format. We then provide client-side service
  115. libraries that will unpack GPS reports into native C, C++, Python, or
  116. Perl structures so you don't even have to know about our wire
  117. format.</p>
  118. <p>If our client applications had to deal with the back-end mess of
  119. poorly-specified NMEA 0183 and seventeen different vendor-specific
  120. binary protocols, I for dead certain <em>guarantee</em> that the total
  121. community bug load from GPS-related problems would go up by an order
  122. of magnitude. And I'd bet more than any of the $500 prizes the Alliance is
  123. offering on the bug count going up by <em>two</em> orders of
  124. magnitude.</p>
  125. <p>We also try to drive out bad code indirectly in the same way we
  126. keep our defect level low &mdash; by providing an example of good
  127. practice that extends all the way up from our development habits to
  128. the zero-configuration design of the gpsd daemon.</p>
  129. <p>The most important thing we do to ensure code quality is maintain a
  130. rigorous test suite. Our "make testregress" runs just shy of sixty
  131. regression and unit tests. Forty-six of those exercise the daemon's
  132. logic for recognizing and processing device reports; the remaining ten
  133. to a dozen exercise the rest of the code, all the way out to the
  134. application service libraries.</p>
  135. <p>We actively collect device logs and metadata from users through <a
  136. href="http://www.thyrsus.com/cgi-bin/gps_report.cgi">this form</a>,
  137. which we use to update a device-capability database and our collection
  138. of test logs. Almost every time a user fills out one of these, the
  139. number of devices for which we can guarantee good performance in the
  140. future goes up. Currently it's 87 devices from 39 vendors.</p>
  141. <!-- splint was dropped in March 2015 --> <p>We also used to routinely
  142. audit our code with <a href="http://www.splint.org/">splint</a>. Not
  143. many people do this, because splint is very finicky and a pain in the
  144. ass to use and requires you to litter your code with cryptic
  145. annotations. We stopped doing this because splint gave us randomly
  146. variable warnings across different Linux distributions, and has been
  147. obsolesced by newer static analyzers. But I believe accepting that
  148. discipline was the main reason the Coverity scan went so well. After
  149. hacking through the underbrush of false positives, I generally find
  150. that splint heads off about two potentially serious bugs per release
  151. cycle, averaging out to about one every 17 weeks.</p>
  152. <p>We have a policy of not using C where a scripting language will do.
  153. Python is what we mostly use, but not the actual point here (though I
  154. do like it a lot and use it in preference to other scripting languages).
  155. The point is to get away from the fertile source of bugs that is
  156. memory-management in a fixed-extent language. The core daemon is
  157. written in C because it has to be; a significant part of our customer
  158. base is embedded and SBC developers who need to run lean and mean.
  159. But our test tools and some of our test clients are Python, and we're
  160. gradually working to retire as much of the C as possible from outside
  161. the daemon in favor of scripting languages.</p>
  162. <p>We have copious documentation, not just of the <a
  163. href="libgps.html">interfaces to the code</a> and the <a
  164. href="gpsd.html">wire protocol</a> but also to the internals and of
  165. our project practices. We have a <a href="hacking.html">Hacker's
  166. Guide</a> to the project philosophy, design, and code internals. We
  167. have <a href="writing-a-driver.html">Notes on Writing a GPSD
  168. Driver</a> by someone who did it. Because everything is documented,
  169. the project doesn't forget things even if the individual members
  170. do.</p>
  171. <p>No account of good practice can leave out the human element. In
  172. the best open-source tradition, GPSD combines the benefits of a small,
  173. highly capable core group (three developers: Chris Kuethe, Gary
  174. Miller, and myself) with about a half dozen other semi-regular
  175. contributors and a halo of casual contributors numbering in the
  176. hundreds. GPSD teaches by example about the kinds of specialization
  177. that produce good code. Here is what the core group looks like...</p>
  178. <p>Chris Kuethe is our GPS domain expert. He knows the devices, the
  179. mathematics of geodesy, and where all the bodies are buried in this
  180. application area to a nearly insane level of detail. I am the systems
  181. architect &mdash; I neither match Chris's depth of domain knowledge
  182. nor want to, but it's been my role to give the GPSD codebase a
  183. strong modular architecture, design and implement our test suites and
  184. tools, design and implement our wire protocols, and push
  185. autoconfiguration as far as it could go. Gary Miller is more of a
  186. generalist who owns some particularly tricky areas of the core code
  187. and device drivers, and is extremely good at detecting bad smells in
  188. other code; he backstops Chris and myself admirably.</p>
  189. <p>If this sounds like a description of a classic "surgical team"
  190. organization straight out of Fred Brooks, that's because it is. Open
  191. source changes a lot of things, and the outer circle of contributors
  192. brings huge value to the GPSD project &mdash; but some things about
  193. software development never change, and the power of teams that include
  194. a domain expert, a master architect, and a bogon detector is one of
  195. them. GPSD reinforces a lesson that is old but never stale; if you
  196. want the kind of good code that improves the whole software ecology
  197. around it, that kind of human constellation is a great place to
  198. start.</p>
  199. <p>Finally, we drive out a lot of potentially bad code by eliminating
  200. configuration options. The <cite>gpsd</cite> daemon is designed to
  201. autobaud and recognize GPS or AIS reporting packets on any serial or
  202. USB device that it's handed, no questions asked. And normally, at
  203. least on Linux systems, those devices are handed to it by udev when a
  204. hotplug event fires. Though arranging this took a lot of work, there
  205. are many fewer combinations of code paths in <cite>gpsd</cite> to test
  206. (and to accumulate bugs) than there would be if the daemon had the
  207. usual semi-infinite array of knobs, switches, and config files.
  208. Because client applications don't have to give users any access to
  209. those nonexistent knobs and switches, thousands of lines of
  210. application code have never had to be written either; the simplifying
  211. effects of autoconfiguration ripple through dozens of
  212. application-development groups and all the way up the software stack
  213. to the end-user.</p>
  214. <p>The RFP for these essays asked software authors to explain what
  215. they'd do with a $500 prize. That's easy; we'd use it to <a
  216. href="wishlist.html">buy test hardware</a>. Because GPSes are wacky,
  217. idiosyncratic devices with poorly documented interfaces, testing on
  218. real hardware is vital to fully learn their quirks.</p>
  219. <hr>
  220. <script src="datestamp.js"></script>
  221. </div>
  222. </body>
  223. </html>