miniblog.

← Back to all posts
46
I'm experimenting with syntax in examples. I don't really like Rust's `assert(inc(1) == 2)` syntax, I find it a little distracting. I'm trying `inc(1) //-> 2`. The comment is rendered differently, and there's nothing before the sample code. What do you think?
PhotoPhoto

6 Comments

@wilfredh the advantage of the assert family is that docs are tested by the compiler so they never diverge from reality. If it's just a comment then you lose that feature.
it took me a while to understand what the assert syntax was saying, i always write the expected output in a comment
@chrisdenton Yep, it’ll need extra tooling support, but I think it might be worthwhile for the friendlier syntax.
@wilfredh It doesn't feel sufficiently better to be worth an unusual syntax. I also think it is less nice for inequality asserts: assert var > 5 vs var > 5 //-> True