DEV Community 👩‍💻👨‍💻

Niclas
Niclas

Posted on

Rust-01: Why am I learning Rust?

This is a good question, a very good question.
Why am I learning Rust?

To begin with, I programmed in a lot of languages so far: C++, Python, Swift, Java, Kotlin and TypeScript to name a few.
All languages have some features I missed when programming in other languages.

Currently, my favorite languages are Kotlin and TypeScript; with Kotlin having the lead.
These languages are expressive, and really nice to write.
I can express my thoughts in code without having to convert them too much in order to make the compiler happy.

Swift also has some super neat aspects.
For example that you are able to add a potocol (≃ Interface) to a class after the fact.
This opened my mind to a whole new set of "Metaprogramming"-Methods.
Swift also introduced me to Pattern Matching, a very powerful tool, if used correctly.
Guards are another thing I'm missing from Swift.
Yes you can achieve a similar behaviour in other languages, but having a special keyword for this type of operation helps in code readability.

Most of my professional programming years I spend programming Java with a short trip to Swift, because a customer wanted to have an iOS app.
During this time Kotlin arrived at my horizon.
It was amazing compared to Java; so concise, so expressive and more secure because the compiler forced you to handle null values.
Unfortunately the company, I was working for at this time, wasn't as exited as me.
So I used Kotlin for private projects only.

In 2020, I switched my job and started to use TypeScript as my primary language.
TypeScript added some features which I really liked but also lacked some.
Duck-Typing is very nice, because you don't have to convert your Data-Objects all the time.
This alone is a huge time saver, but at the cost of some strange behaviours.
For example, if you have a class with two attributes you can assign a plain object to a variable with the type of the class, if it has the same attributes (and methods with the same signatures).
This can introduce strange behaviour if you, for example, rely on the type of the class to execute some code, or you rely on code that is executed in the constructor.
I prepared a code example at typescriptlang.org to make this point more clear.

But back to the initial question: Why am I evaluating Rust to become my primary programming language?

The simple answer is: Rust combines multiple features of languages that I really like.
It is at the same time a low-level (in therms of C and C++) and a high-level (in therms of Kotlin and Typescript) language.
This means I can use it to write webservices and microcontroller / system code.

Some concepts seem odd at first but absolutely make sense if you think about them more deeply.
In the following articles we'll dive deeper into some of these concepts.

Top comments (0)

Super Useful CSS Resources

A collection of 70 hand-picked, web-based tools which are actually useful.
Each will generate pure CSS without the need for JS or any external libraries.