<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:iweb="http://www.apple.com/iweb" version="2.0">
  <channel>
    <title>Bits For Thought</title>
    <link>http://www.bitsforthought.com/main/Blog/Blog.html</link>
    <description>Welcome to Colonel Kernel’s blog about software. Whether you’re interested in programming languages and operating systems, or just want a cure for insomnia, this is the place to be.</description>
    <generator>iWeb 2.0.3</generator>
    <image>
      <url>http://www.bitsforthought.com/main/Blog/Blog_files/IMG_1960.jpg</url>
      <title>Bits For Thought</title>
      <link>http://www.bitsforthought.com/main/Blog/Blog.html</link>
    </image>
    <item>
      <title>TCP/IP in less than 200 lines of code</title>
      <link>http://www.bitsforthought.com/main/Blog/Entries/2008/4/3_TCP_IP_in_less_than_200_lines_of_code.html</link>
      <guid isPermaLink="false">2cd33237-7f61-4ed6-bb93-3f031213cd70</guid>
      <pubDate>Thu, 3 Apr 2008 21:39:52 -0700</pubDate>
      <description>&lt;a href=&quot;http://www.bitsforthought.com/main/Blog/Entries/2008/4/3_TCP_IP_in_less_than_200_lines_of_code_files/IMG_2449.jpg&quot;&gt;&lt;img src=&quot;http://www.bitsforthought.com/main/Blog/Media/IMG_2449.jpg&quot; style=&quot;float:left; padding-right:10px; padding-bottom:10px; width:364px; height:273px;&quot;/&gt;&lt;/a&gt;Lately I’ve been wishing for a much more expressive programming language. This is probably because I’ve spent the past year working on a grotty low-level data-access component in C++ that has to be portable to several *nix platforms. The variability of C++ compiler quality on different platforms is stunning -- “I can’t believe people pay for this” kind of stunning. We were forbidden from using the STL because it was completely broken on one of our target platforms. (Even worse, that target platform was dropped as a requirement after we had spent nearly six person-months developing and testing our own portable library... but that’s another story). Template support for many of our target compilers is pretty poor, so we ended up using templates in only the most rudimentary fashion. If you’ve done much heavy lifting in C++, you know how verbose it can get without a bit of meta-programming to automate things.&lt;br/&gt;&lt;br/&gt;When we were nearing functional completion, I decided to fire up &lt;a href=&quot;http://www.construx.com/Page.aspx%253Fnid%253D69&quot;&gt;Construx Surveyor&lt;/a&gt; (Steve McConnell FTW!) and see how big the code base had become. I was shocked to find that it was nearly twice the size that I thought it would be! Suddenly it was clear to me why we were all working a lot harder to make our deadlines than we had expected. (Say what you will about the fuzziness of counting lines of code, it is still &lt;a href=&quot;http://www.codinghorror.com/blog/archives/000637.html&quot;&gt;an important determinant&lt;/a&gt; of project effort.) Still, it was surprising because we had all been vigilant about avoiding and eliminating copy-paste code. Sure, there were a few areas where more abstraction could have saved some repetition, but the schedule didn’t allow for it at the time... catch-22. Besides that, what irked me was how the language itself kept forcing my hand by its lack of expressiveness -- lambdas and type inference would have helped in many situations. The lack of decent cross-platform template support also really hurt here.&lt;br/&gt;&lt;br/&gt;To give my poor brain some relief from this bleak reality, I spend a lot of time learning other languages like Objective-C, Scala, and Smalltalk to see how their approaches to problem-solving differ from the usual dreck of C++. In my exploration of Smalltalk, I ran across &lt;a href=&quot;http://deimos3.apple.com/WebObjects/Core.woa/Browse/itunes.stanford.edu.1294764018.01294764021.1294649767%253Fi%253D1621593918&quot;&gt;a really cool lecture on iTunes U&lt;/a&gt; by Ian Piumarta about a simple and extensible object model he’s working on. The lecture is worth a look, as are the &lt;a href=&quot;http://piumarta.com/papers/&quot;&gt;related papers&lt;/a&gt;. It’s part of the &lt;a href=&quot;http://vpri.org/pdf/steps_TR-2007-008.pdf&quot;&gt;STEPS project&lt;/a&gt; at &lt;a href=&quot;http://www.vpri.org/&quot;&gt;Viewpoints Research Institute,&lt;/a&gt; which aims to re-invent computer systems, especially programming. What appeals to me about it is the focus (albeit not directly stated) on &lt;a href=&quot;http://www.artima.com/intv/dry.html&quot;&gt;taking the DRY principle&lt;/a&gt; to its ultimate extreme -- every aspect of the entire computer system shall have one and only one concrete representation. The STEPS paper explains with examples how this is achieved for certain domains like graphics, text layout, IDEs, and networking. What blew me away was the tiny TCP/IP implementation, which was expressed in a Yacc-like DSL in under 200 lines of code!&lt;br/&gt;&lt;br/&gt;Obviously, the lines of infrastructure code required for implementing the DSL cannot be ignored, but it is amortized by being used for just about everything. The entire system is based on the idea of expressing a sub-system, component, or program in the most succinct and meaningful way possible, then using a series of tree-rewriting steps to produce optimized executable code. The difference from the modern OS/library/compiler trifecta is that you the developer can trivially intervene at any stage because the entire thing is dynamic, late-bound, and completely flexible.&lt;br/&gt;&lt;br/&gt;When I think about how I might use tools like these to create a DSL for low-level cross-platform database access, it almost makes me want to spend time re-writing my entire project as a Smalltalk-based C code generator.&lt;br/&gt;&lt;br/&gt;On second thought, I think I’ll stick with my honeymoon in Maui.</description>
      <enclosure url="http://www.bitsforthought.com/main/Blog/Entries/2008/4/3_TCP_IP_in_less_than_200_lines_of_code_files/IMG_2449.jpg" length="142615" type="image/jpeg"/>
    </item>
  </channel>
</rss>
