NetNewsWire/Parser/Tests/ParserTests/Resources/russcox.atom

182 lines
434 KiB
Plaintext
Raw Normal View History

<feed xmlns="http://www.w3.org/2005/Atom">
<title>research!rsc</title>
<id>tag:research.swtch.com,2012:research.swtch.com</id>
<link rel="self" href="http://research.swtch.com/feed.atom"></link>
<updated>2019-03-01T11:01:00-05:00</updated>
<author>
<name>Russ Cox</name>
<uri>https://swtch.com/~rsc</uri>
<email>rsc@swtch.com</email>
</author>
<entry>
<title>Transparent Logs for Skeptical Clients</title>
<id>tag:research.swtch.com,2012:research.swtch.com/tlog</id>
<link rel="alternate" href="http://research.swtch.com/tlog"></link>
<published>2019-03-01T11:00:00-05:00</published>
<updated>2019-03-01T11:02:00-05:00</updated>
<summary type="text">How an untrusted server can publish a verifiably append-only log.</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;Suppose we want to maintain and publish a public, append-only log of data.&#xA;Suppose also that clients are skeptical about our correct implementation&#xA;and operation of the log:&#xA;it might be to our advantage to leave things out of the log,&#xA;or to enter something in the log today and then remove it tomorrow.&#xA;How can we convince the client we are behaving?&#xA;&#xA;&lt;p&gt;&#xA;This post is about an elegant data structure we can use to publish&#xA;a log of &lt;i&gt;N&lt;/i&gt; records with these three properties:&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&#xA;For any specific record &lt;i&gt;R&lt;/i&gt; in a log of length &lt;i&gt;N&lt;/i&gt;,&#xA;we can construct a proof of length&#xA;&lt;i&gt;O&lt;/i&gt;(lg &lt;i&gt;N&lt;/i&gt;) allowing the client to verify that &lt;i&gt;R&lt;/i&gt; is in the log.&#xA;&lt;li&gt;&#xA;For any earlier log observed and remembered by the client,&#xA;we can construct a proof of length&#xA;&lt;i&gt;O&lt;/i&gt;(lg &lt;i&gt;N&lt;/i&gt;) allowing the client to verify that the earlier log&#xA;is a prefix of the current log.&#xA;&lt;li&gt;&#xA;An auditor can efficiently iterate over the records in the log.&lt;/ol&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;(In this post, “lg &lt;i&gt;N&lt;/i&gt;” denotes the base-2 logarithm of &lt;i&gt;N&lt;/i&gt;,&#xA;reserving the word “log” to mean only “a sequence of records.”)&#xA;&#xA;&lt;p&gt;&#xA;The&#xA;&lt;a href=&#34;https://www.certificate-transparency.org/&#34;&gt;Certificate Transparency&lt;/a&gt;&#xA;project publishes TLS certificates in this kind of log.&#xA;Google Chrome uses property (1) to verify that&#xA;an &lt;a href=&#34;https://en.wikipedia.org/wiki/Extended_Validation_Certificate&#34;&gt;enhanced validation certificate&lt;/a&gt;&#xA;is recorded in a known log before accepting the certificate.&#xA;Property (2) ensures that an accepted certificate cannot later disappear from the log undetected.&#xA;Property (3) allows an auditor to scan the entire certificate log&#xA;at any later time to detect misissued or stolen certificates.&#xA;All this happens without blindly trusting that&#xA;the log itself is operating correctly.&#xA;Instead, the clients of the log—Chrome and any auditors—verify&#xA;correct operation of the log as part of accessing it.&#xA;&#xA;&lt;p&gt;&#xA;This post explains the design and implementation&#xA;of this verifiably tamper-evident log,&#xA;also called a &lt;i&gt;transparent log&lt;/i&gt;.&#xA;To start, we need some cryptographic building blocks.&#xA;&lt;a class=anchor href=&#34;#cryptographic_hashes_authentication_and_commitments&#34;&gt;&lt;h2 id=&#34;cryptographic_hashes_authentication_and_commitments&#34;&gt;Cryptographic Hashes, Authentication, and Commitments&lt;/h2&gt;&lt;/a&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;A &lt;i&gt;cryptographic hash function&lt;/i&gt; is a deterministic&#xA;function H that maps an arbitrary-size message &lt;i&gt;M&lt;/i&gt;&#xA;to a small fixed-size output H(&lt;i&gt;M&lt;/i&gt;),&#xA;with the property that it is infeasible in practice to produce&#xA;any pair of distinct messages &lt;i&gt;M&lt;sub&gt;1&lt;/sub&gt;&lt;/i&gt; ≠ &lt;i&gt;M&lt;sub&gt;2&lt;/sub&gt;&lt;/i&gt; with&#xA;identical hashes H(&lt;i&gt;M&lt;sub&gt;1&lt;/sub&gt;&lt;/i&gt;) = H(&lt;i&gt;M&lt;sub&gt;2&lt;/sub&gt;&lt;/i&gt;).&#xA;Of course, what is feasible in practice changes.&#xA;In 1995, SHA-1 was a reasonable cryptographic hash function.&#xA;In 2017, SHA-1 became a &lt;i&gt;broken&lt;/i&gt; cryptographic hash function,&#xA;when researchers identified and demonstrated&#xA;a &lt;a href=&#34;https://shattered.io/&#34;&gt;practical way to generate colliding messages&lt;/a&gt;.&#xA;Today, SHA-256 is believed to be a reasonable cryptographic hash function.&#xA;Eventually it too will be broken.&#xA;&#xA;&lt;p&gt;&#xA;A (non-broken) cryptographic hash function provides&#xA;a way to bootstrap a small amount of trusted data into&#xA;a much larger amount of data.&#xA;Suppose I want to share a very large file with you,&#xA;but I am concerned that the data may not arrive intact,&#xA
</entry>
<entry>
<title>An Encoded Tree Traversal</title>
<id>tag:research.swtch.com,2012:research.swtch.com/treenum</id>
<link rel="alternate" href="http://research.swtch.com/treenum"></link>
<published>2019-02-25T12:00:00-05:00</published>
<updated>2019-02-25T12:02:00-05:00</updated>
<summary type="text">An unexpected tree traversal ordering.</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;Every basic data structures course identifies three ways to traverse a binary tree.&#xA;Its not entirely clear how to generalize them to &lt;i&gt;k&lt;/i&gt;-ary trees,&#xA;and I recently noticed an unexpected ordering that Id like to know more about.&#xA;If you know of references to this ordering, please leave a comment&#xA;or email me (&lt;i&gt;rsc@swtch.com&lt;/i&gt;).&#xA;&lt;a class=anchor href=&#34;#binary_tree_orderings&#34;&gt;&lt;h2 id=&#34;binary_tree_orderings&#34;&gt;Binary Tree Orderings&lt;/h2&gt;&lt;/a&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;First a refresher about binary-tree orderings&#xA;to set up an analogy to &lt;i&gt;k&lt;/i&gt;-ary trees.&#xA;&#xA;&lt;p&gt;&#xA;Preorder visits a node before its left and right subtrees:&#xA;&#xA;&lt;p&gt;&#xA;&lt;img name=&#34;treenum-b2-pre&#34; class=&#34;center pad&#34; width=625 height=138 src=&#34;treenum-b2-pre.png&#34; srcset=&#34;treenum-b2-pre.png 1x, treenum-b2-pre@1.5x.png 1.5x, treenum-b2-pre@2x.png 2x, treenum-b2-pre@3x.png 3x, treenum-b2-pre@4x.png 4x&#34;&gt;&#xA;&#xA;&lt;p&gt;&#xA;Inorder visits a node between its left and right subtrees:&#xA;&#xA;&lt;p&gt;&#xA;&lt;img name=&#34;treenum-b2-in&#34; class=&#34;center pad&#34; width=625 height=138 src=&#34;treenum-b2-in.png&#34; srcset=&#34;treenum-b2-in.png 1x, treenum-b2-in@1.5x.png 1.5x, treenum-b2-in@2x.png 2x, treenum-b2-in@3x.png 3x, treenum-b2-in@4x.png 4x&#34;&gt;&#xA;&#xA;&lt;p&gt;&#xA;Postorder visits a node after its left and right subtrees:&#xA;&#xA;&lt;p&gt;&#xA;&lt;img name=&#34;treenum-b2-post&#34; class=&#34;center pad&#34; width=625 height=138 src=&#34;treenum-b2-post.png&#34; srcset=&#34;treenum-b2-post.png 1x, treenum-b2-post@1.5x.png 1.5x, treenum-b2-post@2x.png 2x, treenum-b2-post@3x.png 3x, treenum-b2-post@4x.png 4x&#34;&gt;&#xA;&#xA;&lt;p&gt;&#xA;Each picture shows the same 16-leaf, 31-node binary tree, with the nodes&#xA;numbered and also placed horizontally using the order&#xA;visited in the given traversal.&#xA;&#xA;&lt;p&gt;&#xA;It was observed long ago that one way to represent a tree&#xA;in linear storage is to record the nodes in a fixed order&#xA;(such as one of these), along with a separate array giving&#xA;the number of children of each node.&#xA;In the pictures, the trees are complete, balanced trees, so the&#xA;number of children of each node can be derived from&#xA;the number of total leaves.&#xA;(For more, see Knuth Volume 1 §2.3.1;&#xA;for references, see §2.3.1.6, and §2.6.)&#xA;&#xA;&lt;p&gt;&#xA;It is convenient to refer to nodes in a tree by&#xA;a two-dimensional coordinate (&lt;i&gt;l&lt;/i&gt;, &lt;i&gt;n&lt;/i&gt;), consisting of the level of&#xA;the node (with 0 being the leaves) and its sequence number at that level.&#xA;For example, the root of the 16-node tree has coordinate (4, 0),&#xA;while the leaves are (0, 0) through (0, 15).&#xA;&#xA;&lt;p&gt;&#xA;When storing a tree using a linearized ordering such as these,&#xA;it is often necessary to be able to convert a two-dimensional&#xA;coordinate to its index in the linear ordering.&#xA;For example,&#xA;the right child of the root—node (3, 1)—has&#xA;number 16, 23, and 29&#xA;in the three different orderings.&#xA;&#xA;&lt;p&gt;&#xA;The linearized pre-ordering of (&lt;i&gt;l&lt;/i&gt;, &lt;i&gt;n&lt;/i&gt;) is given by:&lt;blockquote&gt;&#xA;&#xA;&lt;p&gt;&#xA;seq(&lt;i&gt;L&lt;/i&gt;, 0) = 0 (&lt;i&gt;L&lt;/i&gt; is height of tree)&lt;br&gt;&#xA;seq(&lt;i&gt;l&lt;/i&gt;, &lt;i&gt;n&lt;/i&gt;) = seq(&lt;i&gt;l&lt;/i&gt;+1, &lt;i&gt;n&lt;/i&gt;/2) + 1 (&lt;i&gt;n&lt;/i&gt; even)&lt;br&gt;&#xA;seq(&lt;i&gt;l&lt;/i&gt;, &lt;i&gt;n&lt;/i&gt;) = seq(&lt;i&gt;l&lt;/i&gt;+1, &lt;i&gt;n&lt;/i&gt;/2) + 2&lt;sup&gt;&lt;i&gt;l&lt;/i&gt;+1&lt;/sup&gt; (&lt;i&gt;n&lt;/i&gt; odd)&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&#xA;This ordering is awkward because it changes depending on the height of the tree.&#xA;&#xA;&lt;p&gt;&#xA;The linearized post-ordering of (&lt;i&gt;l&lt;/i&gt;, &lt;i&gt;n&lt;/i&gt;) is given by:&lt;blockquote&gt;&#xA;&#xA;&lt;p&gt;&#xA;seq(0, &lt;i&gt;n
</entry>
<entry>
<title>Our Software Dependency Problem</title>
<id>tag:research.swtch.com,2012:research.swtch.com/deps</id>
<link rel="alternate" href="http://research.swtch.com/deps"></link>
<published>2019-01-23T11:00:00-05:00</published>
<updated>2019-01-23T11:02:00-05:00</updated>
<summary type="text">Download and run code from strangers on the internet. What could go wrong?</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;For decades, discussion of software reuse was far more common than actual software reuse.&#xA;Today, the situation is reversed: developers reuse software written by others every day,&#xA;in the form of software dependencies,&#xA;and the situation goes mostly unexamined.&#xA;&#xA;&lt;p&gt;&#xA;My own background includes a decade of working with&#xA;Googles internal source code system,&#xA;which treats software dependencies as a first-class concept,&lt;a class=footnote id=body1 href=&#34;#note1&#34;&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;/a&gt;&#xA;and also developing support for&#xA;dependencies in the Go programming language.&lt;a class=footnote id=body2 href=&#34;#note2&#34;&gt;&lt;sup&gt;2&lt;/sup&gt;&lt;/a&gt;&#xA;&#xA;&lt;p&gt;&#xA;Software dependencies carry with them&#xA;serious risks that are too often overlooked.&#xA;The shift to easy, fine-grained software reuse has happened so quickly&#xA;that we do not yet understand the best practices for choosing&#xA;and using dependencies effectively,&#xA;or even for deciding when they are appropriate and when not.&#xA;My purpose in writing this article is to raise awareness of the risks&#xA;and encourage more investigation of solutions.&#xA;&lt;a class=anchor href=&#34;#what_is_a_dependency&#34;&gt;&lt;h2 id=&#34;what_is_a_dependency&#34;&gt;What is a dependency?&lt;/h2&gt;&lt;/a&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;In todays software development world,&#xA;a &lt;i&gt;dependency&lt;/i&gt; is additional code that you want to call from your program.&#xA;Adding a dependency avoids repeating work already done:&#xA;designing, writing, testing, debugging, and maintaining a specific&#xA;unit of code.&#xA;In this article well call that unit of code a &lt;i&gt;package&lt;/i&gt;;&#xA;some systems use terms like library or module instead of package.&#xA;&#xA;&lt;p&gt;&#xA;Taking on externally-written dependencies is an old practice:&#xA;most programmers have at one point in their careers&#xA;had to go through the steps of manually downloading and installing&#xA;a required library, like Cs PCRE or zlib, or C++s Boost or Qt,&#xA;or Javas JodaTime or JUnit.&#xA;These packages contain high-quality, debugged code&#xA;that required significant expertise to develop.&#xA;For a program that needs the functionality provided by one of these packages,&#xA;the tedious work of manually downloading, installing, and updating&#xA;the package&#xA;is easier than the work of redeveloping that functionality from scratch.&#xA;But the high fixed costs of reuse&#xA;mean that manually-reused packages tend to be big:&#xA;a tiny package would be easier to reimplement.&#xA;&#xA;&lt;p&gt;&#xA;A &lt;i&gt;dependency manager&lt;/i&gt;&#xA;(sometimes called a package manager)&#xA;automates the downloading and installation of dependency packages.&#xA;As dependency managers&#xA;make individual packages easier to download and install,&#xA;the lower fixed costs make&#xA;smaller packages economical to publish and reuse.&#xA;&#xA;&lt;p&gt;&#xA;For example, the Node.js dependency manager NPM provides&#xA;access to over 750,000 packages.&#xA;One of them, &lt;code&gt;escape-string-regexp&lt;/code&gt;,&#xA;provides a single function that escapes regular expression&#xA;operators in its input.&#xA;The entire implementation is:&#xA;&lt;pre&gt;var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;&#xA;&#xA;module.exports = function (str) {&#xA;&#x9;if (typeof str !== &#39;string&#39;) {&#xA;&#x9;&#x9;throw new TypeError(&#39;Expected a string&#39;);&#xA;&#x9;}&#xA;&#x9;return str.replace(matchOperatorsRe, &#39;\\$&amp;amp;&#39;);&#xA;};&#xA;&lt;/pre&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;Before dependency managers, publishing an eight-line code library&#xA;would have been unthinkable: too much overhead for too little benefit.&#xA;But NPM has driven the overhead approximately to zero,&#xA;with the result that nearly-trivial functionality&#xA;can be packaged and reused.&#xA;In late January 2019, the &lt;code&gt;escape-string-regexp&lt;/code&gt; package&#xA;is explicitly depended upon by almost
</entry>
<entry>
<title>Why Add Versions To Go?</title>
<id>tag:research.swtch.com,2012:research.swtch.com/vgo-why-versions</id>
<link rel="alternate" href="http://research.swtch.com/vgo-why-versions"></link>
<published>2018-06-07T10:20:00-04:00</published>
<updated>2018-06-07T10:22:00-04:00</updated>
<summary type="text">Why should Go understand package versions at all? (Go &amp; Versioning, Part 10)</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;People sometimes ask me why we should add package versions to Go at all.&#xA;Isn&#39;t Go doing well enough without versions?&#xA;Usually these people have had a bad experience with versions&#xA;in another language, and they associate versions with breaking changes.&#xA;In this post, I want to talk a little about why we do need to add support for package versions to Go.&#xA;Later posts will address why we won&#39;t encourage breaking changes.&#xA;&#xA;&lt;p&gt;&#xA;The &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; command has two failure modes caused by ignorance of versions:&#xA;it can use code that is too old, and it can use code that is too new.&#xA;For example, suppose we want to use a package D, so we run &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; &lt;code&gt;D&lt;/code&gt;&#xA;with no packages installed yet.&#xA;The &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; command will download the latest copy of D&#xA;(whatever &lt;code&gt;git&lt;/code&gt; &lt;code&gt;clone&lt;/code&gt; brings down),&#xA;which builds successfully.&#xA;To make our discussion easier, let&#39;s call that D version 1.0&#xA;and keep D&#39;s dependency requirements in mind&#xA;(and in our diagrams).&#xA;But remember that while we understand the idea of versions&#xA;and dependency requirements, &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; does not.&#xA;&lt;pre&gt;$ go get D&#xA;&lt;/pre&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;&lt;img name=&#34;vgo-why-1&#34; class=&#34;center pad&#34; width=200 height=39 src=&#34;vgo-why-1.png&#34; srcset=&#34;vgo-why-1.png 1x, vgo-why-1@1.5x.png 1.5x, vgo-why-1@2x.png 2x, vgo-why-1@3x.png 3x, vgo-why-1@4x.png 4x&#34;&gt;&#xA;&#xA;&lt;p&gt;&#xA;Now suppose that a month later, we want to use C, which happens to import D.&#xA;We run &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; &lt;code&gt;C&lt;/code&gt;.&#xA;The &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; command downloads the latest copy of C,&#xA;which happens to be C 1.8 and imports D.&#xA;Since &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; already has a downloaded copy of D, it uses that one&#xA;instead of incurring the cost of a fresh download.&#xA;Unfortunately, the build of C fails:&#xA;C is using a new feature from D introduced in D 1.4,&#xA;and &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; is reusing D 1.0.&#xA;The code is too old.&#xA;&lt;pre&gt;$ go get C&#xA;&lt;/pre&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;&lt;img name=&#34;vgo-why-2&#34; class=&#34;center pad&#34; width=201 height=96 src=&#34;vgo-why-2.png&#34; srcset=&#34;vgo-why-2.png 1x, vgo-why-2@1.5x.png 1.5x, vgo-why-2@2x.png 2x, vgo-why-2@3x.png 3x, vgo-why-2@4x.png 4x&#34;&gt;&#xA;&#xA;&lt;p&gt;&#xA;Next we try running &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; &lt;code&gt;-u&lt;/code&gt;, which downloads the latest&#xA;copy of all the code involved, including code already downloaded.&#xA;&lt;pre&gt;$ go get -u C&#xA;&lt;/pre&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;&lt;img name=&#34;vgo-why-3&#34; class=&#34;center pad&#34; width=201 height=104 src=&#34;vgo-why-3.png&#34; srcset=&#34;vgo-why-3.png 1x, vgo-why-3@1.5x.png 1.5x, vgo-why-3@2x.png 2x, vgo-why-3@3x.png 3x, vgo-why-3@4x.png 4x&#34;&gt;&#xA;&#xA;&lt;p&gt;&#xA;Unfortunately, D 1.6 was released an hour ago and&#xA;contains a bug that breaks C.&#xA;Now the code is too new.&#xA;Watching this play out from above, we know what &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt;&#xA;needs to do: use D ≥ 1.4 but not D 1.6, so maybe D 1.4 or D 1.5.&#xA;It&#39;s very difficult to tell &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; that today,&#xA;since it doesn&#39;t understand the concept of a package version.&#xA;&#xA;&lt;p&gt;&#xA;Getting back to the original question in the post, &lt;i&gt;why add versions to Go?&lt;/i&gt;&#xA;&#xA;&lt;p&gt;&#xA;Because agreeing on a versioning system—a syntax for version identifiers,&#xA;along with rules for how to order and interpret them—establishes&#xA;a
</entry>
<entry>
<title>What is Software Engineering?</title>
<id>tag:research.swtch.com,2012:research.swtch.com/vgo-eng</id>
<link rel="alternate" href="http://research.swtch.com/vgo-eng"></link>
<published>2018-05-30T10:00:00-04:00</published>
<updated>2018-05-30T10:02:00-04:00</updated>
<summary type="text">What is software engineering and what does Go mean by it? (Go &amp; Versioning, Part 9)</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;Nearly all of Gos distinctive design decisions&#xA;were aimed at making software engineering simpler and easier.&#xA;We&#39;ve said this often.&#xA;The canonical reference is Rob Pike&#39;s 2012 article,&#xA;“&lt;a href=&#34;https://talks.golang.org/2012/splash.article&#34;&gt;Go at Google: Language Design in the Service of Software Engineering&lt;/a&gt;.”&#xA;But what is software engineering?&lt;blockquote&gt;&#xA;&#xA;&lt;p&gt;&#xA;&lt;i&gt;Software engineering is what happens to programming&#xA;&lt;br&gt;when you add time and other programmers.&lt;/i&gt;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&#xA;Programming means getting a program working.&#xA;You have a problem to solve, you write some Go code,&#xA;you run it, you get your answer, youre done.&#xA;Thats programming,&#xA;and that&#39;s difficult enough by itself.&#xA;But what if that code has to keep working, day after day?&#xA;What if five other programmers need to work on the code too?&#xA;Then you start to think about version control systems,&#xA;to track how the code changes over time&#xA;and to coordinate with the other programmers.&#xA;You add unit tests,&#xA;to make sure bugs you fix are not reintroduced over time,&#xA;not by you six months from now,&#xA;and not by that new team member whos unfamiliar with the code.&#xA;You think about modularity and design patterns,&#xA;to divide the program into parts that team members&#xA;can work on mostly independently.&#xA;You use tools to help you find bugs earlier.&#xA;You look for ways to make programs as clear as possible,&#xA;so that bugs are less likely.&#xA;You make sure that small changes can be tested quickly,&#xA;even in large programs.&#xA;You&#39;re doing all of this because your programming&#xA;has turned into software engineering.&#xA;&#xA;&lt;p&gt;&#xA;(This definition and explanation of software engineering&#xA;is my riff on an original theme by my Google colleague Titus Winters,&#xA;whose preferred phrasing is “software engineering is programming integrated over time.”&#xA;It&#39;s worth seven minutes of your time to see&#xA;&lt;a href=&#34;https://www.youtube.com/watch?v=tISy7EJQPzI&amp;t=8m17s&#34;&gt;his presentation of this idea at CppCon 2017&lt;/a&gt;,&#xA;from 8:17 to 15:00 in the video.)&#xA;&#xA;&lt;p&gt;&#xA;As I said earlier,&#xA;nearly all of Gos distinctive design decisions&#xA;have been motivated by concerns about software engineering,&#xA;by trying to accommodate time and other programmers&#xA;into the daily practice of programming.&#xA;&#xA;&lt;p&gt;&#xA;For example, most people think that we format Go code with &lt;code&gt;gofmt&lt;/code&gt;&#xA;to make code look nicer or to end debates among&#xA;team members about program layout.&#xA;But the &lt;a href=&#34;https://groups.google.com/forum/#!msg/golang-nuts/HC2sDhrZW5Y/7iuKxdbLExkJ&#34;&gt;most important reason for &lt;code&gt;gofmt&lt;/code&gt;&lt;/a&gt;&#xA;is that if an algorithm defines how Go source code is formatted,&#xA;then programs, like &lt;code&gt;goimports&lt;/code&gt; or &lt;code&gt;gorename&lt;/code&gt; or &lt;code&gt;go&lt;/code&gt; &lt;code&gt;fix&lt;/code&gt;,&#xA;can edit the source code more easily,&#xA;without introducing spurious formatting changes when writing the code back.&#xA;This helps you maintain code over time.&#xA;&#xA;&lt;p&gt;&#xA;As another example, Go import paths are URLs.&#xA;If code said &lt;code&gt;import&lt;/code&gt; &lt;code&gt;&#34;uuid&#34;&lt;/code&gt;,&#xA;youd have to ask which &lt;code&gt;uuid&lt;/code&gt; package.&#xA;Searching for &lt;code&gt;uuid&lt;/code&gt; on &lt;a href=&#34;https://godoc.org&#34;&gt;godoc.org&lt;/a&gt; turns up dozens of packages.&#xA;If instead the code says &lt;code&gt;import&lt;/code&gt; &lt;code&gt;&#34;github.com/pborman/uuid&#34;&lt;/code&gt;,&#xA;now its clear which package we mean.&#xA;Using URLs avoids ambiguity&#xA;and also reuses an existing mechanism for giving out names,&#xA;making it simpler and easier to coordinate with other programmers.&#xA;&#xA;&lt;p&gt;&#xA;Continuing the ex
</entry>
<entry>
<title>The vgo proposal is accepted. Now what?</title>
<id>tag:research.swtch.com,2012:research.swtch.com/vgo-accepted</id>
<link rel="alternate" href="http://research.swtch.com/vgo-accepted"></link>
<published>2018-05-29T16:45:00-04:00</published>
<updated>2018-05-29T16:47:00-04:00</updated>
<summary type="text">What is the state of vgo? (Go &amp; Versioning, Part 8)</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;Last week, the proposal review committee accepted the “vgo approach” elaborated&#xA;on this blog in February and then summarized as &lt;a href=&#34;https://golang.org/issue/24301&#34;&gt;proposal #24301&lt;/a&gt;.&#xA;There has been some confusion about exactly what that means&#xA;and what happens next.&#xA;&#xA;&lt;p&gt;&#xA;In general, &lt;a href=&#34;https://golang.org/s/proposal&#34;&gt;a Go proposal&lt;/a&gt; is a discussion about whether to adopt a particular&#xA;approach and move on to writing, reviewing, and releasing a production implementation. Accepting a proposal&#xA;does not mean the implementation is complete. (In some cases there is no&#xA;implementation yet at all!) Accepting a proposal only means that we believe&#xA;the design is appropriate and that the production implementation can proceed&#xA;and be committed and released.&#xA;Inevitably we find details that need adjustment during that process.&#xA;&#xA;&lt;p&gt;&#xA;Vgo as it exists today is not the final implementation.&#xA;It is a prototype to make the ideas concrete&#xA;and to make it possible to experiment with the approach.&#xA;Bugs and design flaws will necessarily be found and fixed as we move toward making it the official&#xA;approach in the go command.&#xA;For example, the original vgo prototype downloaded code from sites&#xA;like GitHub using their APIs, for better efficiency and to avoid requiring&#xA;users to have every possible version control system installed.&#xA;Unfortunately, the GitHub API is far more restrictively rate-limited than&#xA;plain &lt;code&gt;git&lt;/code&gt; access, so the current vgo implementation has gone back&#xA;to invoking &lt;code&gt;git&lt;/code&gt;.&#xA;Although we&#39;d still &lt;a href=&#34;https://blogs.msdn.microsoft.com/devops/2018/05/29/announcing-the-may-2018-git-security-vulnerability/&#34;&gt;like to move away&lt;/a&gt;&#xA;from version control as the default&#xA;mechanism for obtaining open source code, we won&#39;t do that until we have a viable&#xA;replacement ready, to make any transition&#xA;as smooth as possible.&#xA;&#xA;&lt;p&gt;&#xA;More generally, the key reason for the vgo proposal is to add a common vocabulary&#xA;and semantics around versions of Go code, so that&#xA;developers and all kinds of tools can be precise&#xA;when talking to each other about exactly which program should be built, run, or analyzed.&#xA;Accepting the proposal is the beginning, not the end.&#xA;&#xA;&lt;p&gt;&#xA;One thing I&#39;ve heard from many people is that they want to start&#xA;using vgo in their company or project but are held back by not having&#xA;support for it in the toolchains their developers are using.&#xA;The fact that vgo is integrated deeply into the go command,&#xA;instead of being a separate vendor directory-writer,&#xA;introduces a chicken-and-egg problem.&#xA;To address that problem and make it as easy as possible&#xA;for developers to try the vgo approach,&#xA;we plan to include vgo functionality as an experimental opt-in feature in Go 1.11,&#xA;with the hope of incorporating feedback and finalizing the feature for Go 1.12.&#xA;(This rollout is analogous to how we included vendor directory functionality&#xA;as an experimental opt-in feature in Go 1.5 and turned it on by default in Go 1.6.)&#xA;We also plan to make &lt;a href=&#34;https://golang.org/issue/25069&#34;&gt;minimal changes to legacy &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt;&lt;/a&gt; so that&#xA;it can obtain and understand code written using vgo conventions.&#xA;Those changes will be included in the next point release for Go 1.9 and Go 1.10.&#xA;&#xA;&lt;p&gt;&#xA;One thing I&#39;ve heard from zero people is that&#xA;&lt;a href=&#34;https://research.swtch.com/vgo&#34;&gt;they wish my blog posts were longer&lt;/a&gt;.&#xA;The original posts are quite dense and a number of important points&#xA;are more buried than they should be.&#xA;This post is the first of a series of much shorter posts to try to make&#xA;focused points about specific details of the vgo design, ap
</entry>
<entry>
<title>Versioned Go Commands</title>
<id>tag:research.swtch.com,2012:research.swtch.com/vgo-cmd</id>
<link rel="alternate" href="http://research.swtch.com/vgo-cmd"></link>
<published>2018-02-23T10:09:00-05:00</published>
<updated>2018-02-23T10:11:00-05:00</updated>
<summary type="text">What does it mean to add versioning to the go command? (Go &amp; Versioning, Part 7)</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;What does it mean to add versioning to the &lt;code&gt;go&lt;/code&gt; command?&#xA;The &lt;a href=&#34;vgo-intro&#34;&gt;overview post&lt;/a&gt; gave a preview,&#xA;but the followup posts focused mainly on underlying&#xA;details: &lt;a href=&#34;vgo-import&#34;&gt;the import compatibility rule&lt;/a&gt;,&#xA;&lt;a href=&#34;vgo-mvs&#34;&gt;minimal version selection&lt;/a&gt;,&#xA;and &lt;a href=&#34;vgo-module&#34;&gt;defining go modules&lt;/a&gt;.&#xA;With those better understood, this post examines the&#xA;details of how versioning affects the &lt;code&gt;go&lt;/code&gt; command line&#xA;and the reasons for those changes.&#xA;&#xA;&lt;p&gt;&#xA;The major changes are:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;All commands (&lt;code&gt;go&lt;/code&gt; &lt;code&gt;build&lt;/code&gt;, &lt;code&gt;go&lt;/code&gt; &lt;code&gt;run&lt;/code&gt;, and so on)&#xA;will download imported source code automatically,&#xA;if the necessary version is not already present&#xA;in the download cache on the local system.&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;The &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; command will serve mainly to change&#xA;which version of a package should be used in future&#xA;build commands.&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;The &lt;code&gt;go&lt;/code&gt; &lt;code&gt;list&lt;/code&gt; command will add access to module&#xA;information.&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;A new &lt;code&gt;go&lt;/code&gt; &lt;code&gt;release&lt;/code&gt; command will automate some of the&#xA;work a module author should do when tagging a new release,&#xA;such as checking API compatibility.&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;The &lt;code&gt;all&lt;/code&gt; pattern is redefined to make sense in the&#xA;world of modules.&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;Developers can and will be encouraged to work in&#xA;directories outside the GOPATH tree.&lt;/ul&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;All these changes are implemented in the &lt;code&gt;vgo&lt;/code&gt; prototype.&#xA;&#xA;&lt;p&gt;&#xA;Deciding exactly how a build system should work is hard.&#xA;The introduction of new build caching in Go 1.10 prompted some&#xA;important, difficult decisions about the meaning of &lt;code&gt;go&lt;/code&gt; commands,&#xA;and the introduction of versioning does too.&#xA;Before I explain some of the decisions, I want to start by&#xA;explaining a guiding principle that I&#39;ve found helpful recently,&#xA;which I call the isolation rule:&lt;blockquote&gt;&#xA;&#xA;&lt;p&gt;&#xA;&lt;i&gt;The result of a build command should depend only on the&#xA;source files that are its logical inputs, never on&#xA;hidden state left behind by previous build commands.)&lt;/i&gt;&#xA;&#xA;&lt;p&gt;&#xA;&lt;i&gt;That is, what a command does in isolation—on a&#xA;clean system loaded with only the relevant input&#xA;source files—is what it should do all the time,&#xA;no matter what else has happened on the system recently.&lt;/i&gt;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&#xA;To see the wisdom of this rule, let me retell an old build story&#xA;and show how the isolation rule explains what happened.&#xA;&lt;a class=anchor href=&#34;#old_build_story&#34;&gt;&lt;h2 id=&#34;old_build_story&#34;&gt;An Old Build Story&lt;/h2&gt;&lt;/a&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;Long ago, when compilers and computers were very slow,&#xA;developers had scripts to build their whole programs from scratch,&#xA;but if they were just modifying one source file,&#xA;they might save time by manually recompiling just that file&#xA;and then relinking the overall program,&#xA;avoiding the cost of recompiling all the source files that&#xA;hadn&#39;t changed.&#xA;These manual incremental builds were fast but error-prone:&#xA;if you forgot to recompile a source file that you&#39;d modified,&#xA;the link of the final executable would use an out-of-date object file,&#xA;the executable would demonstrate buggy behavior,&#xA;and you might spend a long time staring at the (correct!) source code&#xA;looki
</entry>
<entry>
<title>Defining Go Modules</title>
<id>tag:research.swtch.com,2012:research.swtch.com/vgo-module</id>
<link rel="alternate" href="http://research.swtch.com/vgo-module"></link>
<published>2018-02-22T17:00:00-05:00</published>
<updated>2018-02-22T17:02:00-05:00</updated>
<summary type="text">How to specify what&#39;s in a module. (Go &amp; Versioning, Part 6)</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;As introduced in the &lt;a href=&#34;vgo-intro&#34;&gt;overview post&lt;/a&gt;, a Go &lt;i&gt;module&lt;/i&gt;&#xA;is a collection of packages versioned as a unit,&#xA;along with a &lt;code&gt;go.mod&lt;/code&gt; file listing other required modules.&#xA;The move to modules is an opportunity for us to revisit and fix&#xA;many details of how the &lt;code&gt;go&lt;/code&gt; command manages source code.&#xA;The current &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; model will be about ten years old when we&#xA;retire it in favor of modules.&#xA;We need to make sure that the module design will serve us&#xA;well for the next decade. In particular:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;We want to encourage more developers to tag releases of their&#xA;packages, instead of expecting that&#xA;users will just pick a commit hash that looks good to them.&#xA;Tagging explicit releases makes clear what is expected to be&#xA;useful to others and what is still under development.&#xA;At the same time, it must still be possible—although maybe not convenient—to request specific&#xA;commits.&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;We want to move away from invoking version control&#xA;tools such as &lt;code&gt;bzr&lt;/code&gt;, &lt;code&gt;fossil&lt;/code&gt;, &lt;code&gt;git&lt;/code&gt;, &lt;code&gt;hg&lt;/code&gt;, and &lt;code&gt;svn&lt;/code&gt; to download source code.&#xA;These fragment the ecosystem: packages developed using Bazaar or&#xA;Fossil, for example, are effectively unavailable to users who cannot&#xA;or choose not to install these tools.&#xA;The version control tools have also been a source of &lt;a href=&#34;https://golang.org/issue/22131&#34;&gt;exciting&lt;/a&gt; &lt;a href=&#34;https://www.mercurial-scm.org/wiki/WhatsNew/Archive#Mercurial_3.2.3_.282014-12-18.29&#34;&gt;security&lt;/a&gt; &lt;a href=&#34;https://git-blame.blogspot.com/2014/12/git-1856-195-205-214-and-221-and.html&#34;&gt;problems&lt;/a&gt;.&#xA;It would be good to move them outside the security perimeter.&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;We want to allow multiple modules to be developed in a single&#xA;source code repository but versioned independently.&#xA;While most developers will likely keep working with one module per repo,&#xA;larger projects might benefit from having multiple modules in a single repo.&#xA;For example, we&#39;d like to keep &lt;code&gt;golang.org/x/text&lt;/code&gt; a single repository&#xA;but be able to version experimental new packages separately&#xA;from established packages.&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;We want to make it easy for individuals and companies to&#xA;put caching proxies in front of &lt;code&gt;go&lt;/code&gt; &lt;code&gt;get&lt;/code&gt; downloads, whether for availability&#xA;(use a local copy to ensure the download works tomorrow)&#xA;or security&#xA;(vet packages before they can be used inside a company).&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;We want to make it possible, at some future point, to introduce&#xA;a shared proxy for use by the Go community, similar in spirit&#xA;to those used by Rust, Node, and other languages.&#xA;At the same time, the design must work well without assuming&#xA;such a proxy or registry.&#xA;&lt;li&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;We want to eliminate vendor directories. They were introduced&#xA;for reproducibility and availability, but we now have better&#xA;mechanisms.&#xA;Reproducibility is handled by proper versioning, and availability&#xA;is handled by caching proxies.&lt;/ul&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;This post presents the parts of the &lt;code&gt;vgo&lt;/code&gt; design that address&#xA;these issues.&#xA;Everything here is preliminary: we will change the design&#xA;if we find that it is not right.&#xA;&lt;a class=anchor href=&#34;#versioned_releases&#34;&gt;&lt;h2 id=&#34;versioned_releases&#34;&gt;Versioned Releases&lt;/h2&gt;&lt;/a&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;Abstraction boundaries let projects scale.&#xA;Originally, all Go packages could be imported b
</entry>
<entry>
<title>Reproducible, Verifiable, Verified Builds</title>
<id>tag:research.swtch.com,2012:research.swtch.com/vgo-repro</id>
<link rel="alternate" href="http://research.swtch.com/vgo-repro"></link>
<published>2018-02-21T21:28:00-05:00</published>
<updated>2018-02-21T21:30:00-05:00</updated>
<summary type="text">Consistent builds in versioned Go. (Go &amp; Versioning, Part 5)</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;Once both Go developers and tools share a vocabulary around package versions,&#xA;it&#39;s relatively straightforward to add support in the toolchain for&#xA;reproducible, verifiable, and verified builds.&#xA;In fact, the basics are already in the &lt;code&gt;vgo&lt;/code&gt; prototype.&#xA;&#xA;&lt;p&gt;&#xA;Since people sometimes disagree about the exact definitions&#xA;of these terms, let&#39;s establish some basic terminology.&#xA;For this post:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;A &lt;i&gt;reproducible build&lt;/i&gt; is one that,&#xA;when repeated, produces the same result.&#xA;&lt;li&gt;&#xA;A &lt;i&gt;verifiable build&lt;/i&gt; is one that records enough&#xA;information to be precise about exactly how to repeat it.&#xA;&lt;li&gt;&#xA;A &lt;i&gt;verified build&lt;/i&gt; is one that checks that it is using&#xA;the expected source code.&lt;/ul&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;&lt;code&gt;Vgo&lt;/code&gt; delivers reproducible builds by default.&#xA;The resulting binaries are verifiable, in that&#xA;they record versions of the exact source code that went into the build.&#xA;And it is possible to configure your repository so that&#xA;users rebuilding your software verify that their builds&#xA;match yours, using cryptographic hashes,&#xA;no matter how they obtain the dependencies.&#xA;&lt;a class=anchor href=&#34;#reproducible_builds&#34;&gt;&lt;h2 id=&#34;reproducible_builds&#34;&gt;Reproducible Builds&lt;/h2&gt;&lt;/a&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;At the very least, we want to make sure that when you build my program,&#xA;the build system decides to use the same versions of the code.&#xA;&lt;a href=&#34;vgo-mvs&#34;&gt;Minimal version selection&lt;/a&gt; delivers this property by default.&#xA;The &lt;code&gt;go.mod&lt;/code&gt; file alone is enough to uniquely determine which&#xA;module versions should be used for the build&#xA;(assuming dependencies are available),&#xA;and that decision is stable even as new versions of a module&#xA;are introduced into the ecosystem.&#xA;This differs from most other systems, which adopt new versions&#xA;automatically and need to be constrained to yield&#xA;reproducible builds.&#xA;I covered this in the minimal version selection post,&#xA;but it&#39;s an important, subtle detail, so I&#39;ll try to give a short reprise here.&#xA;&#xA;&lt;p&gt;&#xA;To make this concrete, let&#39;s look at a few real packages from Cargo,&#xA;Rust&#39;s package manager.&#xA;To be clear, I am not picking on Cargo.&#xA;I think Cargo is an example of the current&#xA;state of the art in package managers,&#xA;and there&#39;s much to learn from it.&#xA;If we can make Go package management as smooth as Cargo&#39;s, I&#39;ll be happy.&#xA;But I also think that it is worth exploring whether we would&#xA;benefit from choosing a different default when it comes to&#xA;version selection.&#xA;&#xA;&lt;p&gt;&#xA;Cargo prefers maximum versions in the following sense.&#xA;Over at crates.io, the latest &lt;a href=&#34;https://crates.io/crates/toml&#34;&gt;&lt;code&gt;toml&lt;/code&gt;&lt;/a&gt; is 0.4.5&#xA;as I write this post.&#xA;It lists a dependency on &lt;a href=&#34;https://crates.io/crates/serde&#34;&gt;&lt;code&gt;serde&lt;/code&gt;&lt;/a&gt; 1.0 or later;&#xA;the latest &lt;code&gt;serde&lt;/code&gt; is 1.0.27.&#xA;If you start a new project and add a dependency on&#xA;&lt;code&gt;toml&lt;/code&gt; 0.4.1 or later, Cargo has a choice to make.&#xA;According to the constraints, any of 0.4.1, 0.4.2, 0.4.3, 0.4.4, or 0.4.5 would be acceptable.&#xA;All other things being equal, Cargo prefers the &lt;a href=&#34;cargo-newest.html&#34;&gt;newest acceptable version&lt;/a&gt;, 0.4.5.&#xA;Similarly, any of &lt;code&gt;serde&lt;/code&gt; 1.0.0 through 1.0.27 are acceptable,&#xA;and Cargo chooses 1.0.27.&#xA;These choices change as new versions are introduced.&#xA;If &lt;code&gt;serde&lt;/code&gt; 1.0.28 is released tonight and I add toml 0.4.5&#xA;to a project tomorrow, I&#39;ll get 1.0.28 instead of 1.0.27.&#xA;As described so far, Cargo&#39;s builds are not repeatable.&#x
</entry>
<entry>
<title>Minimal Version Selection</title>
<id>tag:research.swtch.com,2012:research.swtch.com/vgo-mvs</id>
<link rel="alternate" href="http://research.swtch.com/vgo-mvs"></link>
<published>2018-02-21T16:41:00-05:00</published>
<updated>2018-02-21T16:43:00-05:00</updated>
<summary type="text">How do builds select which versions to use? (Go &amp; Versioning, Part 4)</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;A &lt;a href=&#34;vgo-intro&#34;&gt;versioned Go command&lt;/a&gt; must decide which module versions to use in each build.&#xA;I call this list of modules and versions for use in a given build the &lt;i&gt;build list&lt;/i&gt;.&#xA;For stable development, today&#39;s build list must also be tomorrow&#39;s build list.&#xA;But then developers must also be allowed to change the build list: to upgrade all modules, to upgrade one module, or to downgrade one module.&#xA;&#xA;&lt;p&gt;&#xA;The &lt;i&gt;version selection&lt;/i&gt; problem therefore is to define the meaning of, and to give algorithms implementing, these four operations on build lists:&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&#xA;Construct the current build list.&#xA;&lt;li&gt;&#xA;Upgrade all modules to their latest versions.&#xA;&lt;li&gt;&#xA;Upgrade one module to a specific newer version.&#xA;&lt;li&gt;&#xA;Downgrade one module to a specific older version.&lt;/ol&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;The last two operations specify one module to upgrade or downgrade, but doing so may require upgrading, downgrading, adding, or removing other modules, ideally as few as possible, to satisfy dependencies.&#xA;&#xA;&lt;p&gt;&#xA;This post presents &lt;i&gt;minimal version selection&lt;/i&gt;, a new, simple approach to the version selection problem.&#xA;Minimal version selection is easy to understand and predict,&#xA;which should make it easy to work with.&#xA;It also produces &lt;i&gt;high-fidelity builds&lt;/i&gt;, in which the dependencies a user builds are as close as possible to the ones the author developed against.&#xA;It is also efficient to implement, using nothing more complex than recursive graph traversals,&#xA;so that a complete minimal version selection implementation in Go is only a few hundred lines of code.&#xA;&#xA;&lt;p&gt;&#xA;Minimal version selection assumes that each module declares its own dependency requirements: a list of minimum versions of other modules. Modules are assumed to follow the &lt;a href=&#34;vgo-import&#34;&gt;import compatibility rule&lt;/a&gt;—packages in any newer version should work as well as older ones—so a dependency requirement gives only a minimum version, never a maximum version or a list of incompatible later versions.&#xA;&#xA;&lt;p&gt;&#xA;Then the definitions of the four operations are:&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&#xA;To construct the build list for a given target: start the list with the target itself, and then append each requirement&#39;s own build list. If a module appears in the list multiple times, keep only the newest version.&#xA;&lt;li&gt;&#xA;To upgrade all modules to their latest versions: construct the build list, but read each requirement as if it requested the latest module version.&#xA;&lt;li&gt;&#xA;To upgrade one module to a specific newer version: construct the non-upgraded build list and then append the new module&#39;s build list. If a module appears in the list multiple times, keep only the newest version.&#xA;&lt;li&gt;&#xA;To downgrade one module to a specific older version: rewind the required version of each top-level requirement until that requirement&#39;s build list no longer refers to newer versions of the downgraded module.&lt;/ol&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;These operations are simple, efficient, and easy to implement.&#xA;&lt;a class=anchor href=&#34;#example&#34;&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;&lt;/a&gt;&#xA;&#xA;&#xA;&lt;p&gt;&#xA;Before we examine minimal version selection in more detail, let&#39;s look at why a new approach is necessary. We&#39;ll use the following set of modules as a running example throughout the post:&#xA;&#xA;&lt;p&gt;&#xA;&lt;img name=&#34;version-select-1&#34; class=&#34;center pad&#34; width=463 height=272 src=&#34;version-select-1.png&#34; srcset=&#34;version-select-1.png 1x, version-select-1@1.5x.png 1.5x, version-select-1@2x.png 2x, version-select-1@3x.png 3x, version-select-1@4x.png 4x&#34;&gt;&#xA;&#xA;&lt;p&gt;&#xA;The diagram shows the module requirement graph for seven modules (dotte
</entry>
<entry>
<title>Go and Dogma</title>
<id>tag:research.swtch.com,2012:research.swtch.com/dogma</id>
<link rel="alternate" href="http://research.swtch.com/dogma"></link>
<published>2017-01-09T09:00:00-05:00</published>
<updated>2017-01-09T09:02:00-05:00</updated>
<summary type="text">Programming language dogmatics.</summary>
<content type="html">&#xA;&#xA;&lt;p&gt;&#xA;[&lt;i&gt;Cross-posting from last years &lt;a href=&#34;https://www.reddit.com/r/golang/comments/46bd5h/ama_we_are_the_go_contributors_ask_us_anything/d05yyde/?context=3&amp;st=ixq5hjko&amp;sh=7affd469&#34;&gt;Go contributors AMA&lt;/a&gt; on Reddit, because its still important to remember.&lt;/i&gt;]&#xA;&#xA;&lt;p&gt;&#xA;One of the perks of working on Go these past years has been the chance to have many great discussions with other language designers and implementers, for example about how well various design decisions worked out or the common problems of implementing what look like very different languages (for example both Go and Haskell need some kind of “green threads”, so there are more shared runtime challenges than you might expect). In one such conversation, when I was talking to a group of early Lisp hackers, one of them pointed out that these discussions are basically never dogmatic. Designers and implementers remember working through the good arguments on both sides of a particular decision, and theyre often eager to hear about someone elses experience with what happens when you make that decision differently. Contrast that kind of discussion with the heated arguments or overly zealous statements you sometimes see from users of the same languages. Theres a real disconnect, possibly because the users dont have the experience of weighing the arguments on both sides and dont realize how easily a particular decision might have gone the other way.&#xA;&#xA;&lt;p&gt;&#xA;Language design and implementation is engineering. We make decisions using evaluations of costs and benefits or, if we must, using predictions of those based on past experience. I think we have an important responsibility to explain both sides of a particular decision, to make clear that the arguments for an alternate decision are actually good ones that we weighed and balanced, and to avoid the suggestion that particular design decisions approach dogma. I hope &lt;a href=&#34;https://www.reddit.com/r/golang/comments/46bd5h/ama_we_are_the_go_contributors_ask_us_anything/d05yyde/?context=3&amp;st=ixq5hjko&amp;sh=7affd469&#34;&gt;the Reddit AMA&lt;/a&gt; as well as discussion on &lt;a href=&#34;https://groups.google.com/group/golang-nuts&#34;&gt;golang-nuts&lt;/a&gt; or &lt;a href=&#34;http://stackoverflow.com/questions/tagged/go&#34;&gt;StackOverflow&lt;/a&gt; or the &lt;a href=&#34;https://forum.golangbridge.org/&#34;&gt;Go Forum&lt;/a&gt; or at &lt;a href=&#34;https://golang.org/wiki/Conferences&#34;&gt;conferences&lt;/a&gt; help with that.&#xA;&#xA;&lt;p&gt;&#xA;But we need help from everyone. Remember that none of the decisions in Go are infallible; theyre just our best attempts at the time we made them, not wisdom received on stone tablets. If someone asks why Go does X instead of Y, please try to present the engineering reasons fairly, including for Y, and avoid argument solely by appeal to authority. Its too easy to fall into the “well thats just not how its done here” trap. And now that I know about and watch for that trap, I see it in nearly every technical community, although some more than others.&#xA;</content>
</entry>
<entry>
<title>A Tour of Acme</title>
<id>tag:research.swtch.com,2012:research.swtch.com/acme</id>
<link rel="alternate" href="http://research.swtch.com/acme"></link>
<published>2012-09-17T11:00:00-04:00</published>
<updated>2012-09-17T11:00:00-04:00</updated>
<summary type="text">A video introduction to Acme, the Plan 9 text editor</summary>
<content type="html">&#xA;&lt;p class=&#34;lp&#34;&gt;&#xA;People I work with recognize my computer easily:&#xA;it&#39;s the one with nothing but yellow windows and blue bars on the screen.&#xA;That&#39;s the text editor acme, written by Rob Pike for Plan 9 in the early 1990s.&#xA;Acme focuses entirely on the idea of text as user interface.&#xA;It&#39;s difficult to explain acme without seeing it, though, so I&#39;ve put together&#xA;a screencast explaining the basics of acme and showing a brief programming session.&#xA;Remember as you watch the video that the 854x480 screen is quite cramped.&#xA;Usually you&#39;d run acme on a larger screen: even my MacBook Air has almost four times&#xA;as much screen real estate.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;center&gt;&#xA;&lt;div style=&#34;border: 1px solid black; width: 853px; height: 480px;&#34;&gt;&lt;iframe width=&#34;853&#34; height=&#34;480&#34; src=&#34;https://www.youtube.com/embed/dP1xVpMPn8M?rel=0&#34; frameborder=&#34;0&#34; allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;&#xA;&lt;/center&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;The video doesn&#39;t show everything acme can do, nor does it show all the ways you can use it.&#xA;Even small idioms like where you type text to be loaded or executed vary from user to user.&#xA;To learn more about acme, read Rob Pike&#39;s paper &amp;ldquo;&lt;a href=&#34;/acme.pdf&#34;&gt;Acme: A User Interface for Programmers&lt;/a&gt;&amp;rdquo; and then try it.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;Acme runs on most operating systems.&#xA;If you use &lt;a href=&#34;http://plan9.bell-labs.com/plan9/&#34;&gt;Plan 9 from Bell Labs&lt;/a&gt;, you already have it.&#xA;If you use FreeBSD, Linux, OS X, or most other Unix clones, you can get it as part of &lt;a href=&#34;http://swtch.com/plan9port/&#34;&gt;Plan 9 from User Space&lt;/a&gt;.&#xA;If you use Windows, I suggest trying acme as packaged in &lt;a href=&#34;http://code.google.com/p/acme-sac/&#34;&gt;acme stand alone complex&lt;/a&gt;, which is based on the Inferno programming environment.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=lp&gt;&lt;b&gt;Mini-FAQ&lt;/b&gt;:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;i&gt;Q. Can I use scalable fonts?&lt;/i&gt; A. On the Mac, yes. If you run &lt;code&gt;acme -f /mnt/font/Monaco/16a/font&lt;/code&gt; you get 16-point anti-aliased Monaco as your font, served via &lt;a href=&#34;http://swtch.com/plan9port/man/man4/fontsrv.html&#34;&gt;fontsrv&lt;/a&gt;. If you&#39;d like to add X11 support to fontsrv, I&#39;d be happy to apply the patch.&#xA;&lt;li&gt;&lt;i&gt;Q. Do I need X11 to build on the Mac?&lt;/i&gt; A. No. The build will complain that it cannot build &amp;lsquo;snarfer&amp;rsquo; but it should complete otherwise. You probably don&#39;t need snarfer.&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;If you&#39;re interested in history, the predecessor to acme was called help. Rob Pike&#39;s paper &amp;ldquo;&lt;a href=&#34;/help.pdf&#34;&gt;A Minimalist Global User Interface&lt;/a&gt;&amp;rdquo; describes it. See also &amp;ldquo;&lt;a href=&#34;/sam.pdf&#34;&gt;The Text Editor sam&lt;/a&gt;&amp;rdquo;&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;&lt;i&gt;Correction&lt;/i&gt;: the smiley program in the video was written by Ken Thompson.&#xA;I got it from Dennis Ritchie, the more meticulous archivist of the pair.&#xA;&lt;/p&gt;&#xA;&#xA;</content>
</entry>
<entry>
<title>Minimal Boolean Formulas</title>
<id>tag:research.swtch.com,2012:research.swtch.com/boolean</id>
<link rel="alternate" href="http://research.swtch.com/boolean"></link>
<published>2011-05-18T00:00:00-04:00</published>
<updated>2011-05-18T00:00:00-04:00</updated>
<summary type="text">Simplify equations with God</summary>
<content type="html">&#xA;&lt;p&gt;&lt;style type=&#34;text/css&#34;&gt;&#xA;p { line-height: 150%; }&#xA;blockquote { text-align: left; }&#xA;pre.alg { font-family: sans-serif; font-size: 100%; margin-left: 60px; }&#xA;td, th { padding-left; 5px; padding-right: 5px; vertical-align: top; }&#xA;#times td { text-align: right; }&#xA;table { padding-top: 1em; padding-bottom: 1em; }&#xA;#find td { text-align: center; }&#xA;&lt;/style&gt;&#xA;&#xA;&lt;p class=lp&gt;&#xA;&lt;a href=&#34;http://oeis.org/A056287&#34;&gt;28&lt;/a&gt;. &#xA;That&#39;s the minimum number of AND or OR operators&#xA;you need in order to write any Boolean function of five variables.&#xA;&lt;a href=&#34;http://alexhealy.net/&#34;&gt;Alex Healy&lt;/a&gt; and I computed that in April 2010. Until then,&#xA;I believe no one had ever known that little fact.&#xA;This post describes how we computed it&#xA;and how we almost got scooped by &lt;a href=&#34;http://research.swtch.com/2011/01/knuth-volume-4a.html&#34;&gt;Knuth&#39;s Volume 4A&lt;/a&gt;&#xA;which considers the problem for AND, OR, and XOR.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;A Naive Brute Force Approach&lt;/h3&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;Any Boolean function of two variables&#xA;can be written with at most 3 AND or OR operators: the parity function&#xA;on two variables X XOR Y is (X AND Y&#39;) OR (X&#39; AND Y), where X&#39; denotes&#xA;&amp;ldquo;not X.&amp;rdquo; We can shorten the notation by writing AND and OR&#xA;like multiplication and addition: X XOR Y = X*Y&#39; + X&#39;*Y.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;For three variables, parity is also a hardest function, requiring 9 operators:&#xA;X XOR Y XOR Z = (X*Z&#39;+X&#39;*Z+Y&#39;)*(X*Z+X&#39;*Z&#39;+Y).&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;For four variables, parity is still a hardest function, requiring 15 operators:&#xA;W XOR X XOR Y XOR Z = (X*Z&#39;+X&#39;*Z+W&#39;*Y+W*Y&#39;)*(X*Z+X&#39;*Z&#39;+W*Y+W&#39;*Y&#39;).&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;The sequence so far prompts a few questions. Is parity always a hardest function?&#xA;Does the minimum number of operators alternate between 2&lt;sup&gt;n&lt;/sup&gt;&amp;#8722;1 and 2&lt;sup&gt;n&lt;/sup&gt;+1?&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;I computed these results in January 2001 after hearing&#xA;the problem from Neil Sloane, who suggested it as a variant&#xA;of a similar problem first studied by Claude Shannon.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;The program I wrote to compute a(4) computes the minimum number of&#xA;operators for every Boolean function of n variables&#xA;in order to find the largest minimum over all functions.&#xA;There are 2&lt;sup&gt;4&lt;/sup&gt; = 16 settings of four variables, and each function&#xA;can pick its own value for each setting, so there are 2&lt;sup&gt;16&lt;/sup&gt; different&#xA;functions. To make matters worse, you build new functions&#xA;by taking pairs of old functions and joining them with AND or OR.&#xA;2&lt;sup&gt;16&lt;/sup&gt; different functions means 2&lt;sup&gt;16&lt;/sup&gt;&amp;#183;2&lt;sup&gt;16&lt;/sup&gt; = 2&lt;sup&gt;32&lt;/sup&gt; pairs of functions.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;The program I wrote was a mangling of the Floyd-Warshall&#xA;all-pairs shortest paths algorithm. That algorithm is:&#xA;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&#34;indent alg&#34;&gt;&#xA;// Floyd-Warshall all pairs shortest path&#xA;func compute():&#xA; for each node i&#xA; for each node j&#xA; dist[i][j] = direct distance, or &amp;#8734;&#xA; &#xA; for each node k&#xA; for each node i&#xA; for each node j&#xA; d = dist[i][k] + dist[k][j]&#xA; if d &amp;lt; dist[i][j]&#xA; dist[i][j] = d&#xA; return&#xA;&lt;/pre&gt;&#xA;&#xA;&lt;p class=lp&gt;&#xA;The algorithm begins with the distance table dist[i][j] set to&#xA;an actual distance if i is connected to j and infinity otherwise.&#xA;Then each round updates the table to account for paths&#xA;going through the node k: if it&#
</entry>
<entry>
<title>Zip Files All The Way Down</title>
<id>tag:research.swtch.com,2012:research.swtch.com/zip</id>
<link rel="alternate" href="http://research.swtch.com/zip"></link>
<published>2010-03-18T00:00:00-04:00</published>
<updated>2010-03-18T00:00:00-04:00</updated>
<summary type="text">Did you think it was turtles?</summary>
<content type="html">&#xA;&lt;p&gt;&lt;p class=lp&gt;&#xA;Stephen Hawking begins &lt;i&gt;&lt;a href=&#34;http://www.amazon.com/-/dp/0553380168&#34;&gt;A Brief History of Time&lt;/a&gt;&lt;/i&gt; with this story:&#xA;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;&lt;p class=pp&gt;&#xA;A well-known scientist (some say it was Bertrand Russell) once gave a public lecture on astronomy. He described how the earth orbits around the sun and how the sun, in turn, orbits around the center of a vast collection of stars called our galaxy. At the end of the lecture, a little old lady at the back of the room got up and said: &amp;ldquo;What you have told us is rubbish. The world is really a flat plate supported on the back of a giant tortoise.&amp;rdquo; The scientist gave a superior smile before replying, &amp;ldquo;What is the tortoise standing on?&amp;rdquo; &amp;ldquo;You&#39;re very clever, young man, very clever,&amp;rdquo; said the old lady. &amp;ldquo;But it&#39;s turtles all the way down!&amp;rdquo;&#xA;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p class=lp&gt;&#xA;Scientists today are pretty sure that the universe is not actually turtles all the way down,&#xA;but we can create that kind of situation in other contexts.&#xA;For example, here we have &lt;a href=&#34;http://www.youtube.com/watch?v=Y-gqMTt3IUg&#34;&gt;video monitors all the way down&lt;/a&gt;&#xA;and &lt;a href=&#34;http://www.amazon.com/gp/customer-media/product-gallery/0387900926/ref=cm_ciu_pdp_images_all&#34;&gt;set theory books all the way down&lt;/a&gt;,&#xA;and &lt;a href=&#34;http://blog.makezine.com/archive/2009/01/thousands_of_shopping_carts_stake_o.html&#34;&gt;shopping carts all the way down&lt;/a&gt;.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;And here&#39;s a computer storage equivalent: &#xA;look inside &lt;a href=&#34;http://swtch.com/r.zip&#34;&gt;&lt;code&gt;r.zip&lt;/code&gt;&lt;/a&gt;.&#xA;It&#39;s zip files all the way down:&#xA;each one contains another zip file under the name &lt;code&gt;r/r.zip&lt;/code&gt;.&#xA;(For the die-hard Unix fans, &lt;a href=&#34;http://swtch.com/r.tar.gz&#34;&gt;&lt;code&gt;r.tar.gz&lt;/code&gt;&lt;/a&gt; is&#xA;gzipped tar files all the way down.)&#xA;Like the line of shopping carts, it never ends,&#xA;because it loops back onto itself: the zip file contains itself!&#xA;And it&#39;s probably less work to put together a self-reproducing zip file&#xA;than to put together all those shopping carts,&#xA;at least if you&#39;re the kind of person who would read this blog.&#xA;This post explains how.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;Before we get to self-reproducing zip files, though,&#xA;we need to take a brief detour into self-reproducing programs.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Self-reproducing programs&lt;/h3&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;The idea of self-reproducing programs dates back to the 1960s.&#xA;My favorite statement of the problem is the one Ken Thompson gave in his 1983 Turing Award address:&#xA;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;&lt;p class=pp&gt;&#xA;In college, before video games, we would amuse ourselves by posing programming exercises. One of the favorites was to write the shortest self-reproducing program. Since this is an exercise divorced from reality, the usual vehicle was FORTRAN. Actually, FORTRAN was the language of choice for the same reason that three-legged races are popular.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;More precisely stated, the problem is to write a source program that, when compiled and executed, will produce as output an exact copy of its source. If you have never done this, I urge you to try it on your own. The discovery of how to do it is a revelation that far surpasses any benefit obtained by being told how to do it. The part about &amp;ldquo;shortest&amp;rdquo; was just an incentive to demonstrate skill and determine a winner.&#xA;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p class=lp&gt;&#xA;&lt;b&gt;Spoiler alert!&lt;/b&gt;&#xA;I agree: if you have never done this, I urge you to try it on your own.&#xA;The internet
</entry>
<entry>
<title>UTF-8: Bits, Bytes, and Benefits</title>
<id>tag:research.swtch.com,2012:research.swtch.com/utf8</id>
<link rel="alternate" href="http://research.swtch.com/utf8"></link>
<published>2010-03-05T00:00:00-05:00</published>
<updated>2010-03-05T00:00:00-05:00</updated>
<summary type="text">The reasons to switch to UTF-8</summary>
<content type="html">&#xA;&lt;p&gt;&lt;p class=pp&gt;&#xA;UTF-8 is a way to encode Unicode code points&amp;#8212;integer values from&#xA;0 through 10FFFF&amp;#8212;into a byte stream,&#xA;and it is far simpler than many people realize.&#xA;The easiest way to make it confusing or complicated&#xA;is to treat it as a black box, never looking inside.&#xA;So let&#39;s start by looking inside. Here it is:&#xA;&lt;/p&gt;&#xA;&#xA;&lt;center&gt;&#xA;&lt;table cellspacing=5 cellpadding=0 border=0&gt;&#xA;&lt;tr height=10&gt;&lt;th colspan=4&gt;&lt;/th&gt;&lt;/tr&gt;&#xA;&lt;tr&gt;&lt;th align=center colspan=2&gt;Unicode code points&lt;/th&gt;&lt;th width=10&gt;&lt;th align=center&gt;UTF-8 encoding (binary)&lt;/th&gt;&lt;/tr&gt;&#xA;&lt;tr height=10&gt;&lt;td colspan=4&gt;&lt;/td&gt;&lt;/tr&gt;&#xA;&lt;tr&gt;&lt;td align=right&gt;00-7F&lt;/td&gt;&lt;td&gt;(7 bits)&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td align=right&gt;0&lt;i&gt;tuvwxyz&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&#xA;&lt;tr&gt;&lt;td align=right&gt;0080-07FF&lt;/td&gt;&lt;td&gt;(11 bits)&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td align=right&gt;110&lt;i&gt;pqrst&lt;/i&gt;&amp;nbsp;10&lt;i&gt;uvwxyz&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&#xA;&lt;tr&gt;&lt;td align=right&gt;0800-FFFF&lt;/td&gt;&lt;td&gt;(16 bits)&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td align=right&gt;1110&lt;i&gt;jklm&lt;/i&gt;&amp;nbsp;10&lt;i&gt;npqrst&lt;/i&gt;&amp;nbsp;10&lt;i&gt;uvwxyz&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&#xA;&lt;tr&gt;&lt;td align=right valign=top&gt;010000-10FFFF&lt;/td&gt;&lt;td&gt;(21 bits)&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td align=right valign=top&gt;11110&lt;i&gt;efg&lt;/i&gt;&amp;nbsp;10&lt;i&gt;hijklm&lt;/i&gt; 10&lt;i&gt;npqrst&lt;/i&gt;&amp;nbsp;10&lt;i&gt;uvwxyz&lt;/i&gt;&lt;/td&gt;&#xA;&lt;tr height=10&gt;&lt;td colspan=4&gt;&lt;/td&gt;&lt;/tr&gt;&#xA;&lt;/table&gt;&#xA;&lt;/center&gt;&#xA;&#xA;&lt;p class=lp&gt;&#xA;The convenient properties of UTF-8 are all consequences of the choice of encoding.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;i&gt;All ASCII files are already UTF-8 files.&lt;/i&gt;&lt;br&gt;&#xA;The first 128 Unicode code points are the 7-bit ASCII character set,&#xA;and UTF-8 preserves their one-byte encoding.&#xA;&lt;/li&gt;&#xA;&#xA;&lt;li&gt;&lt;i&gt;ASCII bytes always represent themselves in UTF-8 files. They never appear as part of other UTF-8 sequences.&lt;/i&gt;&lt;br&gt;&#xA;All the non-ASCII UTF-8 sequences consist of bytes&#xA;with the high bit set, so if you see the byte 0x7A in a UTF-8 file,&#xA;you can be sure it represents the character &lt;code&gt;z&lt;/code&gt;.&#xA;&lt;/li&gt;&#xA;&#xA;&lt;li&gt;&lt;i&gt;ASCII bytes are always represented as themselves in UTF-8 files. They cannot be hidden inside multibyte UTF-8 sequences.&lt;/i&gt;&lt;br&gt;&#xA;The ASCII &lt;code&gt;z&lt;/code&gt; 01111010 cannot be encoded as a two-byte UTF-8 sequence&#xA;11000001 10111010&lt;/code&gt;. Code points must be encoded using the shortest&#xA;possible sequence.&#xA;A corollary is that decoders must detect long-winded sequences as invalid.&#xA;In practice, it is useful for a decoder to use the Unicode replacement&#xA;character, code point FFFD, as the decoding of an invalid UTF-8 sequence&#xA;rather than stop processing the text.&#xA;&lt;/li&gt;&#xA;&#xA;&lt;li&gt;&lt;i&gt;UTF-8 is self-synchronizing.&lt;/i&gt;&lt;br&gt;&#xA;Let&#39;s call a byte of the form 10&lt;i&gt;xxxxxx&lt;/i&gt;&#xA;a continuation byte.&#xA;Every UTF-8 sequence is a byte that is not a continuation byte&#xA;followed by zero or more continuation bytes.&#xA;If you start processing a UTF-8 file at an arbitrary point,&#xA;you might not be at the beginning of a UTF-8 encoding,&#xA;but you can easily find one: skip over&#xA;continuation bytes until you find a non-continuation byte.&#xA;(The same applies to scanning backward.)&#xA;&lt;/li&gt;&#xA;&#xA;&lt;li&gt;&lt;i&gt;Substring search is just byte string search.&lt;/i&gt;&lt;br&gt;&#xA;Properties 2, 3, and 4 imply that given a string&#xA;of correctly encoded UTF-8, the only way those bytes&#xA;can appear in a larger UTF-8 text is when they represent
</entry>
<entry>
<title>Computing History at Bell Labs</title>
<id>tag:research.swtch.com,2012:research.swtch.com/bell-labs</id>
<link rel="alternate" href="http://research.swtch.com/bell-labs"></link>
<published>2008-04-09T00:00:00-04:00</published>
<updated>2008-04-09T00:00:00-04:00</updated>
<summary type="text">Doug McIlroy&#39;s rememberances</summary>
<content type="html">&#xA;&lt;p&gt;&lt;p class=pp&gt;&#xA;In 1997, on his retirement from Bell Labs, &lt;a href=&#34;http://www.cs.dartmouth.edu/~doug/&#34;&gt;Doug McIlroy&lt;/a&gt; gave a&#xA;fascinating talk about the &amp;ldquo;&lt;a href=&#34;https://web.archive.org/web/20081022192943/http://cm.bell-labs.com/cm/cs/doug97.html&#34;&gt;&lt;b&gt;History of Computing at Bell Labs&lt;/b&gt;&lt;/a&gt;.&amp;rdquo;&#xA;Almost ten years ago I transcribed the audio but never did anything with it.&#xA;The transcript is below.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;My favorite parts of the talk are the description of the bi-quinary decimal relay calculator&#xA;and the description of a team that spent over a year tracking down a race condition bug in&#xA;a missile detector (reliability was king: today you&#39;d just stamp&#xA;&amp;ldquo;cannot reproduce&amp;rdquo; and send the report back).&#xA;But the whole thing contains many fantastic stories.&#xA;It&#39;s well worth the read or listen.&#xA;I also like his recollection of programming using cards: &amp;ldquo;It&#39;s the kind of thing you can be nostalgic about, but it wasn&#39;t actually fun.&amp;rdquo;&#xA;&lt;/p&gt;&#xA;&#xA;&#xA;&lt;p class=pp&gt;&#xA;For more information, Bernard D. Holbrook and W. Stanley Brown&#39;s 1982&#xA;technical report&#xA;&#xA;&amp;ldquo;&lt;a href=&#34;cstr99.pdf&#34;&gt;A History of Computing Research at Bell Laboratories (1937-1975)&lt;/a&gt;&amp;rdquo;&#xA;covers the earlier history in more detail.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;i&gt;Corrections added August 19, 2009. Links updated May 16, 2018.&lt;/i&gt;&lt;/p&gt;&#xA;&#xA;&lt;br&gt;&#xA;&lt;br&gt;&#xA;&#xA;&lt;p class=lp&gt;&lt;i&gt;Transcript of &amp;ldquo;&lt;a href=&#34;https://web.archive.org/web/20081022192943/http://cm.bell-labs.com/cm/cs/doug97.html&#34;&gt;History of Computing at Bell Labs:&lt;/a&gt;&amp;rdquo;&lt;/i&gt;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;Computing at Bell Labs is certainly an outgrowth of the&#xA;&lt;a href=&#34;https://web.archive.org/web/20080622172015/http://cm.bell-labs.com/cm/ms/history/history.html&#34;&gt;mathematics department&lt;/a&gt;, which grew from that first hiring&#xA;in 1897, G A Campbell. When Bell Labs was formally founded&#xA;in 1925, what it had been was the engineering department&#xA;of Western Electric.&#xA;When it was formally founded in 1925,&#xA;almost from the beginning there was a math department with Thornton Fry as the department head, and if you look at some of Fry&#39;s work, it turns out that&#xA;he was fussing around in 1929 with trying to discover&#xA;information theory. It didn&#39;t actually gel until twenty years later with Shannon.&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&lt;span style=&#34;font-size: 0.7em;&#34;&gt;1:10&lt;/span&gt;&#xA;Of course, most of the mathematics at that time was continuous.&#xA;One was interested in analyzing circuits and propagation. And indeed, this is what led to the growth of computing in Bell Laboratories. The computations could not all be done symbolically. There were not closed form solutions. There was lots of numerical computation done.&#xA;The math department had a fair stable of computers,&#xA;which in those days meant people. [laughter]&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&lt;span style=&#34;font-size: 0.7em;&#34;&gt;2:00&lt;/span&gt;&#xA;And in the late &#39;30s, &lt;a href=&#34;http://en.wikipedia.org/wiki/George_Stibitz&#34;&gt;George Stibitz&lt;/a&gt; had an idea that some of&#xA;the work that they were doing on hand calculators might be&#xA;automated by using some of the equipment that the Bell System&#xA;was installing in central offices, namely relay circuits.&#xA;He went home, and on his kitchen table, he built out of relays&#xA;a binary arithmetic circuit. He decided that binary was really&#xA;the right way to compute.&#xA;However, when he finally came to build some equipment,&#xA;he determined that binary to decimal conversion and&#xA;decimal to binary conversion was a drag, and he didn&#39;t&#xA;want to put it in the equipment, and so he finally bu
</entry>
<entry>
<title>Using Uninitialized Memory for Fun and Profit</title>
<id>tag:research.swtch.com,2012:research.swtch.com/sparse</id>
<link rel="alternate" href="http://research.swtch.com/sparse"></link>
<published>2008-03-14T00:00:00-04:00</published>
<updated>2008-03-14T00:00:00-04:00</updated>
<summary type="text">An unusual but very useful data structure</summary>
<content type="html">&#xA;&lt;p&gt;&lt;p class=lp&gt;&#xA;This is the story of a clever trick that&#39;s been around for&#xA;at least 35 years, in which array values can be left&#xA;uninitialized and then read during normal operations,&#xA;yet the code behaves correctly no matter what garbage&#xA;is sitting in the array.&#xA;Like the best programming tricks, this one is the right tool for the &#xA;job in certain situations.&#xA;The sleaziness of uninitialized data&#xA;access is offset by performance improvements:&#xA;some important operations change from linear &#xA;to constant time.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;Alfred Aho, John Hopcroft, and Jeffrey Ullman&#39;s 1974 book &#xA;&lt;i&gt;The Design and Analysis of Computer Algorithms&lt;/i&gt;&#xA;hints at the trick in an exercise (Chapter 2, exercise 2.12):&#xA;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;Develop a technique to initialize an entry of a matrix to zero&#xA;the first time it is accessed, thereby eliminating the &lt;i&gt;O&lt;/i&gt;(||&lt;i&gt;V&lt;/i&gt;||&lt;sup&gt;2&lt;/sup&gt;) time&#xA;to initialize an adjacency matrix.&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p class=lp&gt;&#xA;Jon Bentley&#39;s 1986 book &lt;a href=&#34;http://www.cs.bell-labs.com/cm/cs/pearls/&#34;&gt;&lt;i&gt;Programming Pearls&lt;/i&gt;&lt;/a&gt; expands&#xA;on the exercise (Column 1, exercise 8; &lt;a href=&#34;http://www.cs.bell-labs.com/cm/cs/pearls/sec016.html&#34;&gt;exercise 9&lt;/a&gt; in the Second Edition):&#xA;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;One problem with trading more space for less time is that &#xA;initializing the space can itself take a great deal of time.&#xA;Show how to circumvent this problem by designing a technique&#xA;to initialize an entry of a vector to zero the first time it is&#xA;accessed. Your scheme should use constant time for initialization&#xA;and each vector access; you may use extra space proportional&#xA;to the size of the vector. Because this method reduces &#xA;initialization time by using even more space, it should be&#xA;considered only when space is cheap, time is dear, and &#xA;the vector is sparse.&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p class=lp&gt;&#xA;Aho, Hopcroft, and Ullman&#39;s exercise talks about a matrix and &#xA;Bentley&#39;s exercise talks about a vector, but for now let&#39;s consider&#xA;just a simple set of integers.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;One popular representation of a set of &lt;i&gt;n&lt;/i&gt; integers ranging&#xA;from 0 to &lt;i&gt;m&lt;/i&gt; is a bit vector, with 1 bits at the&#xA;positions corresponding to the integers in the set.&#xA;Adding a new integer to the set, removing an integer&#xA;from the set, and checking whether a particular integer&#xA;is in the set are all very fast constant-time operations&#xA;(just a few bit operations each).&#xA;Unfortunately, two important operations are slow:&#xA;iterating over all the elements in the set &#xA;takes time &lt;i&gt;O&lt;/i&gt;(&lt;i&gt;m&lt;/i&gt;), as does clearing the set.&#xA;If the common case is that &#xA;&lt;i&gt;m&lt;/i&gt; is much larger than &lt;i&gt;n&lt;/i&gt;&#xA;(that is, the set is only sparsely&#xA;populated) and iterating or clearing the set &#xA;happens frequently, then it could be better to&#xA;use a representation that makes those operations&#xA;more efficient. That&#39;s where the trick comes in.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;Preston Briggs and Linda Torczon&#39;s 1993 paper,&#xA;&amp;ldquo;&lt;a href=&#34;http://citeseer.ist.psu.edu/briggs93efficient.html&#34;&gt;&lt;b&gt;An Efficient Representation for Sparse Sets&lt;/b&gt;&lt;/a&gt;,&amp;rdquo;&#xA;describes the trick in detail.&#xA;Their solution represents the sparse set using an integer&#xA;array named &lt;code&gt;dense&lt;/code&gt; and an integer &lt;code&gt;n&lt;/code&gt;&#xA;that counts the number of elements in &lt;code&gt;dense&lt;/code&gt;.&#xA;The &lt;i&gt;dense&lt;/i&gt; array is simply a packed list of the elements in the&#xA;set, stored in order of insertion.&#xA;If the set contains the elements 5, 1, and 4,
</entry>
<entry>
<title>Play Tic-Tac-Toe with Knuth</title>
<id>tag:research.swtch.com,2012:research.swtch.com/tictactoe</id>
<link rel="alternate" href="http://research.swtch.com/tictactoe"></link>
<published>2008-01-25T00:00:00-05:00</published>
<updated>2008-01-25T00:00:00-05:00</updated>
<summary type="text">The only winning move is not to play.</summary>
<content type="html">&#xA;&lt;p&gt;&lt;p class=lp&gt;Section 7.1.2 of the &lt;b&gt;&lt;a href=&#34;http://www-cs-faculty.stanford.edu/~knuth/taocp.html#vol4&#34;&gt;Volume 4 pre-fascicle 0A&lt;/a&gt;&lt;/b&gt; of Donald Knuth&#39;s &lt;i&gt;The Art of Computer Programming&lt;/i&gt; is titled &amp;#8220;Boolean Evaluation.&amp;#8221; In it, Knuth considers the construction of a set of nine boolean functions telling the correct next move in an optimal game of tic-tac-toe. In a footnote, Knuth tells this story:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&lt;p class=lp&gt;This setup is based on an exhibit from the early 1950s at the Museum of Science and Industry in Chicago, where the author was first introduced to the magic of switching circuits. The machine in Chicago, designed by researchers at Bell Telephone Laboratories, allowed me to go first; yet I soon discovered there was no way to defeat it. Therefore I decided to move as stupidly as possible, hoping that the designers had not anticipated such bizarre behavior. In fact I allowed the machine to reach a position where it had two winning moves; and it seized &lt;i&gt;both&lt;/i&gt; of them! Moving twice is of course a flagrant violation of the rules, so I had won a moral victory even though the machine had announced that I had lost.&lt;/p&gt;&lt;/blockquote&gt;&#xA;&#xA;&lt;p class=lp&gt;&#xA;That story alone is fairly amusing. But turning the page, the reader finds a quotation from Charles Babbage&#39;s &lt;i&gt;&lt;a href=&#34;http://onlinebooks.library.upenn.edu/webbin/book/lookupid?key=olbp36384&#34;&gt;Passages from the Life of a Philosopher&lt;/a&gt;&lt;/i&gt;, published in 1864:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&lt;p class=lp&gt;I commenced an examination of a game called &amp;#8220;tit-tat-to&amp;#8221; ... to ascertain what number of combinations were required for all the possible variety of moves and situations. I found this to be comparatively insignificant. ... A difficulty, however, arose of a novel kind. When the automaton had to move, it might occur that there were two different moves, each equally conducive to his winning the game. ... Unless, also, some provision were made, the machine would attempt two contradictory motions.&lt;/p&gt;&lt;/blockquote&gt;&#xA;&#xA;&lt;p class=lp&gt;&#xA;The only real winning move is not to play.&lt;/p&gt;&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;</content>
</entry>
<entry>
<title>Crabs, the bitmap terror!</title>
<id>tag:research.swtch.com,2012:research.swtch.com/crabs</id>
<link rel="alternate" href="http://research.swtch.com/crabs"></link>
<published>2008-01-09T00:00:00-05:00</published>
<updated>2008-01-09T00:00:00-05:00</updated>
<summary type="text">A destructive, pointless violation of the rules</summary>
<content type="html">&#xA;&lt;p&gt;&lt;p class=lp&gt;Today, window systems seem as inevitable as hierarchical file systems, a fundamental building block of computer systems. But it wasn&#39;t always that way. This paper could only have been written in the beginning, when everything about user interfaces was up for grabs.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&lt;p class=lp&gt;A bitmap screen is a graphic universe where windows, cursors and icons live in harmony, cooperating with each other to achieve functionality and esthetics. A lot of effort goes into making this universe consistent, the basic law being that every window is a self contained, protected world. In particular, (1) a window shall not be affected by the internal activities of another window. (2) A window shall not be affected by activities of the window system not concerning it directly, i.e. (2.1) it shall not notice being obscured (partially or totally) by other windows or obscuring (partially or totally) other windows, (2.2) it shall not see the &lt;i&gt;image&lt;/i&gt; of the cursor sliding on its surface (it can only ask for its position).&lt;/p&gt;&#xA;&#xA;&lt;p class=pp&gt;&#xA;Of course it is difficult to resist the temptation to break these rules. Violations can be destructive or non-destructive, useful or pointless. Useful non-destructive violations include programs printing out an image of the screen, or magnifying part of the screen in a &lt;i&gt;lens&lt;/i&gt; window. Useful destructive violations are represented by the &lt;i&gt;pen&lt;/i&gt; program, which allows one to scribble on the screen. Pointless non-destructive violations include a magnet program, where a moving picture of a magnet attracts the cursor, so that one has to continuously pull away from it to keep working. The first pointless, destructive program we wrote was &lt;i&gt;crabs&lt;/i&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p class=lp&gt;As the crabs walk over the screen, they leave gray behind, &amp;#8220;erasing&amp;#8221; the apps underfoot:&lt;/p&gt;&#xA;&lt;blockquote&gt;&lt;img src=&#34;http://research.swtch.com/crabs1.png&#34;&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p class=lp&gt;&#xA;For the rest of the story, see Luca Cardelli&#39;s &amp;#8220;&lt;a style=&#34;font-weight: bold;&#34; href=&#34;http://lucacardelli.name/Papers/Crabs.pdf&#34;&gt;Crabs: the bitmap terror!&lt;/a&gt;&amp;#8221; (6.7MB). Additional details in &amp;#8220;&lt;a href=&#34;http://lucacardelli.name/Papers/Crabs%20%28History%20and%20Screen%20Dumps%29.pdf&#34;&gt;Crabs (History and Screen Dumps)&lt;/a&gt;&amp;#8221; (57.1MB).&lt;/p&gt;&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;</content>
</entry>
</feed>