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.
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
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
- 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
After that, close the shell or run
. .bashrc
If you run that and has an output, all was good
go version
- 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
- 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 .
Rust
This is our recipe to install Rust
Pre requirements
Install build-essential
apt install build-essential
- 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
You only require to choose the first option
And run that
source $HOME/.cargo/env
- 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
By default, "cargo" creates this structure with the file to make our "Hello world!"
fn main() {
println!("Hello, world!");
}
- Step 3
It's time to run our program, you can guess how to?
cargo run
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.
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!
Top comments (8)
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.
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.
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#.
That's amazing, I think C ++ can't be a fighter because it would always win. Thanks for your comment.
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.
Very light hearted, short but nice 😊
We'll be publishing a post soon about comparing Rust and Go in 2024, stay tuned here - packagemain.tech/
Who won for you?