标签(空格分隔): book RxJava
Reactive Programming with RxJava targets intermediate and advanced Java program-
mers. You should be fairly comfortable with Java; however, prior knowledge of reac-
tive programming is not required. Many concepts in this book relate to functional
programming, but you do not need to be familiar with it either. There are two distinct
groups of programmers that can benefit from this book;
RxJava的响应式编程适用于中高级Java工程师。你应该熟悉Java语言,但却不必要熟悉响应式编程。
这本书中的很多概念涉及到了函数式编程,但是你同样不必要去掌握它。有两种程序员能够从中受益:
Curious developers who’ve heard about reactive programming or RxJava in particular and want to get a fair understanding of it. If this is you, and if you are not planning to take advantage of RxJava in production code, you will significantly broaden your horizons.
目标是在服务器和移动设备上提高性能或者更好的程序扩展性的工程师,如果你属于这类人,在本书中你能发现解决问题的办法以及实用的建议。本书讲帮你掌握这一工具。
Additionally, if you are a hands-on software architect, this book will likely help you.
RxJava influences the overall architecture of entire systems, so it is worth knowing.
But even if you are just beginning your adventure with programming, try to go through the
first few chapters, which explain the basics. Underlying concepts like transformations and
composition are quite unversal and not related to reactive programming.
除此之外,如果你是一个软件架构师,这本书可能会帮助到你。RxJava以及影响到了整个软件架构,这是值得学习的。但是如果你刚刚开始编程的道路,尝试阅读基础的前几章。基本的概念比如转换和组合是通用的概念和响应式编程没有关系。
The book was struvtured such that you will derive the most from it by reading it from cover
to cover. If you can not afford that much time, however, fell free to cherry pick only the parts that are most insteresting. If there s a concept that was introduced earlier, you will most likely find a back reference to it. Following is an overview of each chapter:
这本书是循序渐进的,顺序阅读你可以掌握大部分。如果你没有充足的时间,也可以自由的选择感兴趣的部分。如果存在前文的概念,你可以到前文寻找。下面是章节概览。
Chapter 9 highlights future plans for RxJava 2.x(ben).
第一章简要介绍了RxJava的起步,基本概念,和想法。
RxJava is a specific implementation of reactive programming for Java and Android that is influenced by functional programming. It favors function composition, avoidance of global state and side effects, and thinking in streams to compose asynchronous and event-base programs. It begins with the observer pattern of producer/consumer callbacks and extends it with dozens of operators that allow composing, transforming, scheduling, throttling, error handling, and lifecycle management.
RxJava is a mature open source library that has found broad adoption both on the server and on Android mobile devices. Alone with the library, an active community of developers has built up around RxJava and reactive programming to contribute to the project, speak, write, and help one another.
This chapter will provide an overview of RxJava-what it is and how it works-and the rest of this book wull take you through all the details of how to use and apply it in your applications You can begin reading this book with no piror experience with reactive programming, but we will start at the beginning and take you through the concepts and practices of RxJava so that you can apply its strengths to your use cases.
RxJava被函数式编程的影响,是响应式编程针对Java和Android的一种具体实现。支持函数式编程,规避了全局变量和负面影响,并且以流的形式去编写异步的,事件型驱动编程模式。RxJava以生产者/消费者回调的观察者模式开始,并扩展了数十个允许编写,转换,调度,限制,错误处理和生命周期管理的运算符。
RxJava是一个成熟的开源库,已经在服务器和Android设备得到了广泛的应用,围绕RxJava,响应式编程 一个活跃的开发者社区已经被建立起来,提供项目,交流,写作和互相帮助。
本章提供了RxJava的概览-是什么,如何工作,其余部分介绍了如何应用到项目的详细介绍。你可以在没有响应式编程的经验,我们从头开始会为你讲解RxJava的概念和实例以便可以将其优势应用在你的项目当中。
Reactive programming is a general programming term that is focused on reacting to changes, such as data values or events. It can and often is done imperatively. A callback is an approach to reactive programming done imperatively. A spreadsheet is great example of reactive programming: cells dependent on other cells automatically “react” when those other cells change.
响应式编程是一种面向变化传播编程范式,例如数据值或者事件。经常以命令式的完成,通过回调完成响应式编程。电子表格就是非常好的响应式编程的例子:表格根据其他表格的变化而’变化’。
On today’s computers everything ends up being imperative at some point as it hits the operating system and hardware. The computer must be told explicitly whtat needs to be done and how to do it. Hunmans do not think like CPUs and related systems, so we add abstractions. Reactive-functional programming is an abstraction, just like our higher-level imperative programming idioms are abstractions for the underlying binary and assembly instructions. The fact that everything ends up imperative is important to remember and understand because it helps us with the mental model of what reactive-functional programming is addressing and how it ultimately executes-there is no magic.
现代的计算机在某一时刻会将运行在操作系统和硬件上的所有的东西命令化。计算机必须被确切的告知么,如何去做。人类的思维不同于CPUs和操作系统,因此我们增加抽象。响应式编程是一种抽象,类似于我们更高层次的命令式编程是底层二进制和汇编语言的抽象。事实上,所有最终都是指令,记住和理解是非常重要的,他可以帮助你建立响应式编程范式是如何寻址和最终的指令没有魔法。
Reactive-functional programming therefore is an approach to programming-an abstraction on top of imperative systems-that allows us to program asynchronous and event-driven use cases without having to think like the computer itself and imperatively define the complex interactions of state, particularly across thread and network boundaries. Not having to think like the computer is a useful trait when it comes to asynchrony and event-driven systems, because concurrency and parallelism are involved, and these are very challenging characteristics to use correctly and efficiently. Within the Java community, the boooks Java Concurrency in Practive by Brian Goetz and Concurrent Programming in Java by Doug Lea(Addison-Wesley), and forums, and communities since I started using RxJava has convinced me even more than before of how difficult it really is to write high-performance, efficient, scalable, and correct concurrent software. And we haven’t been brought in distributed systems, which take concurrency and parallelism to another level.
响应式函数式编程是一种在命令式编程系统之上的抽象,他允许我们异步和事件驱动编程,而不必考虑计算机本身和命令式编程在状态交互,特别是跨线程和网络编程。因为并发和并行涉及到异步和事件驱动系统,所以不必像电脑一样去思考如何实现,正确有效的使用非常具有挑战性。自从我开始使用Rxjava,比以前更加相信在Java论坛,书籍《Java并发性》和《Java并发编程》和一些论坛,社区中,编写高性能,可扩展和正确的并发软件真的是很困难。我们还没有进入分布式系统,它将并发和并行提升到另一个层次上。
So, the short answer to what reactive-functional programming is solving is concurrency and parallelism. More colloquially, it is solving callback hell, which results from addressing reactive and asyncronous use cases in an imperative way. Reactive programming such as that implemented by RxJava is influenced by functional programming and uses a declarative approach to avoiding the typical pitfalls of reactive-imperative code.
所以,简要的说,响应式函数式编程就是解决了并发和并行。更通俗的说,它解决了结果返回通过寻址和命令式的异步编程的回调地狱。响应式编程范式比如RxJava,被函数式编程影响,使用声明式编程避免典型的响应式编程的陷阱。
Reactive programming is useful in scenarios such as the following:
响应式编程在下面的情景是适用的:
Now, if the code in question is handling only on event stream, reactive-imperative programming with a callback is going to be fine, and bringing in reactive-functional programming is not going to give you much benefit. You can have hundreds of different event streams, and if they are all completed indendent of one another, imperative programming is not likely to be a problem. In such straightforward use cases, imperative approaches are going to be the most efficient because they eliminate the abstraction layer of reactive programming and stay closer to that for which current operating systems, languages, and compilers are optimized.
现在,如果所涉及处理事件流的代码,带有回调的响应式编程很不错,但是响应函数式编程并不会给你带来太多好处。你可以拥有数百个不同的事件流并且他们都是独立完成的,命令式编程不会有问题。在这种直接的情况下,命令式的编程时最有效的,因为他们没有响应式编程的抽象层并且容易被操作系统,语言和编译器优化。
If your program is like most through, you need to combine events(or asynchronous responses from functions or network calls), have conditional logic interacting between them, and must handle failure scenarios and resouce cleanup on any and all of them. This is where the reactive-imperative approach begins to dramatically increase in complexity and reactive-functional programming begins to shine. A nonscientific view I have come to accept is that reactive-functional programming has an initially heigher learning curve and barrier to entry but that the ceiling for complexity is far lower than with reactive-imperative programming.
如果你的程序是顺序的编程,你需要合并事件(或者来自函数和网络请求的异步响应),具有条件逻辑交互,而且必须处理失败的场景并且对其中任何一个进行清理。这时响应式编程范式开始急剧的复杂起来,但响应式函数式编程开始绽放光芒。我开始接受一个非科学的观点,响应式函数式编程有更高的起步曲线和入门的困难,但是编程难度比响应式编程要小很多。
Hence this is where the tagling fo Reactive Extensions(Rx) in general and RxJava specifically comes from, “a library for composing asynchronous and event-based programs”. RxJava is a concrete implementation of reactive programming principles influenced by functional and data-flow programming. There are different approaches to be “reactive,” and RxJava is but one of them. Let’s dig into how it works.
因此,Rx系列有一个总的标语,“一个为异步和事件编程的库”。RxJava是一个被函数式和数据流编程影响的响应式编程范式的具体实现。和”一般响应式“有一些实现的区别,但是RxJava属于其分支,让我们看看RxJava如何工作。