Rust and Swift have sum types, so their equivalent of `memcmp` can have a return type with exactly three values (`Less`, `Equal`, `Greater`).
> 3. Copy once, check twice
I'd like to see the context of this code. Perhaps this could have been written more cleanly using iterators.
> 4. Beware of the ?: operator and enclose it in parentheses
Not a problem in Rust. `if cond { true_case } else { false_case }` is an expression in the obvious way.
> 5. Use available tools to analyze your code
The right tool is called “type checker”, but of course, the language has to be intelligently designed, rather than just evolved, for the type system to be useful.
> 6. Check all the fragments where a pointer is explicitly cast to integer types
Or, even better, don't do it at all.
> 7. Do not call the alloca() function inside loops
Or even better, don't do it at all.
> 8. Remember that an exception in the destructor is dangerous
Rust solves this neatly: use different tools for recoverable and unrecoverable errors (the `Result` sum type and panics, respectively). Destructors always return `()`, so they can't fail in a recoverable way.
> 9. Use the '\0' literal for the terminal null character
Or even better, use Rust-style iterators and forget this null-termination nonsense.
---
I could go on, but this is getting tiresome.