Hello World!

Passiamo al programma Rust più semplice possibile, un classico Hello World:

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

Quello che si vede:

  • Le funzioni sono introdotte con fn.
  • I blocchi sono delimitati da parentesi graffe come in C e C++.
  • La funzione main è il punto di ingresso del programma.
  • Rust ha macro definite come ‘igieniche’ (hygienic macros), println! ne è un esempio.
  • Le stringhe Rust sono codificate in UTF-8 e possono contenere qualsiasi carattere Unicode.
This slide should take about 5 minutes.

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.

Punti chiave:

  • 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 è moderno con pieno supporto per cose come Unicode.

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

  • Le macro definite “igieniche” significa che non catturano accidentalmente identificatori da l’ambito in cui vengono utilizzate. Le macro di Rust sono in realtà solo parzialmente igieniche.

  • 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.