excellence.html 12 KB

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