LWN: Comments on "Testable Examples in Go" https://lwn.net/Articles/643726/ This is a special feed containing comments posted to the individual LWN article titled "Testable Examples in Go". en-us Sun, 05 Oct 2025 12:13:59 +0000 Sun, 05 Oct 2025 12:13:59 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net Testable Examples in Go https://lwn.net/Articles/643994/ https://lwn.net/Articles/643994/ kloczek <div class="FormattedComment"> <font class="QuotedText">&gt; The much simpler approach of having regularly-compiled / regression tested examples in the same directory as the documentation is probably more my speed.</font><br> <p> $ make all<br> $ make check<br> <p> ??<br> </div> Tue, 12 May 2015 11:26:08 +0000 Testable Examples in Go https://lwn.net/Articles/643963/ https://lwn.net/Articles/643963/ jzbiciak <P>Not to mention Donald Knuth's <I>literate programming</I> which goes a step further. He apparently developed that in the late 70s, with WEB debuting publicly in 1981.</P> <P>I have mixed emotions about literate programming personally, in as much as you need to understand both the language you're programming and the documentation markup in parallel, along with the non-linearity it enables. By non-linearity, I mean that a literate program allows you to write your program in a different order than the original programming language requires. While that can be liberating I suppose, allowing you to express your program in the order that makes the most cognitive sense to <I>you</I>, as opposed to the compiler, you're still programming in a third language that's neither the language of the program's compiler nor the language of the documentation markup.</P> <P>Literate programming was invented and leveraged heavily by someone much smarter than I, and at times I think it requires that level of intelligence (or at least a level above mine) to use effectively. Either that, or I haven't really given it the chance it deserves. Perhaps if someone invented a programming language which was literate from the ground up...</P> <P>The much simpler approach of having regularly-compiled / regression tested examples in the same directory as the documentation is probably more my speed. As Kernighan once said, “Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?” So, if I do anything while documenting a programming environment, you'll catch me leaving liberal example programs around with text to describe and dissect them out-of-band.</P> Tue, 12 May 2015 04:50:26 +0000 Testable Examples in Go https://lwn.net/Articles/643923/ https://lwn.net/Articles/643923/ perlwolf <div class="FormattedComment"> This is an old idea.<br> <p> The code examples for Kernighan and Plauger's book "Software Tools" were kept in the same directory as the text and they were compiled as run regularly as well as being included in the text of the book. That dates ack to the 70's. Go was developed by Bell Labs alumni (Rob Pike and Ken Thompson) who were well aware of the development process for that earlier book, and were surely inspired by it. In fact, the same practice probably was used when Kernighan and Ritchie wrote the original edition of "The C Programming Language", which is an even closer tie to Ken Thompson.<br> </div> Mon, 11 May 2015 16:15:58 +0000 Testable Examples in Go https://lwn.net/Articles/643855/ https://lwn.net/Articles/643855/ pj <div class="FormattedComment"> Indeed, python has had doctests in the stdlib since 2001.<br> </div> Sun, 10 May 2015 22:58:36 +0000 Testable Examples in Go https://lwn.net/Articles/643753/ https://lwn.net/Articles/643753/ imgx64 <div class="FormattedComment"> Probably neither. Online code playgrounds have existed for a long time. I remember Ruby had one on their website in 2008, and I'm sure others existed even before that.<br> <p> But this blog post isn't about that, it's about examples in documentation that get compiled and optionally executed as part of tests. I've seen this before in Python[1], but it's great to see this feature in more languages.<br> <p> [1] <a rel="nofollow" href="https://docs.python.org/3/library/doctest.html">https://docs.python.org/3/library/doctest.html</a><br> </div> Sat, 09 May 2015 02:19:05 +0000 Testable Examples in Go https://lwn.net/Articles/643752/ https://lwn.net/Articles/643752/ lsl <div class="FormattedComment"> Definitely the other way around. play.golang.org existed for years and the executable examples in documentation are nothing recent, too. The only thing new here is the blog post.<br> </div> Sat, 09 May 2015 01:39:58 +0000 Testable Examples in Go https://lwn.net/Articles/643728/ https://lwn.net/Articles/643728/ rgs <div class="FormattedComment"> i guess that was inspired from play.rust-lang.org (or maybe the other way around). <br> </div> Fri, 08 May 2015 21:32:33 +0000