You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 24, 2023. It is now read-only.
Initially, [Rust] started out in 2006 as a personal project from Graydon Hoare—a language designer "by trade" to quote his own words. Developed in his free time during the first three years, Rust was then presented to his employers at Mozilla, which went on and started to actively support it. Indeed, Mozilla Research caught interest in it as something which could do away in the future with various recurrent bugs found in Gecko, Firefox's rendering engine written in C++.
10
-
11
-
An original compiler has been written in [OCaml] until a bootstrapped compiler written in Rust itself could take over, in 2010. Right now the compilation process uses an [LLVM] backend (which you might have seen in action inside [Clang]).
9
+
Initially, [Rust] started out in 2006 as a personal project from Graydon
10
+
Hoare—a language designer "by trade" to quote his own words. Developed in
11
+
his free time during the first three years, Rust was then presented to his
12
+
employers at Mozilla, which went on and started to actively support it. Indeed,
13
+
Mozilla Research caught interest in it as something which could do away in the
14
+
future with various recurrent bugs found in Gecko, Firefox's rendering engine
15
+
written in C++.
16
+
17
+
An original compiler has been written in [OCaml] until a bootstrapped compiler
18
+
written in Rust itself could take over, in 2010. Right now the compilation
19
+
process uses an [LLVM] backend (which you might have seen in action inside
20
+
[Clang]).
12
21
13
22
The Goodness
14
23
------------
15
24
16
-
So what is so good about Rust? We talked about C++ right at the beginning and you might think that since Mozilla is actively leading its development, it should actually have some significant advantages compared to it.
25
+
So what is so good about Rust? We talked about C++ right at the beginning and
26
+
you might think that since Mozilla is actively leading its development, it
27
+
should actually have some significant advantages compared to it.
17
28
18
29
First, what are people looking for when they want to use C++?
19
30
20
-
- A [System programming language], which means it does not compromise on performance and allows for low-level access to the available resources (pointers, manual memory management, etc.)
21
-
- A language with a fairly high-level of abstraction and a large feature-set ([OO programming] is one of them) that stays fast and has broad compatibility
31
+
- A [System programming language], which means it does not compromise on
32
+
performance and allows for low-level access to the available resources
33
+
(pointers, manual memory management, etc.)
34
+
- A language with a fairly high-level of abstraction and a large feature-set
35
+
([OO programming] is one of them) that stays fast and has broad compatibility
22
36
23
37
Now, what are the main features that Rust brings on top of that?
24
38
25
-
- Safety (and mostly: safe pointer types thanks to a [very efficient memory model], no void* heresy[<sup>◊</sup>](#appendix-elaborating-on-c-and-safety), no use-after-free, mem leaks,...)
26
-
- Native actor-based concurrency inspired from [Erlang]. This is a big deal for today's programming languages with the rise of multicore processors; in fact, some sort of multithreading is already there on C++11 (2011) and will probably get extended in C++14. Actually, the actor implementation of multithreading consists of explicitly sending message from a lightweight thread (`chan`) and receiving it from another (`port`); it is a great safety/efficiency compromise. Rust allows the use of either green (M:N) or native (1:1) threads.
27
-
- Inspirations from [Haskell] and [OCaml], not only for the functional programming paradigm but also for the type classes (`trait`, `impl`)
28
-
- Some programmers friendly features from Python—that being said, Rust does not compromise on performance: it has static typing (with type inference!)
29
-
- Optional tracing-GC (WIP)—the `std::gc::Gc` type recently landed on mainline
30
-
31
-
As you can see, Rust does not try to be a new fancy thing; rather, it builds up on top of proven useful technology and merges features from some existings languages, noticeably: Erlang's green threads, Haskell trait system and overall functional programming elements of a few languages (it has pattern matching!), some syntax sugar from Python (the `range` iterator is one of them) and it also resurrects a few features from some American research languages developed in the 80s, amongst others.
32
-
As you can see, along with some features that definitely set it in today's rollup of programming languages, Rust is also the result of a true willingness to reuse concepts from the rich history of programming languages, rather than building up the wheel over again. ;) ~ as you might have seen, that's partly where the name "Rust" comes from!
33
-
34
-
>I was fiddling with a number of names. Primarily it's named after the [pathogenic fungi] which are just amazing multi-lifecycle, multi-host parasites, fascinating creatures.
39
+
- Safety (and mostly: safe pointer types thanks to a [very efficient memory
40
+
model], no void* heresy, no use-after-free, mem leaks,...)
41
+
- Native actor-based concurrency inspired from [Erlang]. This is a big deal for
42
+
today's programming languages with the rise of multicore processors; in fact,
43
+
some sort of multithreading is already there on C++11 (2011) and will probably
44
+
get extended in C++14. Actually, the actor implementation of multithreading
45
+
consists of explicitly sending message from a lightweight thread (`chan`) and
46
+
receiving it from another (`port`); it is a great safety/efficiency
47
+
compromise. Rust allows the use of either green (M:N) or native (1:1) threads.
48
+
- Inspirations from [Haskell] and [OCaml], not only for the functional
49
+
programming paradigm but also for the type classes (`trait`, `impl`)
50
+
- Some programmers friendly features from Python—that being said, Rust
51
+
does not compromise on performance: it has static typing (with type
52
+
inference!)
53
+
- Optional tracing-GC (WIP)—the `std::gc::Gc` type recently landed on
54
+
mainline
55
+
56
+
As you can see, Rust does not try to be a new fancy thing; rather, it builds up
57
+
on top of proven useful technology and merges features from some existings
58
+
languages, noticeably: Erlang's green threads, Haskell trait system and overall
59
+
functional programming elements of a few languages (it has pattern matching!),
60
+
some syntax sugar from Python (the `range` iterator is one of them) and it also
61
+
resurrects a few features from some American research languages developed in the
62
+
80s, amongst others.
63
+
As you can see, along with some features that definitely set it in today's
64
+
rollup of programming languages, Rust is also the result of a true willingness
65
+
to reuse concepts from the rich history of programming languages, rather than
66
+
building up the wheel over again. ;) ~ as you might have seen, that's partly
67
+
where the name "Rust" comes from!
68
+
69
+
> I was fiddling with a number of names. Primarily it's named after the
70
+
> [pathogenic fungi] which are just amazing multi-lifecycle, multi-host
71
+
> parasites, fascinating creatures.
35
72
>
36
-
>But the name "rust" has other nice features. It fits with our theme of being "close to the metal" and "using old well-worn language technology". It's also a substring of "trust" and "robust". What's not to like?
73
+
> But the name "rust" has other nice features. It fits with our theme of being
74
+
> "close to the metal" and "using old well-worn language technology". It's also
75
+
> a substring of "trust" and "robust". What's not to like?
37
76
>
38
77
> — Graydon Hoare
39
78
40
-
Actually, Mozilla is already using it in an experimental browser rendering engine that is being developed simultaneously to Rust and is at the core of the team's pragmatic development approach, just like [D]'s—that is, the developers implement features and sometimes change them based on their experience with it; besides, they also take feedback (and contributions!) from the community.
41
-
Remember, C—today's most successful language—has been built in concert with the UNIX OS, allowing adaptations from what happened during the OS development process. Right now, Rust is still in alpha state which means that developers can still make breaking changes to the API (but not to worry, it is converging towards a stable state which will ultimately happen in 1.0).
42
-
43
-
There have been other attempts at providing such a new System programming language (e.g. [D], [Nimrod])—Go also gets mentioned sometimes but it has been developed for apps/webapps and is more oriented towards simplicity and fast compilation-speed.
44
-
Right now, it looks like Rust has a big chance to set itself apart because:
45
-
46
-
- It focuses on safety without compromising performance (D requires GC for safety, and Nimrod does not ensure thread safety), it has low-level features but also lots of sugar for the developer (the syntax is modern and not overly verbose)
47
-
- It is pretty innovative, seeing how it reuses a lot of features that have been developed independently, but make sense together
79
+
Actually, Mozilla is already using it in an experimental browser rendering
80
+
engine that is being developed simultaneously to Rust and is at the core of the
81
+
team's pragmatic development approach, just like [D]'s—that is, the
82
+
developers implement features and sometimes change them based on their
83
+
experience with it; besides, they also take feedback (and contributions!) from
84
+
the community.
85
+
Remember, C—today's most successful language—has been built in
86
+
concert with the UNIX OS, allowing adaptations from what happened during the OS
87
+
development process. Right now, Rust is still in alpha state which means that
88
+
developers can still make breaking changes to the API (but not to worry, it is
89
+
converging towards a stable state which will ultimately happen in 1.0).
90
+
91
+
There have been other attempts at providing such a new System programming
92
+
language (e.g. [D], [Nimrod])—Go also gets mentioned sometimes but it has
93
+
been developed for apps/webapps and is more oriented towards simplicity and fast
94
+
compilation-speed. Right now, it looks like Rust has a big chance to set itself
95
+
apart because:
96
+
97
+
- It focuses on safety without compromising performance (D requires GC for
98
+
safety, and Nimrod does not ensure thread safety), it has low-level features
99
+
but also lots of sugar for the developer (the syntax is modern and not overly
100
+
verbose)
101
+
- It is pretty innovative, seeing how it reuses a lot of features that have been
102
+
developed independently, but make sense together
48
103
- It is backed by Mozilla, not bad if you are trying to set a standard!
49
104
50
105
Appendix: Elaborating on C++ and safety
51
106
---------------------------------------
52
107
53
-
You might think: why were these even allowed in the first place? To quote Tony Hoare, the `null_ptr` precursor:
108
+
You might think: why were these even allowed in the first place? To quote Tony
109
+
Hoare, the `null_ptr` precursor:
54
110
55
-
> I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.
111
+
> I couldn't resist the temptation to put in a null reference, simply because it
112
+
> was so easy to implement. This has led to innumerable errors, vulnerabilities,
113
+
> and system crashes, which have probably caused a billion dollars of pain and
114
+
> damage in the last forty years.
56
115
>
57
116
> — Tony Hoare
58
117
59
-
C++ is a mixed breed: it has been developed from the beginning to build up on top of C with new features that were emerging in the field of programming. Today, it is one of the [Top Five languages] because it has been fast at a higher level of abstraction (also complexity!) than the others.
60
-
Looking back, we realized that the time spared by relaxed programming APIs was often creating much bigger problems down the road—because it is always less time consuming and more convenient to just avoid these programming derps than debugging your program afterwards.
61
-
62
-
Rust tries to ensure safety with some additional syntax markup (which actually makes you to think unambiguously about your desired behavior) that allows for a way more fine-grained static analysis by the compiler and can lead to additional compiler optimizations—indeed, some unsafe code that would pass as valid in most of today's most-used languages would get caught at compile-time in Rust. Instructions that are not safe or cannot be statically checked will have to be located inside an `unsafe` code block (that is mostly for the FFI, which allows you to link your programs to C).
118
+
C++ is a mixed breed: it has been developed from the beginning to build up on
119
+
top of C with new features that were emerging in the field of programming.
120
+
Today, it is one of the [Top Five languages] because it has been fast at a
121
+
higher level of abstraction (also complexity!) than the others.
122
+
Looking back, we realized that the time spared by relaxed programming APIs was
123
+
often creating much bigger problems down the road—because it is always
124
+
less time consuming and more convenient to just avoid these programming derps
125
+
than debugging your program afterwards.
126
+
127
+
Rust tries to ensure safety with some additional syntax markup (which actually
128
+
makes you to think unambiguously about your desired behavior) that allows for a
129
+
way more fine-grained static analysis by the compiler and can lead to additional
130
+
compiler optimizations—indeed, some unsafe code that would pass as valid
131
+
in most of today's most-used languages would get caught at compile-time in Rust.
132
+
Instructions that are not safe or cannot be statically checked will have to be
133
+
located inside an `unsafe` code block (that is mostly for the FFI, which allows
134
+
you to link your programs to C).
63
135
64
136
Appendix: Elaborating on Servo
65
137
------------------------------
66
138
67
-
What is [Servo]? Well—nothing to do with mechanics: it is Mozilla's experimental browser rendering engine.
139
+
What is [Servo]? Well—nothing to do with mechanics: it is Mozilla's
140
+
experimental browser rendering engine.
68
141
69
-
So, in a way, you could say that it's their biggest [hope][servo-hope] and biggest motivation for supporting Rust's development. Safety. Parallelism. (And Performance.)
70
-
Its development started in early-2012 (they like contributions too!) and it is evolving along with Rust.
142
+
So, in a way, you could say that it's their biggest [hope][servo-hope] and
143
+
biggest motivation for supporting Rust's development. Safety. Parallelism. (And
144
+
Performance.) Its development started in early-2012 (they like contributions
145
+
too!) and it is evolving along with Rust.
71
146
72
-
Servo is built on a modular architecture and each engine component is separated from the other in an effort to have parallelized and easy-to-maintain code. Since April 2013, Mozilla and Samsung [are collaborating][moz-samsung] in the project development.
147
+
Servo is built on a modular architecture and each engine component is separated
148
+
from the other in an effort to have parallelized and easy-to-maintain code.
149
+
Since April 2013, Mozilla and Samsung [are collaborating][moz-samsung] in the
150
+
project development.
73
151
74
-
Note that right now, Mozilla has no plans to integrate Servo onto Firefox, i.e., it is as of now a research project and is still in early stages of development.
152
+
Note that right now, Mozilla has no plans to integrate Servo onto Firefox, i.e.,
153
+
it is as of now a research project and is still in early stages of development.
Copy file name to clipboardExpand all lines: source/ch-02.md
+23-10Lines changed: 23 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,13 @@
3
3
Few things you should know
4
4
==========================
5
5
6
-
The Rust API is frequently evolving (read: improving), so this tutorial will be aimed at current master which has the latest language contents.
7
-
Note that most of the "standard" features are pretty much stabilized and should not change much. You can choose to use the latest release, but as it gets older, there will probably be numerous changes onto the latest trunk. If you have any concern related to the language or its syntax, just [jump on IRC][IRC] and ask the others!
6
+
The Rust API is frequently evolving (read: improving), so this tutorial will be
7
+
aimed at current master which has the latest language contents.
8
+
Note that most of the "standard" features are pretty much stabilized and should
9
+
not change much. You can choose to use the latest release, but as it gets older,
10
+
there will probably be numerous changes onto the latest trunk. If you have any
11
+
concern related to the language or its syntax, just [jump on IRC][IRC] and ask
12
+
the others!
8
13
9
14
The latest release is Rust 0.9, released on January 9th 2014.
10
15
@@ -13,20 +18,25 @@ Installing Rust
13
18
14
19
### Windows
15
20
16
-
You can get [snapshot builds][snapshots-windows] for Windows through the NuGet [Package Manager console]:
21
+
You can get [snapshot builds][snapshots-windows] for Windows through the NuGet
22
+
[Package Manager console]:
17
23
18
24
~~~~bash
19
25
Install-Package Rust
20
26
~~~~
21
27
22
-
Or have a look at the [build instructions][build-windows] if you want to build it yourself.
23
-
**Note:**`mingw-w64` should fix a few things compared to the regular `mingw` (it works on both 32- and 64-bit systems, despite the name).
28
+
Or have a look at the [build instructions][build-windows] if you want to build
29
+
it yourself.
30
+
**Note: `mingw-w64` should fix a few things compared to the regular `mingw` (it
31
+
**works on both 32- and 64-bit systems, despite the name).
24
32
25
-
If you are not willing to go through these steps, just download the [0.9 release][win-release].
33
+
If you are not willing to go through these steps, just download the [0.9 release
34
+
][win-release].
26
35
27
36
### Mac OS X
28
37
29
-
The installation process on Mac OS is fairly easy using the [Homebrew package manager][Homebrew]; for the latest trunk, run:
38
+
The installation process on Mac OS is fairly easy using the [Homebrew package
39
+
manager][Homebrew]; for the latest trunk, run:
30
40
31
41
~~~~bash
32
42
brew install --HEAD rust
@@ -61,12 +71,14 @@ make
61
71
sudo make install
62
72
~~~~
63
73
64
-
Note that there are repositories with nightly packages for [Arch], [Fedora] and [Ubuntu].
74
+
Note that there are repositories with nightly packages for [Arch], [Fedora] and
75
+
[Ubuntu].
65
76
66
77
Get your code editor ready
67
78
--------------------------
68
79
69
-
You are about to write your first Rust program; just create a `.rs` file with your favorite text editor. It gets built with `rustc`, the Rust compiler.
80
+
You are about to write your first Rust program; just create a `.rs` file with
81
+
your favorite text editor. It gets built with `rustc`, the Rust compiler.
70
82
71
83
~~~~bash
72
84
# create a new file
@@ -79,7 +91,8 @@ rustc hello.rs
79
91
80
92
Using the `-O` switch will add the default optimization level to the code.
81
93
82
-
BTW, you can get syntax highlighting for [vim], [gedit] or [other highlighting solutions] on the main repo.
94
+
BTW, you can get syntax highlighting for [vim], [gedit] or [other highlighting
0 commit comments