Experimenting with Rust

I know I have mostly been doing reviews of manga and these
days, so some of you guys might be surprised to see something different, but
the tagline is does include both thoughts and reviews.

Due to some things that changed around my current situation,
including some possible distractions that might aggravate me more when I am
busy, I decided to take the time to learn a new programming language, and I
thought I would share my impressions.

As one should be able to easily guess, this language is
called Rust, which I learned through
the official book, so I will
likely comment on the book too.

I first got started in programming quite a while ago, with
the earliest instance of learning a real programming language being
college, where I took a course in C and a course in Java, though I did have
books for some languages, before the, before then, and mainly focused on Java
programming, going on to make some Android apps.

One day, I heard about Swift
and tried it out, but was too used to Java patterns until I took a class that
introduced me to the books from Apple, of which I only recommend is App
Development with Swift
, due to the fact it actually does a good job of
giving a proper foundation to learning programming and explaining things, and
while I do enjoy Swift much more than Java, I hated how a few things do not
quite work out so well in Swift, at least when it is used outside Apple
environments, nor was there any good detail on stuff like concurrency on Linux,
so I decided to give Rust a try, as it promised good concurrency and, if I so
chose, drop down to things that C and C++ would be decent for.

Throughout my time tinkering with Rust, at least while I was
studying the book, I liked how similar it was to Swift, which I am not
surprised about, seeing as many others made the same remark. Almost everything
that was in Swift was also in Rust, even if it did not work the same way as one
would expect.

For example, in Swift there is some called if let,
which allows optional values to be unwrapped by simply doing something like
this:


If let age = {
    print(age)
}

While Rust does have if let too, it is more akin to if
case
and if case let in Swift, both of which I learned the purpose
of thanks to the Rust book, though I heard about them while surfing the net.

Like if case and if case let in Swift, Rust’s if let can
be used be used to match a single pattern, without having to worry about a
catch all or default being provided.

However, while I cannot unwrap an Option, which is Rust’s
equivalent to an optional, in a manner that is as simple as Swift’s if let
allows, I can still do just that with Rust’s if let, as the Option enumeration
is not that different to an Optional in
Swift.

I also liked how simple Rust code seemed to read, while it
is nothing compared to Swift in this area, as I can have functions that are a
little more clear about what they do, it is still a lot better than what I
might with C or Java, especially in the area of loops.

As a result, if I ever feel like getting truly down and
dirty with system programing, or had to write a cross platform application, I
think that I would definitely choose to use Rust, at least right now, seeing as
Swift is getting official support on Windows and more Linux distribution than
Ubuntu, according to an article
by Sergio De Simon on InfQ, which links to
a post on Swift’s website.

Another thing that I really liked was how concurrency and
parallel program actually works in Rust.

Although the Swift book from Apple that I recommend to those
who want to get into programming, or even to learn Swift in general, does talk
about concurrency in Swift, the code it uses, and even most of the code
on the Internet, only works on iOS and/or macOS, due to the fact that there are
additional things that need to be done in non-Apple environments.

Rust, on the other hand, does not seem to have something
special, like GCD (Grand Central Dispatch) that only works as expected on one
platform, probably because their book and the code out there does not assume a
person is using one platform, instead of another, with the only possible
exception being the project in chapter 12,
which requires one to do something that is, as of the time of this writing,
only easy to do in non-Windows environments, since I had to actually look up
how to temporarily set an environment variable on Windows 10.

Seeing this, it actually makes me feel like wanting somebody
to create a way to tap into Rust’s concurrency system as an alternative to GCD
in Swift for non-Apple platforms, but I can probably play around in Rust and
see if I can get Rust code into Swift.

While it seems like I really like Rust, and that would not
exactly be wrong, there are somethings that I am little annoyed with, though
many of them would take time getting used to. The biggest of which is generic
types.

Although I am glad that Rust does them, they feel
unintuitive, along with how I am supposed implement them. In Swift, when I use
generics, I only have to specify it when I create a structure or class and I
have it accessible wherever in the, including in extensions for the type, but
in Rust, I not only need to specify the generic when I create a structure, I
have to declare it in each implementation block in a way like this:


impl<T> Point<T> {
    fn x(&self) -> &T {
	&self.x
    }
}

Why do I need to do this? Rust should already know that
point is generic over type T, but it needs to be told more than once.

Maybe, this will change in the future, along with whatever
gets added, but, until then, I think I would likely stick with Swift as my main
focus in the world of programming, keeping Rust around when I need it or have a
desire to use it.

Tags:

No comments found for article.

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © 2020 Bryce Campbell. All Rights Reserved.