Two Years of Rust

79 points by EvanHahn


mqudsi

Interesting mix of beginner-friendly advice with nuggets for hardcore rust users dealing with scaling problems thrown in in this article. I thought it was going to touch on one of my outstanding issues with rust (namely, the statically typed nature of generic parameters or lifetimes making refactoring (or mocking) time-consuming), but it only grazed on the matter.

But with regards to mocking, the truth is that mock-heavy unit tests are just not part of the rust ecosystem/culture both because of a divergence in principles and also implicitly because it’s so much harder to do so. Your modules should be designed in a way where each module owns a specific functionality and offers an api that (thanks to strict typing) is resilient to being misused. To be perfectly blunt, a high-level mock test (with the exception of mock tests required to test different underlying scenarios - but these would be ones that provide different output and therefore you can use a different approach altogether) does not necessarily provide any real value: just because my mock database client successfully stored and retrieved a user record does not mean your postgres client will, perhaps because of the semantics of the ignored transaction or perhaps because of other issues (for example, in this (contrived but very much real-world) mock test OP is completely ignoring the Transaction because to properly implement transactions in a mock unit test, you’d have to write your own ACID-compliant rdbms).

Basically, you shouldn’t expect to write your codebase (or supporting infrastructure) for a rust project the same way you would in a python or javascript project. There’s a culture mismatch, a language impedance mismatch, a contractual guarantees mismatch, and more.