Live data from Hacker News

Executable Examples in Go

bitfieldconsulting.com

41–50 of 79 posts

Re: Executable Examples in Go

#41
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…

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.

Re: Executable Examples in Go

#42
post #35
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 don't know why you'd need to run an example apart from when running tests. After all, the examples have been tested to output what the example says.

That can be useful because the doc website turns into some kind of sandbox where you can tweak directly the test function and see the result without having to write the code yourself.

Re: Executable Examples in Go

#43
post #37

Earlier quoted context omitted.

> If the original author has a problem with it, they are free to come in and make the complaint themselves. Most won't know it's posted, or won't see until after it no longer matters. "Don't editorialize" is the simplest and surest way to respect the original author. "Don't editorialize titles unless the original title is very nondescript or clickbait-y" is not a controversial HN policy.

[flagged]

My apologies. You were already on my blocklist of toxic HN users never worth engaging with, but it seems my extension wasn't side-loaded in Firefox after a reboot so I accidentally saw your replies. Won't happen again.

Re: Executable Examples in Go

#44
post #36
post #2

It's not a secret; they're all over the place. The article title is "Executable examples in Go". You shouldn't editorialize titles, especially when it makes the title significantly worse. Edit: seems the article title has changed or is A/B tested so never mind I guess (can't delete since there are replies), but it's still not a "secret".

It certainly isn't a secret in the sense that they didn't want you to know about this feature, but it is a de facto secret in that you can find people who have been programming in Go for year who don't realize they exist. In addition to the other replies you can already find in this HN discussion mentioning that, I can attest to the fact that I've personally introduced them to multi-year programmers in Go as well. I…

Well, it doesn't really matter – my main complaint was that the title was editorialized in a way that I personally wouldn't appreciate for my own article, but now the article title changed and the submitter may be the article author (not entirely clear). I would have deleted my previous post if I could.

Re: Executable Examples in Go

#47
post #43

Earlier quoted context omitted.

[flagged]

My apologies. You were already on my blocklist of toxic HN users never worth engaging with, but it seems my extension wasn't side-loaded in Firefox after a reboot so I accidentally saw your replies. Won't happen again.

I guess this is what happens when you have nothing to actually rebut.

Falling back on ad hominems and irrelevant information that, frankly, nobody would ever care to know. Sometimes, you don’t have to say what’s on your mind. I would have hoped the rest of this thread would have shown you that, but clearly that didn’t happen.

Great use of all our time. At least you won’t see this comment to continue your insults of me. Something that, considering you seem to know the guidelines well, is frowned upon here.

Re: Executable Examples in Go

#49
post #36
post #2

It's not a secret; they're all over the place. The article title is "Executable examples in Go". You shouldn't editorialize titles, especially when it makes the title significantly worse. Edit: seems the article title has changed or is A/B tested so never mind I guess (can't delete since there are replies), but it's still not a "secret".

It certainly isn't a secret in the sense that they didn't want you to know about this feature, but it is a de facto secret in that you can find people who have been programming in Go for year who don't realize they exist. In addition to the other replies you can already find in this HN discussion mentioning that, I can attest to the fact that I've personally introduced them to multi-year programmers in Go as well. I…

You make some good points about the examples visibility in the docs. I suggest that you write up an issue on Go’s issue tracker.

Re: Executable Examples in Go

#50

D's had that for many years. It's not a secret! https://dlang.org/phobos/std_algorithm_searching.html#.any See the buttons below the example code. You can even edit the examples and try variations.

I was curious for exactly how long "many years" was, and it appears it was added sometime between 2016 to 2017. The last archive without it is from 2016, the next archive with it is 2017:

https://web.archive.org/web/20160405080736/https://dlang.org...

Now that's of course just the website feature. Maybe D had executable examples that were tested by the compiler before Go, which would still be very interesting. However, it does appear Go at least did have the in-browser feature as far back as 2015:

https://go.dev/blog/examples

Not that this matters for much other than historical interest: good ideas like this should be copied shamelessly (and obviously it's not a terribly original idea to begin with, just a good implementation of it.)

Post reply on HN