Skip to content

翻译优化 24-Concurrent-Programming.md#并发为速度而生 #Java 并发的四句格言 #597

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

Merged
merged 2 commits into from
Sep 30, 2020

Conversation

TENCHIANG
Copy link
Contributor

两节

@sjsdfg
Copy link
Collaborator

sjsdfg commented Sep 25, 2020

PR 重新更新一下。这里面的改动已经 merge 过了

@TENCHIANG
Copy link
Contributor Author

PR 重新更新一下。这里面的改动已经 merge 过了

是这样吗

@@ -135,91 +135,91 @@ slowdown occurs):

在听说并发编程的问题之后,你可能会想知道它是否值得这么麻烦。答案是“不,除非你的程序运行速度不够快。”并且在决定用它之前你会想要仔细思考。不要随便跳进并发编程的悲痛之中。如果有一种方法可以在更快的机器上运行你的程序,或者如果你可以对其进行分析并发现瓶颈并在该位置替换更快的算法,那么请执行此操作。只有在显然没有其他选择时才开始使用并发,然后仅在必要的地方去使用它。

速度问题一开始听起来很简单:如果你想要一个程序运行得更快,将其分解成碎片并在一个单独的处理器上运行每个部分。由于我们能够提高时钟速度流(至少对于传统芯片),速度的提高是出现在多核处理器的形式而不是更快的芯片。为了使你的程序运行得更快,你必须学会如何利用那些额外的处理器,这是并发性给你的一个建议
速度问题一开始听起来很简单:如果你想要一个程序运行得更快,将其分解为多个部分,并在单独的处理器上运行每个部分。随着我们提高时钟速度的能力耗尽(至少对传统芯片而言),速度的提高是出现在多核处理器的形式而不是更快的芯片。为了使程序运行得更快,您必须学会利用那些额外的处理器(译者注:处理器一般代表 CPU 的一个逻辑核心),这是并发所带来的好处之一
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要用敬词「您」
都改成你


但是,并发性通常可以提高在单个处理器上运行的程序的性能。这听起来有点违反直觉。如果考虑一下,由于上下文切换的成本增加(从一个任务更改为另一个任务),在单个处理器上运行的并发程序实际上应该比程序的所有部分顺序运行具有更多的开销。在表面上,将程序的所有部分作为单个任务运行并节省上下文切换的成本似乎更便宜
但是,并发性通常可以提高在单个处理器上运行的程序的性能。这听起来有点违反直觉。你会这么想,由于上下文切换的成本增加(从一个任务切换到另一个任务),在单个处理器上运行的并发程序实际上应该比程序的所有部分顺序运行具有更多的开销。表面上看,将程序的所有部分作为单个任务运行并节省上下文切换的成本似乎更低
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你会这么想。。这个翻译很突兀啊

完全看不懂这个想表达什么

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就是,你可能会怎么认为,单核并发似乎慢于单核顺序,但是阻塞让事情变得不一样了。
这里我没有完全按照英文的一起翻译


并发性会带来成本,包括复杂性成本,但可以通过程序设计,资源平衡和用户便利性的改进来抵消。通常,并发性使你能够创建更加松散耦合的设计;除此以外,你必须特别关注那些使用了并发操作的代码。
并发会带来各种成本,包括复杂性成本,但可以被程序设计,资源平衡和用户便利性方面的改进所抵消。通常,并发性使你能够创建更低耦合的设计;另一方面,你必须特别关注那些使用了并发操作的代码。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但可以被程序设计

难道不是原来的「以通过程序设计」的更好

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

被程序设计,资源负载均衡,和用户便利性,这些 改进 所抵消
被...所... 这是一个整体

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那你就用顿号。用逗号不就分成两个句子了么


这些格言专门针对 Java 的并发设计问题,尽管它们也可以适用于其他一些语言。但是,确实存在旨在防止这些问题的语言。

### 1.不要这样做
### 1.不要用它
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要用它是什么翻译

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要使用并发

