DEV Community

Cover image for Programming Languages war Golang vs Rust
Carlos Rivas
Carlos Rivas

Posted on

Programming Languages war Golang vs Rust

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 https://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 
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode
  • 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!")
  }
Enter fullscreen mode Exit fullscreen mode
  • 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 https://www.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!");
  }
Enter fullscreen mode Exit fullscreen mode
  • 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!

Discussion (10)

Collapse
lexiebkm profile image
Alexander B.K.

How both languages define methods is interesting. Being not (fully) OOP, both provide different ways in defining methods, but basically similar, i.e in the context of a type like Struct which both languages provide, and can use pointers for that purpose.
So for me, it is not a war, they are like friends to me. C/C++ too.

Collapse
devlikeyou profile image
Carlos Rivas Author

I like your way to think, in my opinion all languages are good if you feel good with that and you can solve the problem.

Collapse
sharpninja profile image
The Sharp Ninja

What did I just read? I thought there would be a conclusion with a winner.

Collapse
devlikeyou profile image
Carlos Rivas Author

Who won for you?

Collapse
sharpninja profile image
The Sharp Ninja

I mean, there's nothing here but a description of installing the base set of tools. There's no comparison of the languages, syntax, features, standard libraries, error handling... Just nothing.

Thread Thread
devlikeyou profile image
Carlos Rivas Author

This was the first post about these languages, I will post more about them with differences and similarities. I hope you read the next post.

Thread Thread
sharpninja profile image
The Sharp Ninja

Yes, happily. I suggest making it clear that it's going to be a multi-part series.

Collapse
lexiebkm profile image
Alexander B.K.

I am concerned with the executable file size for that simple helloworld when I use Rust, Go and C++ on Windows with the following result which is surprising to me:
Rust is 4Mb, Go is 3Mb, while C++ is only 171kb.
It seems that for a simple console app, I cannot ignore C++. That's why I want to re-learn it in the correct way.
However, these 3 languages provides Struct and Pointer that I will feel like at home when learning them all.
Currently, for web backend that uses a compiled language, my 1st option is Go because of ease and quick development. Next is Java, followed by probably C#.

Collapse
devlikeyou profile image
Carlos Rivas Author

That's amazing, I think C ++ can't be a fighter because it would always win. Thanks for your comment.

Collapse
lil5 profile image
Lucian I. Last

Very light hearted, short but nice 😊