Live data from Hacker News

Executable Examples in Go

bitfieldconsulting.com

71–79 of 79 posts

Re: Executable Examples in Go

#71
post #30

Python also has doctest https://docs.python.org/3/library/doctest.html since ... a long time now. The documentation tools are not as advanced as Go's and as far as I know, there's no way to "run the examples" yourself. It's a great way to write tests for some functions though, to me the sweet spot is for small, without side effects functions. It's totally possible for bigger functions but then all the initialization…

I was blown away this year when I realized Django REST Framework was reading comments from classes to generate docs, for example the welcome message on this page [0] comes from a comment in the code.

[0] https://govscent.org/api/

I've come to really love Python, in all its somewhat slow glory.

Re: Executable Examples in Go

#72
I wondered why the hell people find that as a surprise here and figured out that is because the syntax for examples is not documented in [1] how to write a documentation part but instead in [2] "how our testing framework works"

- [1] https://go.dev/blog/godoc

- [2] https://pkg.go.dev/testing#hdr-Examples

Re: Executable Examples in Go

#73

Check out my https://github.com/dave/rebecca package for a neat way of building readme docs by embedding Go docs and examples. It generates the big readme for https://github.com/dave/jennifer (see https://github.com/dave/jennifer/blob/master/README.md.tpl ).

Dave I've been a heavy user of Jennifer for quite some time, thank you for making such an awesome library.

Re: Executable Examples in Go

#76

Earlier quoted context omitted.

Dude doc tests are the one thing I really really miss when I moved over from working on python backend to a typescript backend… Actually unittest as a whole, testing in ts/JS feels like a mess, everything is just fanned out everywhere, there has been such a lack of structure in our codebase. I’m sure there are examples of well organized testing suites, but I’ve yet to find them.

Thing is, most testing frameworks/libraries in JS gives you a lot of freedom to structure the overall testing architecture however you want, without being much picky about it. That means teams writing the tests have to carefully consider their testing architecture, treating it like production code. But most people don't consider testing code "production" code, they treat it like something they should be able to write…

I agree 100% with the statement that it tells us more about our engineering team practices, but the question I have is, how to get it better? Python provides rich built ins, which make it easy to compose a rich suite.

It appears that no one else has an issue with it in my group, but I’m the oddball, these guys come from a TS/JS background. They don’t appear to express concern with it.

Are there resources that you can recommend that I can use to get better?

Re: Executable Examples in Go

#77
post #53

Earlier quoted context omitted.

Having unit testing built-in to the programming language and tooling is a huge plus, absolutely. I don't know who originally came up with this, but I swear, it would be worth some recognition :) (And thankfully, whoever did originally come up with this idea, it has been copied a ton by the recent crop of programming language designs.)

Quite a few D features have made it into other languages: 1. integrated documentation 2. unit tests 3. 1_000_000 literals 4. ranges 5. compile time function execution 6. static if

Unless there is a time machine to have D come up before Smalltalk and Common Lisp/Interlisp-D, it definitely did not do 1, 2 and 3 as influence to other languages.

Re: Executable Examples in Go

#78
post #77

Earlier quoted context omitted.

Quite a few D features have made it into other languages: 1. integrated documentation 2. unit tests 3. 1_000_000 literals 4. ranges 5. compile time function execution 6. static if

Unless there is a time machine to have D come up before Smalltalk and Common Lisp/Interlisp-D, it definitely did not do 1, 2 and 3 as influence to other languages.

Those languages have indeed been around decades before D. But somehow those features did not move into the general language community until after D was very successful with them and popularized those features in a modern language.

BTW, the 1_000_000 specifically came from Ada 1983.

Re: Executable Examples in Go

#79
post #77

Earlier quoted context omitted.

Unless there is a time machine to have D come up before Smalltalk and Common Lisp/Interlisp-D, it definitely did not do 1, 2 and 3 as influence to other languages.

Those languages have indeed been around decades before D. But somehow those features did not move into the general language community until after D was very successful with them and popularized those features in a modern language. BTW, the 1_000_000 specifically came from Ada 1983.

The agile movement is what popularised them, driven by key figures in the Smalltalk and Lisp community, pushing them via Java, Ruby and Python.

All of them predating D.

Post reply on HN