From 5b071b936b7b33568c02f2ea42fa93a60074738d Mon Sep 17 00:00:00 2001 From: xiaohulu Date: Sun, 19 Aug 2018 22:15:22 +0800 Subject: [PATCH] update ch01-02-hello-world.md --- src/ch01-02-hello-world.md | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index ef48fac..ac166b9 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -99,7 +99,7 @@ fn main() { println!("Hello, world!"); ``` -这行代码完成这个简单程序的所有工作:在屏幕上打印文本。这里有四个重要的细节需要注意。首先 Rust 的缩进风格 使用 4 个空格,而不是 1 个制表符(tab)。 +这行代码完成这个简单程序的所有工作:在屏幕上打印文本。这里有四个重要的细节需要注意。首先 Rust 的缩进风格使用 4 个空格,而不是 1 个制表符(tab)。 第二,`println!` 调用了一个 Rust 宏(macro)。如果是调用函数,则应输入 `println`(没有`!`)。我们将在附录 D 中详细讨论宏。现在你只需记住,当看到符号 `!` 的时候,就意味着调用的是宏而不是普通函数。 @@ -143,15 +143,6 @@ $ ./main # or .\main.exe on Windows 如果 *main.rs* 是上文所述的 Hello, world! 程序,它将会在终端上打印 `Hello, world!`。 -If you’re more familiar with a dynamic language, such as Ruby, Python, or -JavaScript, you might not be used to compiling and running a program as -separate steps. Rust is an *ahead-of-time compiled* language, meaning you can -compile a program and give the executable to someone else, and they can run it -even without having Rust installed. If you give someone a *.rb*, *.py*, or -*.js* file, they need to have a Ruby, Python, or JavaScript implementation -installed (respectively). But in those languages, you only need one command to -compile and run your program. Everything is a trade-off in language design. - 如果你更熟悉动态语言,如 Ruby、Python 或 JavaScript,则可能不习惯将编译和运行分为两个单独的步骤。Rust 是一种 **预编译静态类型**(*ahead-of-time compiled*)语言,这意味着你可以编译程序,并将可执行文件送给其他人,他们甚至不需要安装 Rust 就可以运行。如果你给他人一个 *.rb*、*.py* 或 *.js* 文件,他们需要先分别安装 Ruby,Python,JavaScript 实现(运行时环境,VM)。不过在这些语言中,只需要一句命令就可以编译和运行程序。这一切都是语言设计上的权衡取舍。 仅仅使用 `rustc` 编译简单程序是没问题的,不过随着项目的增长,你可能需要管理你项目的方方面面,并让代码易于分享。接下来,我们要介绍一个叫做 Cargo 的工具,它会帮助你编写真实世界中的 Rust 程序。