Common newbie mistakes or bad practices

That deserves an answer:

Quite a lot of my Rust code looks like Javascript. Thing is I want to avoid as many as possible of Rust syntax features that are likely weird and alien to those readers of my code that don't know Rust, Javascripters and the like. Even if they don't have any Rust chops to be able to hack on my code I don't want to totally confuse them and frighten them away from Rust at first sight. So, for example if I have to use lifetime tick marks in my code I have failed.

Speed. Often I feel the need for speed. I can't make JS outrun compiled code.

See little example here: Writing Javascript in Rust ... almost

Scale. Javascript is really not suitable when programs get large and there are multiple people working on it. Rusts type checking helps enormously in keeping everything in order. It makes one far more confident when modifying/refactoring code knowing that Rust will prevent the myriad of ways that one can silently break things in other languages.

Politic: Before we had written a line of code our former employer threatened to sue us thinking we had stolen the code we wrote for them before they went bust. We had not. I thought it would be prudent to implement the similar functionality we needed in a different language, just in case. So what was JS and node.js became Rust.

On the other hand I write a lot of my Rust code as if it were C. As much as the compiler will allow. Because C like languages are what I understand.

Speaking of "mechanical translation". A vendor supplied us with a couple of thousand lines of C# to show how to communicate with their device. In lieu of documentation. I pretty much did a line by line translation of that in to Rust. Worked a treat.

4 Likes