ponyc icon indicating copy to clipboard operation
ponyc copied to clipboard

Rewrite of producer-consumer example

Open glycerine opened this issue 2 months ago • 3 comments

addresses bugs and add assertions to verify correctness:

  • no internal fifo buffer overflows

  • the ordering invariant is maintained, such that the consumer consumes, in sequential order, the complete set of products produced.

glycerine avatar Sep 30 '25 07:09 glycerine

@glycerine i will spend some time looking at this and grab you to discuss the best way to test this for correctness.

SeanTAllen avatar Oct 07 '25 19:10 SeanTAllen

@jemc how do you feel about the assertions and having tests in the example? we don't do tests in examples at the moment but @glycerine made the excellent point that they would add support for knowing you didn't break anything if you follow the "modifications you can do" instructions.

SeanTAllen avatar Oct 07 '25 19:10 SeanTAllen

But I think it's really distracting to have this kind of code as part of an example, so I'd like to see this use more idiomatic Pony test helper uses if possible.

I agree its a little distracting. And I was surprised that I could not locate equivalent functionality elsewhere. But that could just be me being new.

Is there equivalent already available? I tried pony_test. It does not exit immediately on assertion, making debugging difficult.

To me, the ideal situation would be that the pony_assert file readily available for inclusion with a use; perhaps in the standard lib.

I don't know how to summarize or finesse what seems to be a fundamental tension between correctness assertions (critical to safe and correct code and the ability to maintain it long term, in my experience; witness that the prior/existing producer/consumer example is buggy, and I'd bet good money there are other bugs in the examples, since none of them appear to be tested), and the refcap safety which is fundamental to production-time race/deadlock freedom.

Most systems seem to end up with a "debug mode" and a "release mode". Even Go ended up there, despite disliking "debug mode". The race detector is exactly debug mode. edit to add: Zig even has 4 modes; Debug, ReleaseSafe, ReleaseSmall, and ReleaseFast.

glycerine avatar Oct 11 '25 17:10 glycerine