2 ms·
GitHub repo with all of the code: https://github.com/mrfloya/thesis-ba https://github.com/mrfloya/thesis-ba Most interesting part of the thesis, for me, is pag
by steveklabnik 12y ago
GitHub repo with all of the code: https://github.com/mrfloya/thesis-ba https://github.com/mrfloya/thesis-ba
Most interesting part of the thesis, for me, is page 42:
> In this case it was even an advantage that the Rust version was developed last since it revealed a critical error in the other implementations.
Null strikes again!
- yiyus 12y agoHe would have found the problem in Go too if he was using the comma-ok form: n1_idx, ok1 := g.nodeIdx[n1] n2_idx, ok2 := g.nodeIdx[n2] if !ok1 || !ok2 { When you do not use the comma-ok form, you are specifically asking the map to return the zero value for non initialized elements (which is something fine to do in many cases).
- heinrich5991 12y agoWell, you're implicitely asking for it. In Rust you have to explicitely specify your intent, i.e. not by omitting something, but rather by specifying that you want to ignore it.
- yiyus 12y agoTrue. I agree it could be better if omitting the check looked like the exception and not the other way around. You could also argue that encoding non-presence on the type is more powerful/elegant/whatever than multiple return values. But what I wanted to point out is that the problem is not that "Go indicate[s] this error case with a return of zero". The language has an easy way to check this and he ignored it (he eventually used comma-ok in his code, although he makes the check first and the assignment later in different operations for no apparent reason).