News for hackers. Stuff that matters.
Re:Pyret Programming Language by bialpio on Sunday August 22, 2021 @02:30AM (#28263384)
I like the idea of attaching tests to the function itself - oftentimes I'm finding myself combing through the unit tests for various components to understand the expectations around how they are meant to be used (especially when they are not documented well enough), I feel this approach could help in this aspect (and also with adding new test cases that could have been missed).
Re:Pyret Programming Language by mdew on Sunday August 22, 2021 @03:00AM (#28263501)
And in python you can use doctests (tests inside de docstrings of functions)
Re:Pyret Programming Language by bialpio on Sunday August 22, 2021 @03:28AM (#28263597)
That's also pretty nice, although elevating those tests to be first-class-citizens makes more sense to me. My approach is that "code is truth, despite what the comment says", and docstrings feel too much like comments, but I haven't used Python professionally that much so I just may not be used to those.
Re:Pyret Programming Language by piperswe on Sunday August 22, 2021 @04:22AM (#28263775)
I haven't used doctests in Python, but I have in Rust. It really helps that any code blocks in a docstring is a doctest by default, so they ensure that examples in your documentation stay evergreen. It's nice to know that if there's a code example in documentation, it will compile and run properly and hasn't been broken.
Re:Pyret Programming Language by Waterluvian on Sunday August 22, 2021 @08:00AM (#28264758)
Practically speaking how useful are the Rust doctests?

I thought they looked like a genius idea but I don’t get how they work 95% of the time when examples don’t come with all the plumbing required to make valid state for a function to actually work on.

Re:Pyret Programming Language by justinpombrio on Sunday August 22, 2021 @10:38AM (#28265819)
There's a feature for that: you prefix the plumbing with `#`, and it runs in the doctest but doesn't render on the doc page. https://doc.rust-lang.org/rustdoc/documentation-tests.html#h...
Re:Pyret Programming Language by Waterluvian on Sunday August 22, 2021 @05:46PM (#28269966)
That would help. I’ll have to experiment to better understand if it all works well enough.

I’m thinking about Python unittest having setUp function for preparing every test without repeating myself. Maybe Rust has a similar way to define setup code for every test.

Re:Pyret Programming Language by adsharma on Sunday August 22, 2021 @10:25AM (#28265720)
I'm looking to do something in this general area better than doctests. Looking for collaborators.

http://adsharma.github.io/pysmt

Re:Pyret Programming Language by scns on Sunday August 22, 2021 @02:33AM (#28263396)
Elixir (Rust too IIRC) check code in doccomments for correctness.