-
Notifications
You must be signed in to change notification settings - Fork 1k
Add zh-CN tutorial translation #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: lightsing <[email protected]>
Why failed..? |
I think it was a transient problem with Bintray. I hit "restart", let's see how it does this time. |
OK, everything is fine this time. I'm going to translate more tutorials. |
can you suggest a reviewer? (see #745 for some possibilities) |
OK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修正一些不太通顺的点
|
||
## 介绍 | ||
|
||
此教学将对 Scala 语言以及编译器做一个简易介绍。面向的读者为具有变成经验且想简要了解 Scala 的人。本文假设读者有着基本、特别是 Java 上的面向对象知识。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo与建议:面向的读者为具有编程经验,并且想简单了解 Scala 的人。本文假设读者有着基本的、最好是 Java 上的面向对象知识。
|
||
## 第一个例子 | ||
|
||
这里用标准的 *Hello world* 程序作为第一个例子。虽然它很无趣,可是这让我们在仅用少量语言特性下演示 Scala 工具。程序如下: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
虽然它很无趣,但让我们可以用少量语言特性来演示 Scala 工具
} | ||
} | ||
|
||
Java 程序员应该对这个程序结构感到熟悉:这有一个`main` 函数,该函数接受一个字符串阵列参数,也就是命令列参数;函数内容为调用已定义好的函数`println ` 并用Hello world 字符串当参数。 `main` 函数没有回传值 (它是程序函数)。因此并不需要声明回传类型。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该函数接受一个字符串数组作为参数,即命令行参数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main
函数没有返回值 (它是一个过程方法)。因此并不需要声明返回值类型。
|
||
Java 程序员应该对这个程序结构感到熟悉:这有一个`main` 函数,该函数接受一个字符串阵列参数,也就是命令列参数;函数内容为调用已定义好的函数`println ` 并用Hello world 字符串当参数。 `main` 函数没有回传值 (它是程序函数)。因此并不需要声明回传类型。 | ||
|
||
Java 程序员不太熟悉的是包着 `main` 函数的 `object` 声明。这种声明引入我们一般称之 *Singleton* 的东西,也就是只有一个实例的类。所以上面的声明同时声明了一个 `HelloWorld` 类跟一个这类的实例,也叫做 `HelloWorld`。该实例会在第一次被使用到的时候即时产生。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所以上面的代码同时声明了一个 HelloWorld
类和该类的一个实例,也叫做 HelloWorld
。
|
||
眼尖的读者可能已经注意到这边 `main` 函数的声明没有带着 `static`。这是因为 Scala 没有静态成员 (函数或属性)。 Scala 程序员将这成员声明在单实例对象中,而不是定义静态成员。 | ||
|
||
### 编译这例子 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
编译这个例子
Derivative relative to y: | ||
Sum(Sum(Const(0),Const(0)),Sum(Const(0),Const(1))) | ||
|
||
研究这输出我们可以发现,取导数的结果应该在输出前更进一步化简。用模式匹配实作一个基本化简函数是一个很有趣 (但是意外的棘手) 的问题,在这边留给读者当练习。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用模式匹配实现一个
|
||
研究这输出我们可以发现,取导数的结果应该在输出前更进一步化简。用模式匹配实作一个基本化简函数是一个很有趣 (但是意外的棘手) 的问题,在这边留给读者当练习。 | ||
|
||
## 特性 (Traits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
特质
|
||
## 特性 (Traits) | ||
|
||
除了由父类继承行为以外,Scala 类还可以从一或多个*特性*导入行为。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
特质
|
||
除了由父类继承行为以外,Scala 类还可以从一或多个*特性*导入行为。 | ||
|
||
对一个 Java 程序员最简单去理解特性的方式应该是视它们为带有实例的接口。在 Scala 里,当一个类继承特性时,它实作了该特性的介面并继承所有特性带有的功能。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
特质 实现 介面->接口
|
||
Java 程序员采用所有对象的父类 `Object`。这个解决办法并不理想,一方面这并不能用在基础类型 (`int`、`long`、`float` 之类),再来这表示必须靠程序员手动加入大量的动态转型。 | ||
|
||
Scala 借由可定义泛型类 (跟函数) 来解决这问题。让我们借由最简单的类容器来检视这点:参照,它可以是空的或者指向某类型的对象。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参照 -> 引用
|
||
Java 程序员不太熟悉的是包着 `main` 函数的 `object` 声明。这种声明引入我们一般称之 *Singleton* 的东西,也就是只有一个实例的类。所以上面的声明同时声明了一个 `HelloWorld` 类跟一个这类的实例,也叫做 `HelloWorld`。该实例会在第一次被使用到的时候即时产生。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一个该类的实例
|
||
我们用 Scala 编译器 `scalac`来编译这个例子。 `scalac` 就像大多数编译器一样,它接受源代码文件当对象,并接受额外的选项,然后产生一个或多个对象文件。它产出的对象文件为标准 Java class 文件。 | ||
|
||
如果我们将上面的程序存成 `HelloWorld.scala` 档,编译指令为( `>` 是提示字符,不用打): | ||
如果我们将上面的程序存为文件 `HelloWorld.scala` 档,编译指令为( `>` 是提示字符,不用打): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果我们将上面的程序存为文件 HelloWorld.scala
,编译指令为( >
是提示字符,不用打):
@@ -291,17 +291,17 @@ Java 中我们会将这个树用一个抽象父类表示,然后每种节点跟 | |||
Derivative relative to y: | |||
Sum(Sum(Const(0),Const(0)),Sum(Const(0),Const(1))) | |||
|
|||
研究这输出我们可以发现,取导数的结果应该在输出前更进一步化简。用模式匹配实作一个基本化简函数是一个很有趣 (但是意外的棘手) 的问题,在这边留给读者当练习。 | |||
研究这输出我们可以发现,取导数的结果应该在输出前更进一步化简。用用模式匹配实现一个基本化简函数是一个很有趣 (但是意外的棘手) 的问题,在这边留给读者当练习。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用用模式匹配实现一个基本化简函数是一个很有趣 这里多了一个用
|
||
## 泛型 | ||
|
||
在这份教学里,我们最后要探讨的 Scala 特性是泛型。Java 程序员应该相当清楚在 Java 1.5 之前缺乏泛型所导致的问题。 | ||
在这份教学里,我们最后要探讨的 Scala 特质是泛型。Java 程序员应该相当清楚在 Java 1.5 之前缺乏泛型所导致的问题。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
特性是泛型 这里不用改为特质
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
抱歉,直接全文替换了...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
this didn't get merged before the big site overhaul. I would like to hit "merge" now, but the file is no longer being added in the right place, since the site structure changed. @lightsing are you still available to update the PR...? |
Is there anything else to change? |
this seems off: -discourse: false
+disqus: true the site no longer uses Disqus. |
OK? |
thanks! sorry for the long delay. |
Add zh-CN tutorial translation based on zh-TW
#779 closed by mistake