Reactive Programming with RxJava,介绍一本书和Rx

Reactive Programming with RxJava,介绍一本书和Rx

标签(空格分隔): book RxJava


Who Should Read This Book

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语言,但却不必要熟悉响应式编程。
这本书中的很多概念涉及到了函数式编程,但是你同样不必要去掌握它。有两种程序员能够从中受益:

  • Craftsmen who seek improved performance on the server or more maintainable code on mobile devices. If you fal into this categroy, you will find ideas and solutions to real problems, you will find ideas and solutions to real problems as well as practical advice. In this case, RxJava is just another tool that this book will help to master.
  • 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.

  • 目标是在服务器和移动设备上提高性能或者更好的程序扩展性的工程师,如果你属于这类人,在本书中你能发现解决问题的办法以及实用的建议。本书讲帮你掌握这一工具。

  • 对流行起来的响应式编程或RxJava感兴趣并且希望有一个清晰的认识的人,如果你属于这类人,并且不准备将RxJava的优点应用在产品代码中。你可以显著的拓宽视野。

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 1 very briefly goes through the inception of RxJava, basic concepts, and ideas(Ben).
  • Chapter 2 explains how RxJava can appear in your application and how to interact with it. This chapter is very basic, but, but understanding concepts like hot versus cold sources is tremendously important(Tomasz).
  • Chapter 3 is a whirlwind tour of many operators provided by RxJava. We will introduce you to the expressive and powerful functions that are a foundation of this library(Tomasz).
  • Chapter 4 is more practical, showing how to embed RxJava in various places across your codebase. It also touches on concurrency(Tomasz).
  • Chapter 5 is advanced, explaining how to implement reactive applications from top to bottom.
  • Chapter 6 explains an important problem of flow control and backpressure mechainisms in RxJava that support it (Tomasz).
  • Chapter 7 shows techniques of unit testing, maintaining, and troubleshooting Rx-base applications(Tomasz).
  • Chapter 8 shows a few selected applications of RxJava, especially in distributed systems(Tomasz).
  • Chapter 9 highlights future plans for RxJava 2.x(ben).

  • 第一章简要介绍了RxJava的起步,基本概念,和想法。

  • 第二章阐述了如何将RxJava集成并运用在项目中,本章非常基础,同样理解如 动态编程和静态编程是风场重要的。
  • 第三章浏览了RxJava的很多操作符。我们会展示给你基于RxJava基础库强力有效的功能。
  • 第四章偏向与实战,展示了如何将RxJava的代码应用到你的代码中。RxJava同样样涉及并发。
  • 第五章是高级,阐述了如何将响应式程序应用到各个层面。
  • 第六章阐述了重要的流处理问题和RxJava支持的反压机制。
  • 第七章演示了RxJava程序如何进行单元测试,扩展和调试技术。
  • 第八章展示了使用RxJava的项目,特别是在分布式操作系统。
  • 第九章标注了第二版RxJava的功能概览。

CHAPTER 1 Reactive Programming with 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 and 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,被函数式编程影响,使用声明式编程避免典型的响应式编程的陷阱。

When You Need Reactive Programming

Reactive programming is useful in scenarios such as the following:

  • Processing use events such as mouse movement and clicks, keyboard typing, GPS signals changing over time as users move with their device, device gyroscope signals, touch events, and so on.
  • Responding to and processing any and all latency-bound IO events from disk or network, given that IO is inherently asynchronous(a request is made, time passes, a response might or might not be received, which the tiggers further work.
  • Handling events or data pushed at an application by a producer it cannot control(system events from a server, the aforementioned user events, signals from hardware, events triggered by the analog world from sensors, and so on).

响应式编程在下面的情景是适用的:

  • 处理用户事件,比如鼠标移动和点击,键盘编辑,GPS信号随着时间的变化当用户移动自己的设备,陀螺仪信号,触摸时间等等。
  • 响应和处理任何磁盘或网络相关的异步IO事件(执行一个请求,时间执行,一个响应可能或者不能被收到,然后继续执行下一步工作)。
  • 处理被程序生产者推出的不可控时间或者消息(服务器发出的系统消息,上面提到的用户事件,硬件信号,传感器模拟事件的触发等等)。

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如何工作。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值