Live data from Hacker News

Executable Examples in Go

bitfieldconsulting.com

61–70 of 79 posts

Re: Executable Examples in Go

#61
post #53

Earlier quoted context omitted.

> Maybe D had executable examples that were tested by the compiler before Go Sounds like D's ability to specify unit tests in production source code, and have them optionally executed, fits the bill for that. https://dlang.org/spec/unittest.html Builtin unit tests were a great leap forward for code verification.

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

Re: Executable Examples in Go

#64
post #11

Elixir has a similar concept with doc tests: https://elixir-lang.org/getting-started/mix-otp/docs-tests-a... You're comments/docs for the method can have demonstration code that is executed when you run your tests, ensuring your docs remain accurate. It's a great pattern.

Is it similar to what Rust does?

Re: Executable Examples in Go

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

Since 2001, it seems: https://github.com/python/cpython/blob/3.11/Lib/doctest.py#L...

Re: Executable Examples in Go

#68
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.

Whoa, please don't get personal and please don't perpetuate tit-for-tat spats on HN. I know they can be hard to extricate oneself from, but they're very much against the intended spirit here.

https://news.ycombinator.com/newsguidelines.html

Re: Executable Examples in Go

#69
post #43

Earlier quoted context omitted.

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 m…

Whoa, please don't get personal and please don't perpetuate tit-for-tat spats on HN. I know they can be hard to extricate oneself from, but they're very much against the intended spirit here.

https://news.ycombinator.com/newsguidelines.html

Post reply on HN