咱们翻译过来就把英文字爱做的代词替换给明确化

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我之前有想过把它都替换成并发的。但是你看上下文这一小节的标题是关于Java并发的4句格言,然后再把每一条格言的它都替换成并发的话,可能有一点重复。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

也行吧


### 2.没有什么是真的,一切可能都有问题

没有并发性的编程,你会发现你的世界有一定的顺序和一致性。通过简单地将变量赋值给某个值,很明显它应该始终正常工作
不使用并发编程,你已经料到了你的世界具有确定的顺序和一致性。对于变量赋值这样简单的操作,很明显它应该总是能够正常工作
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经料到,和你会发现明显原翻译更好吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

简单或期望,更接近原文的意思

you’ve come to expect a certain order and consistency in your world.
你已经期望自己的世界有明确的顺序和一致性。

我把期望翻译为料到,意思就是,不用并发,可以很容易的想到是有顺序的并且是一致的


### 4.你必须仍然理解
### 4.你必须理解它
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种代词替换都把 并发带回来吧。要么这四句格言都贼奇怪

「你必须理解并发」这种翻译不是更好么


实现并发的直接方法是在操作系统级别,使用与线程不同的进程。进程是一个在自己的地址空间内运行的自包含程序。进程很有吸引力,因为操作系统通常将一个进程与另一个进程隔离,因此它们不会相互干扰,这使得进程编程相对容易。相比之下,线程共享内存和 I/O 等资源,因此编写多线程程序时遇到的困难是在不同的线程驱动的任务之间协调这些资源,一次不能通过多个任务访问它们
实现并发的一种简单方式是使用操作系统级别的进程。与线程不同,进程是在其自己的地址空间中运行的独立程序。进程的优势在于,因为操作系统通常将一个进程与另一个进程隔离,因此它们不会相互干扰,这使得进程编程相对容易。相比之下,线程之间会共享内存和 I/O 等资源,因此编写多线程程序最基本的困难在于协调不同线程驱动的任务之间对这些资源的使用,以免这些资源不会同时被多个资源访问
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「以免这些资源不会同时被多个资源访问」
应该是
「以免这些资源同时被多个资源访问」

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实有些语义重复


一些编程语言旨在将并发任务彼此隔离。这些通常被称为_函数式语言_,其中每个函数调用不产生其他影响(因此不能与其他函数干涉),因此可以作为独立的任务来驱动。Erlang 就是这样一种语言,它包括一个任务与另一个任务进行通信的安全机制。如果你发现程序的某一部分必须大量使用并发性并且你在尝试构建该部分时遇到了过多的问题,那么你可能会考虑使用专用并发语言创建程序的那一部分
一些编程语言被设计为将并发任务彼此隔离。这些通常被称为_函数式语言_,其中每个函数调用不产生副作用(不会干扰到其它函数),所以可以作为独立的任务来驱动。Erlang 就是这样一种语言,它包括一个任务与另一个任务进行通信的安全机制。如果发现程序的某一部分必须大量使用并发,并且在尝试构建该部分时遇到了过多的问题,那么可以考虑使用这些专用的并发语言创建程序的这个部分
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「一些编程语言被设计为将并发任务彼此隔离」被动语态转主动。

中文喜欢正着说

「一些编程语言旨在将并发任务彼此隔离」


因为这些主题太复杂,本章无法为你提供更专业的知识(再次参见 Java Concurrency in Practice),但你必须了解它们
因为这些主题太复杂,以至于本章无法为你提供更专业的知识(再次参见 Java Concurrency in Practice),但你必须意识到它们
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「但你必须意识到它们」

这个意识的含义很模糊啊。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you must be aware of them.
这整段说的都是并发编程的复杂性,然后又说我们避免不了它,所以结合上下文应该是说这一章没办法全面的介绍并发,但是你必须意识到这两点。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成「但你必须意识到并发编程的复杂性」吧

@sjsdfg sjsdfg merged commit 7dc616e into lingcoder:master Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants