Debian Codegraph @

_benchmarks/sample_blogpost.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="UTF-8">
5 <title>research!rsc: My Go Resolutions for 2017</title>
6 <link rel="alternate" type="application/atom+xml" title="research!rsc - Atom" href="http://research.swtch.com/feed.atom" />
7
8 <link href='https://fonts.googleapis.com/css?family=Inconsolata:400,700' rel='stylesheet' type='text/css'>
9 <script type="text/javascript" src="https://use.typekit.com/skm6yij.js"></script>
10 <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
11 <style>
12 body {
13 padding: 0;
14 margin: 0;
15 font-size: 100%;
16 }
17 .header {
18 height: 1.25em;
19 background-color: #dff;
20 margin: 0;
21 padding: 0.1em 0.1em 0.2em;
22 border-top: 1px solid black;
23 border-bottom: 1px solid #8ff;
24 }
25 .header h3 {
26 margin: 0;
27 padding: 0 2em;
28 display: inline-block;
29 padding-right: 2em;
30 font-style: italic;
31 font-family: "adobe-text-pro" !important;
32 font-size: 90%;
33 }
34 .rss {
35 float: right;
36 padding-top: 0.2em;
37 padding-right: 2em;
38 display: none;
39 }
40 .toc {
41 margin-top: 2em;
42 }
43 .toc-title {
44 font-family: "caflisch-script-pro";
45 font-size: 300%;
46 line-height: 50%;
47 }
48 .toc-subtitle {
49 display: block;
50 margin-bottom: 1em;
51 font-size: 83%;
52 }
53 @media only screen and (max-width: 550px) { .toc-subtitle { display: none; } }
54 .header h3 a {
55 color: black;
56 }
57 .header h4 {
58 margin: 0;
59 padding: 0;
60 display: inline-block;
61 font-weight: normal;
62 font-size: 83%;
63 }
64 @media only screen and (max-width: 550px) { .header h4 { display: none; } }
65 .main {
66 padding: 0 2em;
67 }
68 @media only screen and (max-width: 479px) { .article { font-size: 120%; } }
69 .article h1 {
70 text-align: center;
71 }
72 .article h1, .article h2, .article h3 {
73 font-family: 'Myriad Pro';
74 }
75 .normal {
76 font-size: medium;
77 font-weight: normal;
78 }
79 .when {
80 text-align: center;
81 font-size: 100%;
82 margin: 0;
83 padding: 0;
84 }
85 .when p {
86 margin: 0;
87 padding: 0;
88 }
89 .article h2 {
90 font-size: 100%;
91 padding-top: 0.25em;
92 }
93 pre {
94 margin-left: 4em;
95 margin-right: 4em;
96 }
97 pre, code {
98 font-family: 'Inconsolata', monospace;
99 font-size: 100%;
100 }
101 .footer {
102 margin-top: 10px;
103 font-size: 83%;
104 font-family: sans-serif;
105 }
106 .comments {
107 margin-top: 2em;
108 background-color: #ffe;
109 border-top: 1px solid #aa4;
110 border-left: 1px solid #aa4;
111 border-right: 1px solid #aa4;
112 }
113 .comments-header {
114 padding: 0 5px 0 5px;
115 }
116 .comments-header p {
117 padding: 0;
118 margin: 3px 0 0 0;
119 }
120 .comments-body {
121 padding: 5px 5px 5px 5px;
122 }
123 #plus-comments {
124 border-bottom: 1px dotted #ccc;
125 }
126 .plus-comment {
127 width: 100%;
128 font-size: 14px;
129 border-top: 1px dotted #ccc;
130 }
131 .me {
132 background-color: #eec;
133 }
134 .plus-comment ul {
135 margin: 0;
136 padding: 0;
137 list-style: none;
138 width: 100%;
139 display: inline-block;
140 }
141 .comment-when {
142 color:#999;
143 width:auto;
144 padding:0 5px;
145 }
146 .old {
147 font-size: 83%;
148 }
149 .plus-comment ul li {
150 display: inline-block;
151 vertical-align: top;
152 margin-top: 5px;
153 margin-bottom: 5px;
154 padding: 0;
155 }
156 .plus-icon {
157 width: 45px;
158 }
159 .plus-img {
160 float: left;
161 margin: 4px 4px 4px 4px;
162 width: 32px;
163 height: 32px;
164 }
165 .plus-comment p {
166 margin: 0;
167 padding: 0;
168 }
169 .plus-clear {
170 clear: left;
171 }
172 .toc-when {
173 font-size: 83%;
174 color: #ccc;
175 }
176 .toc {
177 list-style: none;
178 }
179 .toc li {
180 margin-bottom: 0.5em;
181 }
182 .toc-head {
183 margin-bottom: 1em !important;
184 font-size: 117%;
185 }
186 .toc-summary {
187 margin-left: 2em;
188 }
189 .favorite {
190 font-weight: bold;
191 }
192 .article p {
193 line-height: 144%;
194 }
195 sup, sub {
196 vertical-align: baseline;
197 position: relative;
198 font-size: 83%;
199 }
200 sup {
201 bottom: 1ex;
202 }
203 sub {
204 top: 0.8ex;
205 }
206
207 .main {
208 position: relative;
209 margin: 0 auto;
210 padding: 0;
211 width: 900px;
212 }
213 @media only screen and (min-width: 768px) and (max-width: 959px) { .main { width: 708px; } }
214 @media only screen and (min-width: 640px) and (max-width: 767px) { .main { width: 580px; } }
215 @media only screen and (min-width: 480px) and (max-width: 639px) { .main { width: 420px; } }
216 @media only screen and (max-width: 479px) { .main { width: 300px; } }
217
218 </style>
219
220 </head>
221 <body>
222
223 <div class="header">
224 <h3><a href="/">research!rsc</a></h3>
225 <h4>Thoughts and links about programming,
226 by <a href="https://swtch.com/~rsc/" rel="author">Russ Cox</a> </h4>
227 <a class="rss" href="/feed.atom"><img src="/feed-icon-14x14.png" /></a>
228 </div>
229
230 <div class="main">
231 <div class="article">
232 <h1>My Go Resolutions for 2017
233 <div class="normal">
234 <div class="when">
235
236 Posted on Wednesday, January 18, 2017.
237
238
239 </div>
240 </div>
241 </h1>
242 <p class=lp>’Tis the season for resolutions,
243 and I thought it would make sense to write a little
244 about what I hope to work on this year as far as Go is concerned.</p>
245
246 <p class=pp>My goal every year is to <em>help Go developers</em>.
247 I want to make sure that the work we do on the Go team
248 has a significant, positive impact on Go developers.
249 That may sound obvious, but there are a variety of common ways to fail to achieve that:
250 for example, spending too much time cleaning up or optimizing code that doesn’t need it;
251 responding only to the most common or recent complaints or requests;
252 or focusing too much on short-term improvements.
253 It’s important to step back and make sure we’re focusing
254 our development work where it does the most good.</p>
255
256 <p class=pp>This post outlines a few of my own major focuses for this year.
257 This is only my personal list, not the Go team’s list.</p>
258
259 <p class=pp>One reason for posting this is to gather feedback.
260 If these spark any ideas or suggestions of your own,
261 please feel free to comment below or on the linked GitHub issues.</p>
262
263 <p class=pp>Another reason is to make clear that I’m aware of these issues as important.
264 I think too often people interpret lack of action by the Go team
265 as a signal that we think everything is perfect, when instead
266 there is simply other, higher priority work to do first.</p>
267
268 <h2><a name="alias"></a>Type aliases</h2>
269
270 <p class=lp>There is a recurring problem with moving types
271 from one package to another during large codebase refactorings.
272 We tried to solve it last year with <a href="https://golang.org/issue/16339">general aliases</a>,
273 which didn’t work for at least two reasons: we didn’t explain the change well enough,
274 and we didn’t deliver it on time, so it wasn’t ready for Go 1.8.
275 Learning from that experience,
276 I <a href="https://www.youtube.com/watch?v=h6Cw9iCDVcU">gave a talk</a>
277 and <a href="https://talks.golang.org/2016/refactor.article">wrote an article</a>
278 about the underlying problem,
279 and that started a <a href="https://golang.org/issue/18130">productive discussion</a>
280 on the Go issue tracker about the solution space.
281 It looks like more limited <a href="https://golang.org/design/18130-type-alias">type aliases</a>
282 are the right next step.
283 I want to make sure those land smoothly in Go 1.9. <a href="https://golang.org/issue/18130">#18130</a>.</p>
284
285 <h2><a name="package"></a>Package management</h2>
286
287 <p class=lp>I designed the Go support for downloading published packages
288 (“goinstall”, which became “go get”) in February 2010.
289 A lot has happened since then.
290 In particular, other language ecosystems have really raised the bar
291 for what people expect from package management,
292 and the open source world has mostly agreed on
293 <a href="http://semver.org/">semantic versioning</a>, which provides a useful base
294 for inferring version compatibility.
295 Go needs to do better here, and a group of contributors have been
296 <a href="https://blog.gopheracademy.com/advent-2016/saga-go-dependency-management/">working on a solution</a>.
297 I want to make sure these ideas are integrated well
298 into the standard Go toolchain and to make package management
299 a reason that people love Go.</p>
300
301 <h2><a name="build"></a>Build improvements</h2>
302
303 <p class=lp>There are a handful of shortcomings in the design of
304 the go command’s build system that are overdue to be fixed.
305 Here are three representative examples that I intend to
306 address with a bit of a redesign of the internals of the go command.</p>
307
308 <p class=pp>Builds can be too slow,
309 because the go command doesn’t cache build results as aggressively as it should.
310 Many people don’t realize that <code>go</code> <code>install</code> saves its work while <code>go</code> <code>build</code> does not,
311 and then they run repeated <code>go</code> <code>build</code> commands that are slow
312 because the later builds do more work than they should need to.
313 The same for repeated <code>go</code> <code>test</code> without <code>go</code> <code>test</code> <code>-i</code> when dependencies are modified.
314 All builds should be as incremental as possible.
315 <a href="https://golang.org/issue/4719">#4719</a>.</p>
316
317 <p class=pp>Test results should be cached too:
318 if none of the inputs to a test have changed,
319 then usually there is no need to rerun the test.
320 This will make it very cheap to run “all tests” when little or nothing has changed.
321 <a href="https://golang.org/issue/11193">#11193</a>.</p>
322
323 <p class=pp>Work outside GOPATH should be supported nearly as well
324 as work inside GOPATH.
325 In particular, it should be possible to <code>git</code> <code>clone</code> a repo,
326 <code>cd</code> into it, and run <code>go</code> commands and have them work fine.
327 Package management only makes that more important:
328 you’ll need to be able to work on different versions of a package (say, v1 and v2)
329 without having entirely separate GOPATHs for them.
330 <a href="https://golang.org/issue/17271">#17271</a>.</p>
331
332 <h2><a name="corpus"></a>Code corpus</h2>
333
334 <p class=lp>I think it helped to have concrete examples from real projects
335 in the talk and article I prepared about codebase refactoring (see <a href="#alias">above</a>).
336 We&rsquo;ve also defined that <a href="https://golang.org/src/cmd/vet/README">additions to vet</a>
337 must target problems that happen frequently in real programs.
338 I&rsquo;d like to see that kind of analysis of actual practice—examining
339 the effects on and possible improvements to real programs—become a
340 standard way we discuss and evaluate changes to Go.</p>
341
342 <p class=pp>Right now there&rsquo;s not an agreed-upon representative corpus of code to use for
343 those analyses: everyone must first create their own, which is too much work.
344 I&rsquo;d like to put together a single, self-contained Git repo people can check out that
345 contains our official baseline corpus for those analyses.
346 A possible starting point could be the top 100 Go language repos
347 on GitHub by stars or forks or both.</p>
348
349 <h2><a name="vet"></a>Automatic vet</h2>
350
351 <p class=lp>The Go distribution ships with this powerful tool,
352 <a href="https://golang.org/cmd/vet/"><code>go</code> <code>vet</code></a>,
353 that points out correctness bugs.
354 We have a high bar for checks, so that when vet speaks, you should listen.
355 But everyone has to remember to run it.
356 It would be better if you didn’t have to remember.
357 In particular, I think we could probably run vet
358 in parallel with the final compile and link of the test binary
359 during <code>go</code> <code>test</code> without slowing the compile-edit-test cycle at all.
360 If we can do that, and if we limit the enabled vet checks to a subset
361 that is essentially 100% accurate,
362 we can make passing vet a precondition for running a test at all.
363 Then developers don’t need to remember to run <code>go</code> <code>vet</code>.
364 They run <code>go</code> <code>test</code>,
365 and once in a while vet speaks up with something important
366 and avoids a debugging session.
367 <a href="https://golang.org/issue/18084">#18084</a>,
368 <a href="https://golang.org/issue/18085">#18085</a>.</p>
369
370 <h2><a name="error"></a>Errors &amp; best practices</h2>
371
372 <p class=lp>Part of the intended contract for error reporting in Go is that functions
373 include relevant available context, including the operation being attempted
374 (such as the function name and its arguments).
375 For example, this program:</p>
376
377 <pre><code>err := os.Remove(&quot;/tmp/nonexist&quot;)
378 fmt.Println(err)
379 </code></pre>
380
381 <p class=lp>prints this output:</p>
382
383 <pre><code>remove /tmp/nonexist: no such file or directory
384 </code></pre>
385
386 <p class=lp>Not enough Go code adds context like <code>os.Remove</code> does. Too much code does only</p>
387
388 <pre><code>if err != nil {
389 return err
390 }
391 </code></pre>
392
393 <p class=lp>all the way up the call stack,
394 discarding useful context that should be reported
395 (like <code>remove</code> <code>/tmp/nonexist:</code> above).
396 I would like to try to understand whether our expectations
397 for including context are wrong, or if there is something
398 we can do to make it easier to write code that returns better errors.</p>
399
400 <p class=pp>There are also various discussions in the community about
401 agreed-upon interfaces for stripping error context.
402 I would like to try to understand when that makes sense and
403 whether we should adopt an official recommendation.</p>
404
405 <h2><a name="context"></a>Context &amp; best practices</h2>
406
407 <p class=lp>We added the new <a href="https://golang.org/pkg/context/">context package</a>
408 in Go 1.7 for holding request-scoped information like
409 <a href="https://blog.golang.org/context">timeouts, cancellation state, and credentials</a>.
410 An individual context is immutable (like an individual string or int):
411 it is only possible to derive a new, updated context and
412 pass that context explicitly further down the call stack or
413 (less commonly) back up to the caller.
414 The context is now carried through APIs such as
415 <a href="https://golang.org/pkg/database/sql">database/sql</a>
416 and
417 <a href="https://golang.org/pkg/net/http">net/http</a>,
418 mainly so that those can stop processing a request when the caller
419 is no longer interested in the result.
420 Timeout information is appropriate to carry in a context,
421 but—to use a <a href="https://golang.org/issue/18284">real example we removed</a>—database options
422 are not, because they are unlikely to apply equally well to all possible
423 database operations carried out during a request.
424 What about the current clock source, or logging sink?
425 Is either of those appropriate to store in a context?
426 I would like to try to understand and characterize the
427 criteria for what is and is not an appropriate use of context.</p>
428
429 <h2><a name="memory"></a>Memory model</h2>
430
431 <p class=lp>Go’s <a href="https://golang.org/ref/mem">memory model</a> is intentionally low-key,
432 making few promises to users, compared to other languages.
433 In fact it starts by discouraging people from reading the rest of the document.
434 At the same time, it demands more of the compiler than other languages:
435 in particular, a race on an integer value is not sufficient license
436 for your program to misbehave in arbitrary ways.
437 But there are some complete gaps, in particular no mention of
438 the <a href="https://golang.org/pkg/sync/atomic/">sync/atomic package</a>.
439 I think the core compiler and runtime developers all agree
440 that the behavior of those atomics should be roughly the same as
441 C++ seqcst atomics or Java volatiles,
442 but we still need to write that down carefully in the memory model,
443 and probably also in a long blog post.
444 <a href="https://golang.org/issue/5045">#5045</a>,
445 <a href="https://golang.org/issue/7948">#7948</a>,
446 <a href="https://golang.org/issue/9442">#9442</a>.</p>
447
448 <h2><a name="immutability"></a>Immutability</h2>
449
450 <p class=lp>The <a href="https://golang.org/doc/articles/race_detector.html">race detector</a>
451 is one of Go’s most loved features.
452 But not having races would be even better.
453 I would love it if there were some reasonable way to integrate
454 <a href="https://www.google.com/search?q=%22reference+immutability%22">reference immutability</a> into Go,
455 so that programmers can make clear, checked assertions about what can and cannot
456 be written and thereby eliminate certain races at compile time.
457 Go already has one immutable type, <code>string</code>; it would
458 be nice to retroactively define that
459 <code>string</code> is a named type (or type alias) for <code>immutable</code> <code>[]byte</code>.
460 I don’t think that will happen this year,
461 but I’d like to understand the solution space better.
462 Javari, Midori, Pony, and Rust have all staked out interesting points
463 in the solution space, and there are plenty of research papers
464 beyond those.</p>
465
466 <p class=pp>In the long-term, if we could statically eliminate the possibility of races,
467 that would eliminate the need for most of the memory model.
468 That may well be an impossible dream,
469 but again I’d like to understand the solution space better.</p>
470
471 <h2><a name="generics"></a>Generics</h2>
472
473 <p class=lp>Nothing sparks more <a href="https://research.swtch.com/dogma">heated arguments</a>
474 among Go and non-Go developers than the question of whether Go should
475 have support for generics (or how many years ago that should have happened).
476 I don’t believe the Go team has ever said “Go does not need generics.”
477 What we <em>have</em> said is that there are higher-priority issues facing Go.
478 For example, I believe that better support for package management
479 would have a much larger immediate positive impact on most Go developers
480 than adding generics.
481 But we do certainly understand that for a certain subset of Go use cases,
482 the lack of parametric polymorphism is a significant hindrance.</p>
483
484 <p class=pp>Personally, I would like to be able to write general channel-processing
485 functions like:</p>
486
487 <pre><code>// Join makes all messages received on the input channels
488 // available for receiving from the returned channel.
489 func Join(inputs ...&lt;-chan T) &lt;-chan T
490
491 // Dup duplicates messages received on c to both c1 and c2.
492 func Dup(c &lt;-chan T) (c1, c2 &lt;-chan T)
493 </code></pre>
494
495 <p class=lp>I would also like to be able to write
496 Go support for high-level data processing abstractions,
497 analogous to
498 <a href="https://research.google.com/pubs/archive/35650.pdf">FlumeJava</a> or
499 C#’s <a href="https://en.wikipedia.org/wiki/Language_Integrated_Query">LINQ</a>,
500 in a way that catches type errors at compile time instead of at run time.
501 There are also any number of data structures or generic algorithms
502 that might be written,
503 but I personally find these broader applications more compelling.</p>
504
505 <p class=pp>We’ve <a href="https://research.swtch.com/generic">struggled</a> off and on
506 <a href="https://golang.org/design/15292-generics">for years</a>
507 to find the right way to add generics to Go.
508 At least a few of the past proposals got hung up on trying to design
509 something that provided both general parametric polymorphism
510 (like <code>chan</code> <code>T</code>) and also a unification of <code>string</code> and <code>[]byte</code>.
511 If the latter is handled by parameterization over immutability,
512 as described in the previous section, then maybe that simplifies
513 the demands on a design for generics.</p>
514
515 <p class=pp>When I first started thinking about generics for Go in 2008,
516 the main examples to learn from were C#, Java, Haskell, and ML.
517 None of the approaches in those languages seemed like a
518 perfect fit for Go.
519 Today, there are newer attempts to learn from as well,
520 including Dart, Midori, Rust, and Swift.</p>
521
522 <p class=pp>It’s been a few years since we ventured out and explored the design space.
523 It is probably time to look around again,
524 especially in light of the insight about mutability and
525 the additional examples set by newer languages.
526 I don’t think generics will happen this year,
527 but I’d like to be able to say I understand the solution space better.</p>
528
529 </div>
530
531
532 <div id="disqus_thread"></div>
533 <script>
534 var disqus_config = function () {
535 this.page.url = "https://research.swtch.com/go2017";
536 this.page.identifier = "blog/go2017";
537 };
538 (function() {
539 var d = document, s = d.createElement('script');
540 s.src = '//swtch.disqus.com/embed.js';
541 s.setAttribute('data-timestamp', +new Date());
542 (d.head || d.body).appendChild(s);
543 })();
544 </script>
545 <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
546 </div>
547
548 </div>
549
550
551 <script type="text/javascript">
552 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
553 document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
554 </script>
555 <script type="text/javascript">
556 var pageTracker = _gat._getTracker("UA-3319603-2");
557 pageTracker._initData();
558 pageTracker._trackPageview();
559 </script>
560
561
562
563 </body>
564 </html>
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580