My Initial Impressions of the Rust Programming Language

This blog post presents my initial reactions after a few days working with the Rust programming language.

Of course, anyone using a programming language should read the book (https://doc.rust-lang.org/stable/book/). Some people in the rust community may push on this pretty hard. I like to read books, but I do not like to read online, and did not want to print it. I also think it is a little weird that everyone is supposed to read the same book and program the same way. It probably would have helped, so I highly recommend it, especially for some basics around string processing and other fundamentals.

I found the rust community to be helpful without being abusive.

Rust and related tools are easy to install on Windows or Linux.

Rust is free and cross-platform. I did not even check whether it is open source, but how else could it exist? Rust appears to be a system programming language for processes that run on the command line or present no user interface. The syntax and specific formatting conventions appear to be relatively unique and precise.

In some cases, the syntax seems extremely verbose, while in others it is very concise. Other decisions seem arbitrary, such as suggesting no parentheses to group conditions in conditionals and that apparently any statement without a semicolon can function as a return statement. Some of these aspects may make rust frustrating at first, especially for developers more familiar with lightweight scripting engines or languages such as C#, but given enough time, the potential advantages may become apparent. You can really feel the efficiency, like going back to the days when people thought about memory allocation (nowadays, unused memory is wasted memory – just buy more).

In some cases, rust may be an appropriate alternative to C or C++. Rust integrates with standard libraries and linkers and will likely be more approachable to developers familiar with variants of Unix. Unfortunately, new rust developers are likely create code with numerous syntax errors, and the compiler does not always provide optimal guidance.

Though developers not familiar with those paradigms must immediately address certain obstacles and patterns for things as simple and common as string processing, it quickly becomes clear that the language and tooling intend to improve your code quality, and in the medium term, it seems easier than C or C++. While I have not used either of those languages in years, I believe that rust may be easier to learn and *possibly* easier to maintain in the long term. Rust for Windows and WSL show Microsoft’s commitments to Linux.

While it is possible to access platform specifics, such as invoking command lines that might only work on Windows or *nix, rust does not seem to immediately address any cross-platform concerns.

Useful rust-related commands:

  • curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh : Install rust tools.
  • rustup : Upgrade and otherwise maintain rust tools.
  • rustup doc : Open local documentation (under WSL, rustup.exe doc works).
  • rustfmt main.rs : Reformat code in place according to standards.
  • rustcs main.rs : Compile.
  • cargo new <project> ; cd <project>/src ; vi main.rs : Create a new project.
  • cd <project> ; cargo check : Check package and dependencies for errors.
  • cd <project> ; cargo update : Update dependencies.
  • cd <project> ; cargo-clippy : Coding suggestions for project.
  • cd <project> ; cargo build : Build debug project.
  • cd <project> ; cargo build –release : Build release project.
  • cd <project> ; cargo doc : Generate documentation.
  • cd <project> ; cargo run [command line arguments] : Run project (or use target/debug/binary).

You can start with the rust compiler rustc, but I suggest using cargo from the start instead. Apply rustfmt, and apply suggestions from cargo-clippy, and read the guidance referenced by the compiler,

You may want to write a script that builds, invokes, tests, and/or deploys your program. For example, for a program named wink, I wrote a shell script wince to build it for Linux and a Windows command script named wince.cmd that invokes rustfmt. Then, if cargo-clippy and cargo build do not generate warnings, the script can deploy the build, and then even run the newly built wink, passing on any arguments passed to these build scripts on to wink itself. In this way, rust can function almost as a compiled scripting language.

Update 21.June.2021: Build script wince moved to github repository linked below.

wink/wince at main · deliverystack/wink (github.com)

Running the wince script to build wink

I am still working on it, but within a few days, I wrote what I consider to be a useful tool I call wink for accessing Windows features and launching Windows programs from the Windows Console or Bash command line. As someone who has written software for more than 35 years, I consider this to be one of the most useful things that I have ever written. I prefer a Bash shell to Windows, but I use C# and Visual Studio requires Windows. The combination of Windows, WSL, Rust, and Visual Studio Code is optimal for certain relevant requirements.

At least for Windows and especially for WSL (Windows Subsystem for Linux), I recommend Visual Studio Code for rust coding. You may want to use the shell within Visual Studio Code to compile and run your rust programs. I have not used any Visual Studio extensions for rust so far. You may want to launch Visual Studio Code with the shell script (/mnt/c/Users/<USERNAME>/AppData/Local/Programs/Microsoft VS Code/bin/code) rather than the executable (/mnt/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/devenv.exe). Visual Studio Code understands WSL paths.

Rust puns and related jokes:

  • russ
  • truss
  • rusty
  • Rusty “I stabbed my brain” Griswold
  • crusty
  • trusty
  • rusty the clown
  • rusted
  • I gave up in rustacion
  • my rust went bust
  • the upper rust
  • the solution is rust around the corner
  • ashes to ashes, rust to rust
  • rust a minute
  • she is rustworthy
  • I do not rust his code
  • rust bucket
  • rust in the wind
  • rustoleum
  • rust in peace
  • coding oxidents
  • cosmic rust
  • the rust of the story
  • rust resistant
  • stainless
  • isn’t it ironic (that I use Visual Studio Code on Windows to write a rust program that can launch Visual Studio code from Windows Subsystem for Linux shells or the Windows console? or that iron rusts?)

One thought on “My Initial Impressions of the Rust Programming Language

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: