New FAMILUG

The PyMiers

Showing posts with label Mozilla. Show all posts
Showing posts with label Mozilla. Show all posts

Friday, 21 October 2016

Hello, Rust!

Mình thích thì mình học thôi.

Tài liệu: "The Book”,The Rust Programming Language 
Update: tài liệu dễ đọc hơn: http://rust-lang.github.io/book/

Rust thuộc loại ngôn ngữ nào?


Rust là một sản phẩm xuất phát từ Mozilla - tổ chức đứng sau Firefox thần thánh.
Rust is a systems programming language focused on three goals: safety, speed, and concurrency.

Vậy đừng lôi Rust ra làm web rồi chê này kia. Những lĩnh vực mà Rust quảng cáo là phù hợp:
  • embedding in other languages
  • programs with specific space and time requirements
  • and writing low-level code like device drivers and operating systems.
Vậy Rust có thể mang ra code những thứ người ta code bằng C hay C++.

Cài đăt: https://www.rust-lang.org/en-US/downloads.html
Kiểm tra version:
$ rustc --version
rustc 1.12.1 (d4f39402a 2016-10-19)
Những người code Rust được gọi là : Rustaceans

File code Rust có đuôi ".rs". Tên dùng dấu ``_`` để phân cách giữa các từ, như hello_world.rs 
$ cat main.rs
fn main() {
    println!("Hello, FAMILUG!");
}
$ rustc main.rs
$ ./main
Hello, FAMILUG!
Rust là compiled language, tức phải "build" từ file source ".rs" thành file binary, sau đó chạy file binary.
Everything is a tradeoff in language design.

Cargo

Cargo là một phần quan trọng của Rust, quan trọng đến mức khi học lập trình bao nhiêu ngôn ngữ khác bạn sẽ không thấy người ta giới thiệu package manager ngay ở bài Hello, world. Chả ai nói về ``pip`` khi bắt đầu học Python cả.