Monday, 4 January 2016

A basic Introduction

Welcome to the world of Rust Programming.

Before we start anything on this topic, I would like to assume the following,

  1. You know about computer programs.
  2. You know about different form of languages.
  3. You know the basics of using a computer like using notepad to write something on it.
  4. Copy paste and save on Notepad etc.
  5. You know how to deal with the command prompt/shell.
However, if you don't know about computer programs, you can read the information in this post, Computer Programs. This post gives you an insight why a computer program exists and what its basic functionality is.

If you are a beginner and yet to know about forms of programming language, the following two articles are just right for you,


If you do not have any idea of Unix Shell/ Windows Powershell or Mac OS Command Line, I recommend you complete this crash course on Command Line, Command Line Crash Course.

At this point, I assume that you are aware of Computer Programming, High Level languages and Command Line.

Please don't prove my assumptions wrong. Because, they are the strong base you will be requiring throughout all the subsequent articles.

Now, I want to be very frank on my writing rules,
  • While writing any article, I assume that you are in front of me and you have asked me a question and I have to answer the question for you. Questions are generally marked bold while my answers to them are in plain text. That may be weird way of writing. But that's the best way I can explain things in minute details.
    For example, look at this article on data, Data. Once you go through it, you will definitely understand what I mean.
  • Sometimes articles are too long. No way, you have to bear with them.
  • Most of the articles will be having real code examples and the output.
  • Although you will see the output in the article, I recommend you to write them on a notepad, save it, compile and run it to see the results yourself rather than relying on me.
  • Practice makes a man perfect. So, practice every day. If you are stuck with anything, comments are welcome. I will try to reply on your comment as soon as possible.
  • I strongly suggest you use simple text editors like Notepad, Notepad++, Vi etc. Please do not use highly functional IDE's and plugins. They will surely bar you from seeing the errors.
  • Wherever necessary, there will  be a section named Source Code Distribution. This section will details about the source code discussed in the article. You can download the source code and can verify the same with your program. But it is not recommended to directly download and use it for your purposes. That will actually defeat the purpose of learning.
I think after reading all these, some people will surely go back and surf some other website. If you are still reading this, 'Welcome reader, I thank you to be here. One thing, I can tell you, this is the way I have learnt programming and it proved to be fruitful. So, I suggest these to my readers to follow as well.'
We'll start our discussion on Rust in the next article.

Introduction to Rust



Rust is a general purpose programming language developed by Mozilla Research.

From Rust Docs, we found that : Rust is a systems programming language focused on three goals: safety, speed, and concurrency. It maintains these goals without having a garbage collector, making it a useful language.
Rust is a new compiled programming language with multiple paradigm support, focused on safety and speed. It accomplishes these goals by being memory safe without garbage collection.
You may be curious about the name of this new born baby in Programming World.
Well, it has taken its name from a family of fungi, usually grown on plants known as Rust.

The release history
The first stable version of Rust (Version 1.0.0) was released on May 15, 2015. So, you can understand how young Rust is.

And subsequent releases are mentioned as below,

Rust version 1.1.0 was released on June 25,2015.
Rust version 1.2.0 was released on August 07,2015.
Rust version 1.3.0 was released on September 17,2015.
Rust version 1.4.0 was released on October 29,2015.
Rust version 1.5.0 was released on December 10,2015.


So, at the time of writing this series, we have the stable version 1.5.0 and we'll be using these throughout this tutorial.

The Syntax
As Rust is a new language, you may query about the syntax of this language. I was also curious about the syntax of this language. So, I jumped off to the examples and I found that, syntax of Rust is similar to that of C, C++. So, who are coming from a background of C, C++, C#, Java, JavaScript etc. they may easily understand the basics of this language. People who are involving themselves in the world of programming for the first time, it should not matter to you. But, I can tell you that the syntax is similar to most modern and popular languages.

That's all I could gather from different sources for an introductory article in Rust. In our next post, I will start with the installation and verification of Rust.

Prev     Next

Installation and verification

For any language to work with, we have to perform set-up. Rust is also not an exception. We have to install Rust to get started with Rust. Now, let's see how we can set-up our environment.

The installation process has several steps,
  1. Download the artefact

    I am using Windows platform and the set-up instructions are mentioned for this platform. So, For Windows platform, you have to browse to this site, Rust Download
    For Widows Rust is supported for 64 bit version only. So, first step before download should be checking your OS architecture. Open command prompt/Powershell and run the following command,
    wmic os get osarchitecture
    

    And you will get similar to the following,
    OSArchitecture
    64-bit
    

    If you get it 32-bit, its time you should upgrade to 64-bit OS. If you are not sure how to do that, please talk to the vendor of your system or get help from your friend who knows about OS Installation.

    Once you have checked the OS version, you should navigate to the website. On the website, we can see there are two options for Windows platform, GNU ABI and MSVC ABI. MSVC ABI. You may get confused at this stage. So, I recommend using the GNU ABI which does not have any other dependencies while the MSVC Builds are dependent on Microsoft Visual Studio. So, for learning purpose, we'll be using the GNU ABI version.

    The website also suggests that, 'Rust's support for the GNU ABI is more mature, and is recommended for typical uses.' So we'll adhere to Rust  recommendation.

    So, download the GNU ABI Version as pointed in the snapshot,

  2. Once the file is downloaded to your system, it should have the name, 'rust-1.5.0-x86_64-pc-windows-gnu.msi'. The name might be different but it surely will have rust and 1.5.0.
  3. Once the file is downloaded, click on it and it will show a window with License of Rust.
  4. Now, you should see a button, 'Install' on the screen and you have to click on the button
  5. Once, you have clicked on the button, you will see the following window,
  6. You have to wait until this gets completed. You may get a warning from Windows. You should click Yes.
  7. Once the installation is completed, you will get to see the following and you can click 'Finish'.
  8. Once you click on 'Finish', the installation is completed and you are good to go with exploring Rust.
  9. Now, you should close all the open command prompt and start with a new command prompt.
  10. In the new command prompt, issue the following command,
    rustc --version
    And you should see the version of Rust Compiler.
At this point, we can tell that the installation is completed. Now let's write a small program to verify if Rust is completely working on your system. Open Notepad/Notepad++ and write the following content on a file and save it with name main.rs,

fn main() {
    println!("Hello, world!");
}

Now, using command prompt, navigate to the location where you have saved main.rs.

On the directory issue the following command,

rustc main.rs

Now if you have typed everything correct, moved to the right directory containing main.rs file and mentioned the right file name, you will see no output and you will get to see another prompt similar to the following,

Now, that's right. After the compilation is completed, you should see another file generated on the same directory with the name main.exe

Now, its time to run the program and check the integrity. Let's run the program using the following command on the command prompt,
main

Now, you will see the following output on the screen,

Hello, world!

Now, that completes the installation and verification of Rust.

You can download the main.rs file from Git, here is the link.