noname icon indicating copy to clipboard operation
noname copied to clipboard

convention for functions that don't assert the result?

Open mimoo opened this issue 11 months ago • 2 comments

Interestingly in ocaml there's a convention that if your function can raise an exception then it should have _exn at the end (e.g. https://ocaml.janestreet.com/ocaml-core/109.20.00/doc/core/List.html)

Rust sort of had a convention that you should document any function that could panic.

In both cases this was never really asserted by the compiler and so wasn't too useful. But I think these are good ideas.

I'm wondering if it would make sense to have a convention in function naming to distinguish functions that assert the result, or don't assert the result. For example assert_equal asserts that two variables are equal and equal returns a boolean.

mimoo avatar Jan 23 '25 16:01 mimoo

Can we maybe also include the constraint generating functions in the convention? Like not only assert_equal may raise an exception, it also generates a constraint. I was super confused when circom doesn't create a constraint using assert for instance. This kind of convention could signal that beforehand clearly.

bufferhe4d avatar Mar 05 '25 14:03 bufferhe4d

I don't think so because IMO it's a leaky abstraction, the user shouldn't care about what creates or doesn't create constraints. The fact that circom doesn't constrain anything on assert() is a bad language design

mimoo avatar Mar 05 '25 18:03 mimoo