Programming Languages war
Golang vs Rust

Programming Languages war Golang vs Rust

Install new fighters

Install new fighters

I'm back, first if anyone miss my post I offer my apologizes, but I was without inspiration, but I'm here again with new fighters.

wwe-the-miz.gif

Ladies and gentlemen, in this corner first appeared in 2009 with memory safety, garbage collection, structural typing and is loved according to Stack Overflow 2021 by 62.74% Goooooolang

Now the next fighter had the first appeared in 2010 with memory safety without garbage collection, reference counting is optional and is loved according to Stack Overflow 2021 by 86.98% Ruuuuuuuust.

Note: Please read that like WWE or Boxing presentations.

Now we're going with the tech stuff, but remember, I don't know which is better, but I'll try to figure it out. I hope y'all enjoy this series. Obviously We have to start the installation and amazing "Hello, World!". The whole series I'm going to use SO Ubuntu, then if you need support for other SO I'm going to be here to help you.

Pre requirements

Install curl apt install curl

Screenshot_20211113_191136.png

Golang/Go

This is our recipe to install Golang/Go

  • Step 1:

    Download golang from the website golang.org/doc/install#download I recommend to use curl to download the file

    curl https://dl.google.com/go/go1.17.3.linux-amd64.tar.gz --output go1.17.3.linux-amd64.tar.gz
    

Screenshot_20211113_194718.png

  • Step 2

    Now you have to decompress the file in folder /usr/local rm -rf /usr/local/go && tar -C /usr/local -xzf go1.17.3.linux-amd64.tar.gz

  • Step 3

    Add to the file .bashrc the next line export PATH=$PATH:/usr/local/go/bin

Screenshot_20211113_195304.png

After that, close the shell or run . .bashrc

Screenshot_20211113_195413.png

If you run that and has an output, all was good go version

Screenshot_20211113_195451.png

  • Step 4

    Create a folder and join in it

    mkdir hello
    cd hello/
    
  • Step 5

    You have to enable dependency tracking for your code go mod init example/hello

Screenshot_20211113_195840.png

  • Step 6

    You have to create a file, can you guess the name? Image tic tac

    hello.go

    package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Hello, World!")
    }
    
  • Step 7

    It's time to run our program go run .

Screenshot_20211113_200155.png

Rust

This is our recipe to install Rust

Pre requirements Install build-essential apt install build-essential

Screenshot_20211113_192506.png

  • Step 1

    Download the tools that you need to run the rust language from the website rust-lang.org/tools/install curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Screenshot_20211113_191305.png

Screenshot_20211113_191803.png

You only require to choose the first option

And run that source $HOME/.cargo/env

Screenshot_20211113_191847.png

  • Step 2

    This tool is called "cargo", this tool creates all structure for you and do other things, but this time only you create the structure cargo new hello_world

Screenshot_20211113_191944.png

By default, "cargo" creates this structure with the file to make our "Hello world!"

Screenshot_20211113_192115.png

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

    It's time to run our program, you can guess how to? cargo run

Screenshot_20211113_210545.png

Resume

Entertainment fight, Golang starts with its better punch, show a simple structure, but Rust responds with fewer steps to run, Golang requires import the package "fmt" to print with "Println" something and Rust needs to use the macro Println, by the way both have the same method ending with "ln" you know why? To add a break line.

icegif-607.gif

This is our first view about two amazing languages, how you could see we can use any language in so many environments for the same things, but which is better, today we can see a few conclusions:

  • Golang/Go requires more step to run.
  • Golang requires import packages to print, and Rust uses macros to the same.
  • Rust in addition to the language, install the tool "cargo" can run and create the structure base to Rust.

I hope you enjoy my post and remember that I am just a Dev like you!