1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-16 23:08:36 +02:00
comprehensive-rust/src/hello-world.md
Dominik Maier 97ac01dc75
Rust isn't functional, but it does have functional elements (#987)
* Rust isn't functional, but it does have functional elements

* End sentence

Co-authored-by: Martin Geisler <martin@geisler.net>

* add info about OO

---------

Co-authored-by: Martin Geisler <martin@geisler.net>
2023-07-18 01:13:06 +02:00

1.5 KiB

Hello World!

Let us jump into the simplest possible Rust program, a classic Hello World program:

fn main() {
    println!("Hello 🌍!");
}

What you see:

  • Functions are introduced with fn.
  • Blocks are delimited by curly braces like in C and C++.
  • The main function is the entry point of the program.
  • Rust has hygienic macros, println! is an example of this.
  • Rust strings are UTF-8 encoded and can contain any Unicode character.

This slide tries to make the students comfortable with Rust code. They will see a ton of it over the next four days so we start small with something familiar.

Key points:

  • Rust is very much like other languages in the C/C++/Java tradition. It is imperative and it doesn't try to reinvent things unless absolutely necessary.

  • Rust is modern with full support for things like Unicode.

  • Rust uses macros for situations where you want to have a variable number of arguments (no function overloading).

  • Macros being 'hygienic' means they don't accidentally capture identifiers from the scope they are used in. Rust macros are actually only partially hygienic.

  • Rust is multi-paradigm. For example, it has powerful object-oriented programming features, and, while it is not a functional language, it includes a range of functional concepts.