0% found this document useful (0 votes)
30 views52 pages

Frontend Reactive Architectures Explore The Future of The Frontend Using Reactive Javascript Frameworks and Libraries 1st Edition Luca Mezzalira Download

The document is about the book 'Frontend Reactive Architectures' by Luca Mezzalira, which explores the future of frontend development using reactive JavaScript frameworks and libraries. It covers various programming paradigms, architectures, and specific frameworks like Angular, React, and MobX, providing insights into reactive programming principles. The book aims to equip developers with the knowledge to build scalable and efficient web applications using reactive programming techniques.

Uploaded by

hristiabire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views52 pages

Frontend Reactive Architectures Explore The Future of The Frontend Using Reactive Javascript Frameworks and Libraries 1st Edition Luca Mezzalira Download

The document is about the book 'Frontend Reactive Architectures' by Luca Mezzalira, which explores the future of frontend development using reactive JavaScript frameworks and libraries. It covers various programming paradigms, architectures, and specific frameworks like Angular, React, and MobX, providing insights into reactive programming principles. The book aims to equip developers with the knowledge to build scalable and efficient web applications using reactive programming techniques.

Uploaded by

hristiabire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Frontend Reactive Architectures Explore The

Future Of The Frontend Using Reactive Javascript


Frameworks And Libraries 1st Edition Luca
Mezzalira download
https://ebookbell.com/product/frontend-reactive-architectures-
explore-the-future-of-the-frontend-using-reactive-javascript-
frameworks-and-libraries-1st-edition-luca-mezzalira-52953570

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Frontend Development With Aspnet Core Angular And Bootstrap 1st


Edition Simone Chiaretta

https://ebookbell.com/product/frontend-development-with-aspnet-core-
angular-and-bootstrap-1st-edition-simone-chiaretta-53645870

Frontend Development Projects With Vuejs Learn To Build Scalable Web


Applications And Dynamic User Interfaces With Vue 2 Raymond Camden
Hugo Di Francesco Clifford Gurney Philip Kirkbride Maya Shavin

https://ebookbell.com/product/frontend-development-projects-with-
vuejs-learn-to-build-scalable-web-applications-and-dynamic-user-
interfaces-with-vue-2-raymond-camden-hugo-di-francesco-clifford-
gurney-philip-kirkbride-maya-shavin-23268256

Frontend Tooling With Gulp Bower And Yeoman Not True Pdf 1st Edition
Stefan Baumgartner

https://ebookbell.com/product/frontend-tooling-with-gulp-bower-and-
yeoman-not-true-pdf-1st-edition-stefan-baumgartner-24680268

Frontend Developer Bcs Guides To It Roles Dominic Myers

https://ebookbell.com/product/frontend-developer-bcs-guides-to-it-
roles-dominic-myers-33362702
Frontend Vision And Multiscale Image Analysis Multiscale Computer
Vision Theory And Applications Written In Mathematics 1st Edition Prof
Dr Bart M Ter Haar Romeny Auth

https://ebookbell.com/product/frontend-vision-and-multiscale-image-
analysis-multiscale-computer-vision-theory-and-applications-written-
in-mathematics-1st-edition-prof-dr-bart-m-ter-haar-romeny-auth-4290726

Frontend Architecture A Modern Blueprint For Scalable And Sustainable


Design Systems 1 Early Release Micah Godbolt

https://ebookbell.com/product/frontend-architecture-a-modern-
blueprint-for-scalable-and-sustainable-design-systems-1-early-release-
micah-godbolt-5207824

Front End Drupal Designing Theming Scripting 1st Edition Konstantin


Kafer

https://ebookbell.com/product/front-end-drupal-designing-theming-
scripting-1st-edition-konstantin-kafer-1272948

Front End Drupal Designing Theming Scripting 1st Edition Konstantin


Kafer

https://ebookbell.com/product/front-end-drupal-designing-theming-
scripting-1st-edition-konstantin-kafer-1338250

Frontend Development Projects With Vuejs Learn To Build Scalable Web


Applications And Dynamic User Interfaces With Vue Raymond Camden

https://ebookbell.com/product/frontend-development-projects-with-
vuejs-learn-to-build-scalable-web-applications-and-dynamic-user-
interfaces-with-vue-raymond-camden-22152720
Front-End Reactive
Architectures
Explore the Future of the Front-End
using Reactive JavaScript Frameworks
and Libraries

Luca Mezzalira
Front-End Reactive
Architectures
Explore the Future of the Front-End
using Reactive JavaScript
Frameworks and Libraries

Luca Mezzalira
Front-End Reactive Architectures
Luca Mezzalira
London, Surrey, United Kingdom

ISBN-13 (pbk): 978-1-4842-3179-1 ISBN-13 (electronic): 978-1-4842-3180-7


https://doi.org/10.1007/978-1-4842-3180-7
Library of Congress Control Number: 2017964608
Copyright © 2018 by Luca Mezzalira
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Louise Corrigan
Development Editor: James Markham
Technical Reviewers: Antonio DeLuca and Massimo Nardone
Coordinating Editor: Nancy Chen
Copy Editor: Karen Jameson
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street,
6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-
sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member
(owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a
Delaware corporation.
For information on translations, please e-mail [email protected], or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484231791. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
To my Dad.
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� ix

About the Technical Reviewers������������������������������������������������������������������������������� xi


Acknowledgments������������������������������������������������������������������������������������������������� xiii

Chapter 1: What Is Reactive Programming?������������������������������������������������������������� 1


What Is Reactive Programming?��������������������������������������������������������������������������������������������������� 2
Programming Paradigms�������������������������������������������������������������������������������������������������������������� 6
Imperative Programming �������������������������������������������������������������������������������������������������������� 6
Functional Programming �������������������������������������������������������������������������������������������������������� 7
Reactive Programming ��������������������������������������������������������������������������������������������������������� 11
When Should You Use Reactive Programming?�������������������������������������������������������������������������� 16
How Should You Write an Application Fully Reactive?���������������������������������������������������������������� 17

Chapter 2: Architectures Comparison�������������������������������������������������������������������� 19


MV* Architectures����������������������������������������������������������������������������������������������������������������������� 21
Model View Control���������������������������������������������������������������������������������������������������������������� 22
Model View Presenter������������������������������������������������������������������������������������������������������������ 28
Model View View-Model�������������������������������������������������������������������������������������������������������� 35
JavaScript Frameworks�������������������������������������������������������������������������������������������������������������� 40
Angular���������������������������������������������������������������������������������������������������������������������������������� 41
Ember������������������������������������������������������������������������������������������������������������������������������������ 50
React + Redux����������������������������������������������������������������������������������������������������������������������� 56
Wrap-Up�������������������������������������������������������������������������������������������������������������������������������� 64

v
Table of Contents

Chapter 3: Reactive Programming������������������������������������������������������������������������� 65


Reactive Programming 101�������������������������������������������������������������������������������������������������������� 66
Observer Pattern������������������������������������������������������������������������������������������������������������������������� 68
Iterator Pattern���������������������������������������������������������������������������������������������������������������������������� 69
Putting the Code into Practice���������������������������������������������������������������������������������������������������� 70
Stream Implementations������������������������������������������������������������������������������������������������������������� 71
Rx.JS������������������������������������������������������������������������������������������������������������������������������������������� 71
Hot and Cold Observables����������������������������������������������������������������������������������������������������� 77
Cold Observables������������������������������������������������������������������������������������������������������������������� 78
Hot Observables�������������������������������������������������������������������������������������������������������������������� 80
XStream��������������������������������������������������������������������������������������������������������������������������������� 82
Back Pressure����������������������������������������������������������������������������������������������������������������������������� 90
Wrap-Up�������������������������������������������������������������������������������������������������������������������������������������� 95

Chapter 4: Cycle.js and MVI������������������������������������������������������������������������������������ 97


Introduction to Cycle.js��������������������������������������������������������������������������������������������������������������� 97
Structuring a Simple Cycle.js Application����������������������������������������������������������������������������������� 99
Model View Intent Architecture������������������������������������������������������������������������������������������������� 110
Cycle.js and State Management����������������������������������������������������������������������������������������������� 117
Wrap-Up������������������������������������������������������������������������������������������������������������������������������������ 127

Chapter 5: MobX: Simple State Management������������������������������������������������������� 129


Introduction to MobX����������������������������������������������������������������������������������������������������������������� 129
Our First Application with MobX and React������������������������������������������������������������������������������ 133
Examining the Folder Structure������������������������������������������������������������������������������������������� 136
MobX State Tree������������������������������������������������������������������������������������������������������������������ 149
Wrap-Up������������������������������������������������������������������������������������������������������������������������������������ 158

vi
Table of Contents

Chapter 6: SAM: A Functional Reactive Pattern��������������������������������������������������� 159


Introduction to SAM������������������������������������������������������������������������������������������������������������������ 160
SAM Pattern Data Flow�������������������������������������������������������������������������������������������������������� 162
A Basic Implementation of SAM������������������������������������������������������������������������������������������������ 165
Reviewing the Example������������������������������������������������������������������������������������������������������� 166
Wrap-Up������������������������������������������������������������������������������������������������������������������������������������ 173

Chapter 7: A Reactive Future�������������������������������������������������������������������������������� 175


Ben Lesh���������������������������������������������������������������������������������������������������������������������� 176
Michel Weststrate��������������������������������������������������������������������������������������������������������������������� 178

Index��������������������������������������������������������������������������������������������������������������������� 183

vii
About the Author
Luca Mezzalira is a System Architect with 15 years
of experience, a Google Developer Expert on Web
Technologies, and the London Javascript community
Manager (www.londonjs.uk).
He had the opportunity to work on cutting-edge projects
for mobile, desktop, web, TVs, set-top boxes, and embedded
devices.
He is also an international speaker on Tech conferences
with over 100 talks made in less than 10 years.
Luca thinks the best way to use any programming language is mastering their
models; that’s why he spends a lot of time researching topics such as OOP, Functional
and Reactive programming.
With these skills, Luca can easily apply the best practices learned and drive any team
to success.
He is also a natural leader, delivery focused, a problem solver, and a game changer;
his passion is the driver for any activity, and he’s able to make the difference in many
circumstances.
In his spare time, Luca writes for national and international technical magazines
and editors, and he’s a technical reviewer for Apress, Manning Publications, Packt
Publishing, Pragmatic Bookshelf, and O’Reilly.

ix
About the Technical Reviewers
Antonio DeLuca is a fanatic of minimalist software development, accurate database
design, and meticulous business analysis. He is focused on functional/object paradigms
and service orientation. He has worked in various contexts and levels developing
applications for the Web as well as other purposes with JavaScript/PHP, Java/C#, and
other programming languages. He is based in London and is the Principal Software
Developer at DAZN (a division of Perform Group).

Massimo Nardone has more than 23 years of experiences


in Security, Web/Mobile development, Cloud, and IT
Architecture. His true IT passions are Security and Android.
He has been programming and teaching how to program
with Android, Perl, PHP, Java, VB, Python, C/C++, and
MySQL for more than 20 years.
He holds a Master of Science degree in Computing
Science from the University of Salerno, Italy.
Massimo has worked as a Project Manager, Software
Engineer, Research Engineer, Chief Security Architect,
Information Security Manager, PCI/SCADA Auditor, and Senior Lead IT Security/Cloud/
SCADA Architect for many years.
Technical skills include the following Security, Android, Cloud, Java, MySQL, Drupal,
Cobol, Perl, Web and Mobile development, MongoDB, D3, Joomla, Couchbase, C/C++,
WebGL, Python, Pro Rails, Django CMS, Jekyll, Scratch, etc.
He worked as visiting lecturer and supervisor for exercises at the Networking
Laboratory of the Helsinki University of Technology (Aalto University). He holds four
international patents (PKI, SIP, SAML, and Proxy areas).
Currently he currently works as Chief Information Security Office (CISO) for
Cargotec Oyj and he is a member of the ISACA Finland chapter board.
Massimo has reviewed more than 40 IT books for different publishing companies
and is the coauthor of Pro Android Games (Apress, 2015).

xi
Acknowledgments
I’d like to thank so many people that probably they wouldn’t fit in just a page!
I think the most important one to mention though is my girlfriend Maela that is
always here for me and she is the key to our family happiness.
Sometimes inspirations come in strange ways. I once read the story of the UFC
champion Conor McGregor: he is really an interesting guy, sometimes with an
overwhelming personality, but I think it is part of the role or mask he decided to wear.
McGregor made me think when I read this sentence:

“There’s no talent here, this is hard work. This is an obsession. Talent does not exist,
we are all equal as human beings. You could be anyone if you put in the time. You will
reach the top, and that is that. I am not talented, I am obsessed.”

To be honest, I totally agree. Everyone can be who he or she wants to be; it’s hard and
often we can be nearly there for giving up a dream, but our obsessions could really make
the difference from failing to succeeding.
Several years ago, I would have never thought I’d be able to write an entire book in
English and succeeding as a Software Architect outside my country – apparently my
obsessions won.

xiii
CHAPTER 1

What Is Reactive
Programming?
A journey of a thousand miles begins with a single step.
—Lao Tzu, Tao Te Chang

Have you ever heard about Reactive Programming or Reactive Systems? Do you think
React.js is a reactive library? Have you ever thought about why you should use Rx.JS
inside an Angular project? Is Rx.JS the new Loadash?
If at least one of these questions is often in your mind, this is exactly the right book to
find an answer!
In these pages you will have a chance to learn more about reactive programming
and reactive architecture for front-end development: a programming paradigm that
is becoming more popular, every day, in the front-end community; but these days it is
probably one of the most misunderstood and abused paradigm.
The main goal of this book is to provide a good understanding of what reactive
programming is, how to use it in our projects, and particularly how to create fully
reactive architectures for creating resilient and maintainable projects.
During this journey you will learn the following:

• What Reactive Programming is and why it’s important

• What are the best use cases of this programming paradigm

• How to structure a fully Reactive architecture with different


frameworks

• What will be the future of Reactive Programming on the front-end


ecosystem

1
© Luca Mezzalira 2018
L. Mezzalira, Front-End Reactive Architectures, https://doi.org/10.1007/978-1-4842-3180-7_1
Chapter 1 What Is Reactive Programming?

If you are wondering if the concepts learned inside this book are applicable also on a
back-end architecture, my answer would be YES, or at least, the majority of them could be
applied to your back-end architecture too.
Bear in mind that this book will focus the attention on front-end architectures with
JavaScript, but some of the concepts illustrated should be easily portable to other back-­
end programming languages such as Node.js, for instance.
This book assumes that you already have good understanding of JavaScript, in
particular ECMAScript 6 and 7 syntax; object-oriented programming; and possibly some
knowledge of functional programming, but it’s not mandatory. Let the journey begin!

What Is Reactive Programming?


Every day when we open an editor or IDE to develop a program, we use our favorite
programming language; sometimes we study a new one, but, consciously or
unconsciously, we are making the decision of what kind of programming paradigm we
are going to work with.
Reactive programming is not a new paradigm: it’s one of the buzzwords we are used
to hearing about in the JavaScript community in the past year or so, and it will become
more than just a buzzword in the future.
I don’t want to begin immediately by using too many technical terms because we will
have enough time to learn about them while reading this book, but it’s important that
you understand what is the benefit of working in a “reactive way.”
If you read blog posts or articles on the Web, few of them are going to explain reactive
programming with the spreadsheet cells example, where spreadsheet cells are reacting
to changes happening in other cells after user input. This is definitely a good example
but we can do better than this.
I’m sure you are familiar with the dependency injection pattern where an object
is injected via the constructor or in a public method exposed by a class or module.
This pattern leverages several benefits like decoupling between two objects and the
possibility of testing the hosting object in isolation without creating dependencies and
so on.
In some programming languages when we use dependency injection we are going to
define an interface as function’s argument in the hosting object and then we can interact
with the methods available in the injected object.

2
Chapter 1 What Is Reactive Programming?

The injected object in this case is used as an interactive object, because the host
knows exactly what the contract is and how to use it.
In reactive programming instead, the hosting object will just subscribe to the injected
one, and it will react to the propagation of changes during the application lifetime.
See Figure 1-1.

Figure 1-1. Interactive vs. Reactive programming: in Reactive Programming the


producer is A and the consumer is B

Looking at the image above, we can immediately grasp the main difference between
the two approaches:
• In the interactive example, object A is aware of which methods to
call because knows exactly the B’s object contract, also if we have to
understand who has affected the state of the ingested object, we will
search across all the projects that we are interacting with.
• In the reactive one, the contract is standard and object A is reacting
to changes happened in object B, on top we are certain that any
manipulation would occur inside the injected object; therefore we
will have a stronger separation of concerns between objects.
• Because the hosting object is reacting to any value propagated inside
the object injected, our program will be up to date without the need
for implementing any additional logic.
3
Chapter 1 What Is Reactive Programming?

It’s time for a simple example before we move ahead with other concepts.
Let’s assume we have a class called Calculator with a method sum and a class
Receipt with a method print as shown in Listing 1-1.

Listing 1-1. Check Snippet1.js

class Calculator {
  sum(a, b){
    return a + b;
  }
}

class Receipt {
  constructor(calculator){
    this.calc = calculator;
  }
  print(itemA, itemB){
    const total = this.calc.sum(itemA, itemB);
    console.log(`total receipt £${total}`);
  }
}

const pizza = 6.00;


const beer = 5.00;

const calc = new Calculator();


const receipt = new Receipt(calc);

receipt.print(pizza, beer);

As you can imagine, the program outputs “total receipt £11.”


What we are doing in this example is creating the Calculator object and a Receipt
object, and then we inject the Calculator instance called calc and we call the method
print from the receipt instance with few arguments.
Inside the print method we are writing in the console the total price of the elements
passed.
Checking the Receipt class implementation, you can spot in the print method that
we are interacting with the method sum of the Calculator class and then getting the final
result.

4
Chapter 1 What Is Reactive Programming?

Now let’s try to implement the same example in a reactive way in Listing 1-2.

Listing 1-2. Check Snippet2.js

class Calculator {
  constructor(itemA, itemB){
    const obs = Rx.Observable.of(itemA, itemB);
    const sum$ = obs.reduce((acc, item) => (acc + item));

    return {
      observable: sum$
    }
  }
}

class Receipt {
  constructor(observable$){
    observable$.subscribe(value => console.log(`total receipt: £${value}`))
  }

const pizza = 6.00;


const beer = 5.00;

const calc = new Calculator(pizza, beer);


const receipt = new Receipt(calc.observable);

As you can see in this example, the Receipt class is subscribing to an object called
observable, injected via the constructor, and all the logic of how to sum the prices
and propagate them is delegated to the Calculator class. Therefore, the Receipt class
is just reacting to a change, happening in a certain moment of the program’s lifetime,
displaying in the console the value emitted by the Calculator instance.
Another thing to highlight here is the contract between the objects: instead of
knowing exactly what method we should call, we pass an, with a default contract, and we
react when something changes inside it.
Overall, it’s a very simple example but I hope it helps you to understand the shift of
mindset we are going to have when we work with reactive programming; in the next few
chapters we will see more reactive examples like this one.

5
Chapter 1 What Is Reactive Programming?

Programming Paradigms
It’s time to spend some words on programming paradigms to shed some light on reactive
concepts and comparing them with functional and imperative programming.

Imperative Programming
Imperative programming is probably one of the most well-known programming paradigms.
Often, it’s the first paradigm that we learn for understanding how a computer
elaborates a program: it gives us all the tools for defining implementation details in
depth and specifying exactly how a program should behave step by step.
Let’s see an example of imperative programming:

class Calculator {
  constructor(){
    this.VAT = 22;
  }
  sum(...items){
    let total = 0;
    let i = 0;
    for(i; i < items.length; i++){
      total = total + items[i];
      total = total + items[i] * this.VAT/100;
    }
    return total;
  }
}

class Receipt {
  constructor(calculator){
    this.calc = calculator;
  }
  print(...items){
    let total = this.calc.sum(...items);
    console.log(`total receipt £${total.toFixed(2)}`);
  }
}
6
Chapter 1 What Is Reactive Programming?

const JEANS = 80.00;


const SHIRT = 35.00;
const SHOES = 90.00;
const COAT = 140.00;
const HAT = 29.00;

const calc = new Calculator();


const receipt = new Receipt(calc);

receipt.print(JEANS, SHIRT, SHOES, COAT, HAT); //"total receipt £456.28"

Similar to the example discussed before, the sum method of the calculator object is
accepting multiple arguments instead of just a couple, and we are summing all of them
and applying the VAT value calculated per item.
As you can see, we are describing the exact implementation we want to perform:
from defining a for statement in order to iterate trough the values in the array until
expressing the VAT calculation for each single item.
Basically what we are doing is focusing on any implementation detail; potentially we
could change the way we were iterating through the array’s elements and start from the
last element in the array instead of the first one or use a different variable name from “i”;
these are the levels of detail we usually handle with imperative programming.
Now it’s time to see how this example would be handled in functional and reactive
programming.

Functional Programming
Functional programming is getting more famous on a daily base. Many languages arise
embracing this paradigm and many existing languages are embracing it too for the
readability, maintainability, and testability improvements.
If you are asking yourself why Functional Programming is becoming so popular, the
answer can be found behind the concepts of this paradigm.
When we talk about Functional Programming we are talking about functions: in
particular we are talking about pure functions.
A pure function is a function that, given an argument, is always returning the same
result; it’s predictable, easy to test, and doesn’t generate any side effect inside the program.
Another important topic related to functional programming is the concept of
immutability.

7
Chapter 1 What Is Reactive Programming?

Immutability means that a specific value won’t ever change during its life cycle, but
if we need to manipulate it, we will create a new instance that contains the manipulated
version of the original object.
Even if you are not familiar with this concept or have never dealt with it, I want you to
see at least one concrete example.
Usually when you are dealing with an array and you want to iterate trough the values
and interact with them in an imperative programming way, you would write something
like this:

const originalArray = [1, 4, 8, 12];

for(let i = 0; i < originalArray.length; i++){


  originalArray[i] = originalArray[i] + 1;
}

console.log(originalArray) //[2, 5, 9, 13]

At this stage we have completely lost the initial values of the array called
originalArray; if we want to have a copy of the initial values, we would create a new array
that contains the modified values and then we would check that one.
In functional programming, instead, we are working by default with immutable
objects; therefore, every modification we need to apply won’t affect the original value
but will generate a new one.
Taking into consideration the previous example, we could write in a functional
programming way like this:

const originalArray = [1, 4, 8, 12];


const finalArray = originalArray.map(value => value+1);
console.log(finalArray); //[2, 5, 9, 13]

As you can see from these simple examples, functional programming is focused on
what you are trying to achieve more than its implementation details.
That’s a fundamental distinction compared to imperative programming. In fact, with
functional programming we are describing our program, focusing on each action; and
we need to do describe the data flow of our program more than focusing on each single
detail such as which variable we have to define for iterating an array or how to increment
the variable inside the for statement.
Another important aspect of software programming is how to deal with state
management.
8
Chapter 1 What Is Reactive Programming?

In Object-Oriented Programming we are used to encapsulating a state inside an


object and changing it via different methods described in the same object. But in
functional programming we are trying to compose it via pure functions that accept as the
argument a state and return a new state.
Redux (http://redux.js.org/), a very well-known library in the React community,
aims to resolve the problem of state management by implementing a state machine pattern.
In Redux, when we want to change the application state, we will need to call a
method that accepts two arguments: the previous application state and an action. And it
is returning the new state without mutating the previous one.

An Action is a simple object used for identifying in which state the application
should transform.

Relying to pure functions will make our code more modular and more reusable, will
create less bugs, and will suddenly become more testable!
Let’s try now to convert the previous imperative example, porting it to functional
programming. See Listing 1-3.

Listing 1-3. Check Snippet3.js


class Calculator {
  getTotal(...items){  
    const total = items.map(::this.addVAT)
                     .reduce(this.sumElements);
    return total;
  }
  addVAT(itemValue){
    return itemValue + this.calculateVAT(itemValue);
  }
  calculateVAT(value){
    const VAT = 22;
    return value * VAT/100;
  }
  sumElements(accumulator, value){
    return accumulator + value
  }
}
9
Chapter 1 What Is Reactive Programming?

class Receipt {
  print(total){
    console.log(`total receipt £${total.toFixed(2)}`);
  }
}

const JEANS = 80.00;


const SHIRT = 35.00;
const SHOES = 90.00;
const COAT = 140.00;
const HAT = 29.00;

const calc = new Calculator();


const receipt = new Receipt();

receipt.print(calc.getTotal(JEANS, SHIRT, SHOES, COAT, HAT)); // "total


receipt £456.28"

As we can see in the sum method implementation, we are focusing more on the
actions we want to implement more than how to apply them; therefore, first we know
that we need to calculate the VAT value for each single element (map method) and then
to sum the items for retrieving the total (reduce method).
In this implementation we don’t need to specify how we are iterating through the
array elements or specifying variables to keep the state of the iteration; we just focus on
our goal.
Another thing to notice in this implementation is how we are using functions as an
argument of other functions; this mechanism is called high-order functions and it is
another cornerstone of Functional Programming.
Obviously, Functional Programming is not just that: it is a broad topic with many
other patterns to take in consideration like currying, practical application, memoization,
and so on, but this is not the main topic of the book.
Bear in mind these concepts and possibly read a few posts online regarding them
for mastering the different implementations because being familiar with Functional
Programing will allow you to embrace Reactive Programming more easily.
If you are not used to thinking functionally, I strongly suggest peaking at a book that
describes this paradigm in your favorite language; it’s a great time investment, and you
won’t regret it.

10
Random documents with unrelated
content Scribd suggests to you:
upon the domain of private life. Expostulation and active warfare,
however, are equally useless. The carpenter-ant has no moral sense,
and is not amenable either to kindness or blows. On one occasion,
when a body of these intrusive creatures had constructed an
absurdly conspicuous brown gallery straight across the ceiling of my
drawing-room, I determined to declare open war against them, and
getting my black servant to bring in the steps and a mop, I
proceeded to demolish the entire gallery just after breakfast. It was
about twenty feet long, as well as I can remember, and perhaps an
inch in diameter. At one o'clock I returned to lunch. My black servant
pointed, with a broad grin on his intelligent features, to the wooden
ceiling. I looked up: in those three hours the carpenter-ants had
reconstructed the entire gallery, and were doubtless mocking me at
their ease, with their uplifted antennæ, under that safe shelter. I
retired at once from the unequal contest. It was clearly impossible to
go on knocking down a fresh gallery every three hours of the day or
night throughout a whole lifetime.
Ants, says Mr. Wallace, without one touch of satire, “force
themselves upon the attention of everyone who visits the tropics.”
They do, indeed, and that most pungently; if by no other method, at
least by the simple and effectual one of stinging. The majority of
ants in every nest are of course neuters, or workers, that is to say,
strictly speaking, undeveloped females, incapable of laying eggs. But
they still retain the ovipositor, which is converted into a sting, and
supplied with a poisonous liquid to eject afterwards into the wound.
So admirably adapted to its purpose is this beautiful provision of
nature, that some tropical ants can sting with such violence as to
make your leg swell and confine you for some days to your room;
while cases have even been known in which the person attacked has
fainted with pain, or had a serious attack of fever in consequence. It
is not every kind of ant, however, that can sting; a great many can
only bite with their little hard horny jaws, and then eject a drop of
formic poison afterwards into the hole caused by the bite. The
distinction is a delicate physiological one, not much appreciated by
the victims of either mode of attack. The perfect females can also
sting, but not, of course, the males, who are poor, wretched, useless
creatures, only good as husbands for the community, and dying off
as soon as they have performed their part in the world—another
beautiful provision, which saves the workers the trouble of killing
them off, as bees do with drones after the marriage flight of the
queen bee.
The blind driver-ants of West Africa are among the very few species
that render any service to man, and that, of course, only incidentally.
Unlike most other members of their class, the driver-ants have no
settled place of residence; they are vagabonds and wanderers upon
the face of the earth, formican tramps, blind beggars, who lead a
gipsy existence, and keep perpetually upon the move, smelling their
way cautiously from one camping-place to another. They march by
night, or on cloudy days, like wise tropical strategists, and never
expose themselves to the heat of the day in broad sunshine, as
though they were no better than the mere numbered British Tommy
Atkins at Coomassie or in the Soudan. They move in vast armies
across country, driving everything before them as they go; for they
belong to the stinging division, and are very voracious in their
personal habits. Not only do they eat up the insects in their line of
march, but they fall even upon larger creatures and upon big
snakes, which they attack first in the eyes, the most vulnerable
portion. When they reach a negro village the inhabitants turn out en
masse, and run away, exactly as if the visitors were English explorers
or brave Marines, bent upon retaliating for the theft of a knife by
nobly burning down King Tom's town or King Jumbo's capital. Then
the negroes wait in the jungle till the little black army has passed on,
after clearing out the huts by the way of everything eatable. When
they return they find their calabashes and saucepans licked clean,
but they also find every rat, mouse, lizard, cockroach, gecko, and
beetle completely cleared out from the whole village. Most of them
have cut and run at the first approach of the drivers; of the
remainder, a few blanched and neatly-picked skeletons alone remain
to tell the tale.
As I wish to be considered a veracious historian, I will not retail the
further strange stories that still find their way into books of natural
history about the manners and habits of these blind marauders.
They cross rivers, the West African gossips declare, by a number of
devoted individuals flinging themselves first into the water as a living
bridge, like so many six-legged Marcus Curtiuses, while over their
drowning bodies the heedless remainder march in safety to the
other side. If the story is not true, it is at least well invented; for the
ant-commonwealth everywhere carries to the extremest pitch the old
Roman doctrine of the absolute subjection of the individual to the
State. So exactly is this the case that in some species there are a
few large, overgrown, lazy ants in each nest, which do no work
themselves, but accompany the workers on their expeditions; and
the sole use of these idle mouths seems to be to attract the
attention of birds and other enemies, and so distract it from the
useful workers, the mainstay of the entire community. It is almost as
though an army, marching against a tribe of cannibals, were to place
itself in the centre of a hollow square formed of all the fattest people
in the country, whose fine condition and fitness for killing might
immediately engross the attention of the hungry enemy. Ants, in
fact, have, for the most part, already reached the goal set before us
as a delightful one by most current schools of socialist philosophers,
in which the individual is absolutely sacrificed in every way to the
needs of the community.
The most absurdly human, however, among all the tricks and habits
of ants are their well-known cattle-farming and slaveholding
instincts. Everybody has heard, of course, how they keep the
common rose-blight as milch cows, and suck from them the sweet
honey-dew. But everybody, probably, does not yet know the large
number of insects which they herd in one form or another as
domesticated animals. Man has, at most, some twenty or thirty such,
including cows, sheep, horses, donkeys, camels, llamas, alpacas,
reindeer, dogs, cats, canaries, pigs, fowl, ducks, geese, turkeys, and
silkworms. But ants have hundreds and hundreds, some of them
kept obviously for purposes of food; others apparently as pets; and
yet others again, as has been plausibly suggested, by reason of
superstition or as objects of worship. There is a curious blind beetle
which inhabits ants' nests, and is so absolutely dependent upon its
hosts for support that it has even lost the power of feeding itself. It
never quits the nest, but the ants bring it in food and supply it by
putting the nourishment actually into its mouth. But the beetle, in
return, seems to secrete a sweet liquid (or it may even be a
stimulant like beer, or a narcotic like tobacco) in a tuft of hairs near
the bottom of the hard wing-cases, and the ants often lick this tuft
with every appearance of satisfaction and enjoyment. In this case,
and in many others, there can be no doubt that the insects are kept
for the sake of food or some other advantage yielded by them.
But there are other instances of insects which haunt ants' nests,
which it is far harder to account for on any hypothesis save that of
superstitious veneration. There is a little weevil that runs about by
hundreds in the galleries of English ants, in and out among the free
citizens, making itself quite at home in their streets and public
places, but as little noticed by the ants themselves as dogs are in
our own cities. Then, again, there is a white woodlouse, something
like the common little armadillo, but blind from having lived so long
underground, which walks up and down the lanes and alleys of
antdom, without ever holding any communication of any sort with its
hosts and neighbors. In neither case has Sir John Lubbock ever seen
an ant take the slightest notice of the presence of these strange
fellow-lodgers. “One might almost imagine,” he says, “that they had
the cap of invisibility.” Yet it is quite clear that the ants deliberately
sanction the residence of the weevils and woodlice in their nests, for
any unauthorised intruder would immediately be set upon and
massacred outright. Sir John Lubbock suggests that they may
perhaps be tolerated as scavengers; or, again, it is possible that they
may prey upon the eggs or larvæ of some of the parasites to whose
attacks the ants are subject. In the first case, their use would be
similar to that of the wild dogs in Constantinople or the common
black John-crow vultures in tropical America: in the second case,
they would be about equivalent to our own cats or to the hedgehog
often put in farmhouse kitchens to keep down cockroaches.
The crowning glory of owning slaves, which many philosophic
Americans (before the war) showed to be the highest and noblest
function of the most advanced humanity, has been attained by more
than one variety of anthood. Our great English horse-ant is a
moderate slave-holder; but the big red ant of Southern Europe
carries the domestic institution many steps further. It makes regular
slave-raids upon the nests of the small brown ants, and carries off
the young in their pupa condition. By-and-by the brown ants hatch
out in the strange nest, and, never having known any other life
except that of slavery, accommodate themselves to it readily
enough. The red ant, however, is still only an occasional slaveowner;
if necessary, he can get along by himself, without the aid of his little
brown servants. Indeed, there are free states and slave states of red
ants side by side with one another, as of old in Maryland and
Pennsylvania: in the first, the red ants do their work themselves, like
mere vulgar Ohio farmers; in the second, they get their work done
for them by their industrious little brown servants, like the
aristocratic first families of Virginia before the earthquake of
emancipation.
But there are other degraded ants, whose life-history may be
humbly presented to the consideration of the Anti-Slavery Society, as
speaking more eloquently than any other known fact for the
demoralising effect of slaveowning upon the slaveholders
themselves. The Swiss rufescent ant is a species so long habituated
to rely entirely upon the services of slaves that it is no longer able to
manage its own affairs when deprived by man of its hereditary
bondsmen. It has lost entirely the art of constructing a nest; it can
no longer tend its own young, whom it leaves entirely to the care of
negro nurses; and its bodily structure even has changed, for the
jaws have lost their teeth, and have been converted into mere
nippers, useful only as weapons of war. The rufescent ant, in fact, is
a purely military caste, which has devoted itself entirely to the
pursuit of arms, leaving every other form of activity to its slaves and
dependents. Officers of the old school will be glad to learn that this
military insect is dressed, if not in scarlet, at any rate in very decent
red, and that it refuses to be bothered in any way with questions of
transport or commissariat. If the community changes its nest, the
masters are carried on the backs of their slaves to the new position,
and the black ants have to undertake the entire duty of foraging and
bringing in stores of supply for their gentlemanly proprietors. Only
when war is to be made upon neighboring nests does the thin red
line form itself into long file for active service. Nothing could be more
perfectly aristocratic than the views of life entertained and acted
upon by these distinguished slaveholders.
On the other hand, the picture has its reverse side, exhibiting clearly
the weak points of the slaveholding system. The rufescent ant has
lost even the very power of feeding itself. So completely dependent
is each upon his little black valet for daily bread, that he cannot so
much as help himself to the food that is set before him. Hüber put a
few slaveholders into a box with some of their own larvæ and pupæ,
and a supply of honey, in order to see what they would do with
them. Appalled at the novelty of the situation, the slaveholders
seemed to come to the conclusion that something must be done; so
they began carrying the larvæ about aimlessly in their mouths, and
rushing up and down in search of the servants. After a while,
however, they gave it up and came to the conclusion that life under
such circumstances was clearly intolerable. They never touched the
honey, but resigned themselves to their fate like officers and
gentlemen. In less than two days, half of them had died of hunger,
rather than taste a dinner which was not supplied to them by a
properly constituted footman. Admiring their heroism or pitying their
incapacity, Hüber, at last, gave them just one slave between them
all. The plucky little negro, nothing daunted by the gravity of the
situation, set to work at once, dug a small nest, gathered together
the larvæ, helped several pupæ out of the cocoon, and saved the
lives of the surviving slaveowners. Other naturalists have tried
similar experiments, and always with the same result. The
slaveowners will starve in the midst of plenty rather than feed
themselves without attendance. Either they cannot or will not put
the food into their own mouths with their own mandibles.
There are yet other ants, such as the workerless Anergates, in which
the degradation of slaveholding has gone yet further. These
wretched creatures are the formican representatives of those
Oriental despots who are no longer even warlike, but are sunk in
sloth and luxury, and pass their lives in eating bang or smoking
opium. Once upon a time, Sir John Lubbock thinks, the ancestors of
Anergates were marauding slaveowners, who attacked and made
serfs of other ants. But gradually they lost not only their arts but
even their military prowess, and were reduced to making war by
stealth instead of openly carrying off their slaves in fair battle. It
seems probable that they now creep into a nest of the far more
powerful slave ants, poison or assassinate the queen, and establish
themselves by sheer usurpation in the queenless nest. “Gradually,”
says Sir John Lubbock, “even their bodily force dwindled away under
the enervating influence to which they had subjected themselves,
until they sank to their present degraded condition—weak in body
and mind, few in numbers, and apparently nearly extinct, the
miserable representatives of far superior ancestors, maintaining a
precarious existence as contemptible parasites of their former
slaves.” One may observe in passing, that these wretched do-
nothings cannot have been the ants which Solomon commended to
the favorable consideration of the sluggard; though it is curious that
the text was never pressed into the service of defence for the
peculiar institution by the advocates of slavery in the South, who
were always most anxious to prove the righteousness of their cause
by most sure and certain warranty of Holy Scripture.—Cornhill
Magazine.
LITERARY NOTICES.
Episodes of My Second Life. By Antonio Gallenga (Luigi Mariotti).
English and American Experiences. Philadelphia: J. B. Lippincott
& Co.

The autobiographer in this case (for the last year has been singularly
rich in interesting autobiography) is not in any degree, at least for
Americans, an eminent and well-known personage. But, in spite of
this, his record of experience and vicissitude is full of interest, and
we may almost say fascinating. His threescore years and ten have
been crowded with events which, if not in themselves strikingly
dramatic, are at least striking in the telling, for he has all the art of
an accomplished raconteur, simple, direct and vigorous in style, and
knowing perfectly when to glide over with little stress, when to put
on his color with a vigorous and lavish brush. Mr. Gallenga (this
being his true name) was in the latter part of his life a leading
correspondent of the London Times, having achieved a high
reputation in this direction prior to the days of Dr. Russell and
Archibald Forbes. His work and position brought him into confidential
relations with many of the most important men and events of
Europe from 1840 to 1875, and he describes these in a racy fashion
which will command attention, we think.
Mr. Gallenga as a youth of twenty took part in the Italian struggle for
liberty in 1831, under the name of Luigi Mariotti. It was one of those
brief episodes of revolution with which Italy was convulsed so often
before the great final dead-lock came, which drove the hated
Sedischi from her soil. The young patriot was for a short time in
prison, but finally escaped, and lived for a while as a tutor in
Tangiers. Thence he came to America, to carve a career for himself,
and located himself in Boston in 1836. Here he speedily found
employment as teacher, lecturer and writer, and was fortunate in
securing the friendship and goodwill of the leading people of the city.
Boston was then without dispute the only literary centre of the
country, in spite of a few brilliant names in New York, and Sig.
Gallenga seems to have found congenial employment and
companionship from the outset. His reminiscences of such men as
Edward Everett, Fields, Ticknor, Prescott and others are entertaining,
and his sketch of the whole entourage of Boston society is given
with a refreshing naïveté, as well as with graceful vivacity. Among
the minor incidents which lend humor to the book is the author's
experience with a young American beauty, with whom he was in
love, and whom in his impulsive and passionate Italian way, he
clasped in his arms and kissed. He professes himself highly
astonished because the damsel was greatly enraged and ordered
him from the house, ending the acquaintance then and there. After
spending four years in America under unusually agreeable
conditions, Mr. Gallenga, who was still known under his pseudonym
of Mariotti, took ship for England, and bade a final farewell to the
country of which he speaks in such cordial and even affectionate
terms. Settling in London good luck still followed him. He secured
introductions to prominent persons, was accorded recognition at
once, and became acquainted with many of the people, both literary
and otherwise, best worth knowing in England. A great interest in
Italian affairs and literature was then the rage, and Mr. Gallenga,
who was a scholar and an able writer, found ample opportunity and
occupation in contributing to the magazines and reviews on subjects
which he discussed con amore. A book which he published gave him
repute beyond that of a mere fugitive writer, and he was fortunate in
making literature lucrative as well as honorable. His gossip about
prominent people and occurrences in London forty years ago, is very
entertaining, and he shows as much skill in throwing light on the
English life of that day as he had done in describing America. Twenty
years of literary and professorial work, were frequently broken up by
long residences in Italy, during which he sat for a time in the Italian
Parliament, and helped to pave the way for that consolidation of
Italian interests which at last led to Solferino and Magenta, and the
grand result of Italian unity. He seems to have been accorded an
important place in the councils and deliberations of his nation, and
to have been an important agent in bringing about those relations
which freed Italy from foreign domination. In 1859 our author
became connected with the Times as correspondent, and since that
time has been employed on many of the most delicate and
important commissions. He represented them in the Franco-Italian-
Austrian War, and succeeded Dr. Russell at the time of our late civil
conflict; was sent repeatedly to every part of Europe, and, for a
good while had a roving commission to write whatever he saw worth
reporting and discussing, particularly on the peoples and events of
the Mediterranean seaboard countries, from the straits of Gibraltar
to the Dardanelles. Mr. Gallenga tells his story (and he has much to
tell) with the vivacity of an Italian and with the ability of a trained
man-of-letters. A number of books, mostly on historical and political
subjects, have given him a recognized literary place aside from mere
journalism, and he reviews a long, diversified and interesting career
with an interest and satisfaction which he fully communicates to his
readers. We have rarely read a volume more packed with interesting
matter, narrated with the skill which comes of long training.

A Historical Reference Book, comprising a Chronological Table of


Universal History, a Chronological Dictionary of Universal History, a
Biographical Dictionary with Geographical Notes for the Use of
Students, Teachers and Readers. By Louis Heilprin. New York: D.
Appleton & Co.

The plan adopted in this handy reference book of historical dates


and events has been to deal separately with the events of different
countries, and an excellent system has been followed with great
thoroughness. The author is very well known as an industrious and
painstaking scholar, the results of whose work can be depended on.
About many historical dates there is much confusion, and the
difficulties in coming to a conclusion are great. Mr. Heilprin very
modestly states the obstacles in the way of perfect accuracy, and
convinces the reader that, if blunders have been made, they are
such as are absolutely unavoidable in the dire chaos which envelops
many of even the most important facts of history so far as certainty
of year is concerned. We may be sure that every caution and pains
have been taken by the author. In many cases where it is impossible
to reach an absolute statement, two dates are given, the preferable
one stated first. Such a book as this is of the greatest convenience,
and one that a well-informed or studious man can hardly afford to
be without. A remarkable seeming omission, however, is the non-
assignment of date to the Christian era, or any reference to the life
and career that gave it significance. The studious avoidal seems
significant, but we may explain it on the theory that the absolute
date of Christ's birth cannot be absolutely fixed within several years.
On the whole, indeed, with this one exception (perhaps an
unavoidable one) the compilation appears to be all such a work
should.

Bermuda: An Idyll of the Summer Islands. By Julia C. R. Dorr. New


York: Charles Scribner's Sons.

The germ of this book was in an article called “Bermudan Days”


published in the Atlantic Monthly for December, 1883, and we find
the paper incorporated with the work. The volume is a brightly
written account of a vacation of three months in the Bermudas, one
of the most charming sanitariums of our western seas. So much has
been written about the pleasant lotos-lands of the North and South
Antilles, that no new facts can be now told about them. But the old
background of cloudless skies, summer seas, and balmy ocean
breezes, which make such places as the Bahamas and the Bermudas
earthly paradises, never get tedious or dull when seen and felt
through the medium of a fresh and lively nature. In winter time
especially, when the bleak cold of the north starts the imagination
travelling toward summer climates, and those condemned to stay in
cold weather, sigh for the delights of the more fortunate voyager,
such books as the one before us make very pleasant reading. The
author describes the attractions of Bermudan life: its roses and
sunshine, its novel sights and sounds, the picturesque aspects of a
primitive, contented, lazy population, delightful sails over beautiful
seas, and all the episodes of the sojourn with the keenest
enjoyment, and a skilful literary touch. The very essence of an
agreeable book of this kind is an utter lack of anything like fine
writing. Mrs. Dorr certainly shows good taste in this matter, though
one might fancy the temptation would be great to try what is so
often called word-painting. She tells us what she has to say, and she
has many good things to tell us, too, in a lively, racy, picturesque,
but utterly unpretentious way. Of course we do not expect anyone to
write a book about the Bermudas, without giving us something of
the oft-repeated tale of its history and traditions; but Mrs. Dorr has
spared us from overmuch, and does not weary the attention. The
enjoyable portion of the work is the personal impressions and
experiences of herself and her party. As every traveller or tourist
with a literary taste, finds it essential, nowadays, to serve the sight-
seeing up in book form, we can only wish that more of them had the
good taste and lively nature of the present author.

Elements of Zoology. (Appleton's Science Text-Books.) By C. F.


Holder, Fellow of the New York Academy of Sciences, etc., and
T. B. Holder, A.M., Curator Zoology, American Museum of Natural
History. New York: D. Appleton & Co.

This new manual of one of the most interesting branches of science,


is equally adapted for the school or for family reading. The object of
the authors, which is to present in plain and concise language and in
the light of the latest research and investigation, the life history of
the various groups making up the animal kingdom has been well
done. The best authorities have been followed. The authors, too,
have introduced a great deal of matter of a descriptive and narrative
matter, such as will thoroughly interest their young readers, such as
the growth of the coral, nest-building fishes, luminous animals,
animal electricians, hibernation, mimicry, etc., things which make
certain phases of science almost like a fairy tale. The dry
classification of science has but little attraction except to the
professional scientist, and the authors have avoided this rock of
dreariness as far as possible. The aim of the book seems to be
largely to encourage the reader to become an original investigator,
and to use his eyes and ears intelligently in observing the order of
animated nature. The cuts are nicely and cleanly made, and the
volume is very neat, though gotten up for service and not for
ornament.

The Reality of Religion. By Henry J. Van Dyke, Jr., D.D. New York:
Charles Scribner's Sons.

In this day of scepticism without, and dry-rot within, it well becomes


the champions of the Christian faith to enter the lists with the
keenest weapons furnished for the fight. Dr. Van Dyke argues, not
from the standpoint of the dialectician, or from that of the defender
of historical Christianity. It is the personal argument drawn from
needs of human nature which he has here elaborated. He says: “We
do not sneer at the dogmas of theology. They are certainly as
important as the dogmas of science. We do not despise the
questions of ritual. They are at least of equal consequence with the
questions of social order. But religion is infinitely beyond all these. It
is more vital and more profound. It does not appeal to the intellect
alone. It is not satisfied with the conclusions of logic. Nor does it rest
at ease upon the æsthetic sense. It reaches down into the very
depths of the living, throbbing, human heart, and stirs a longing
which nothing outward and formal can ever fill—the longing for
personal fellowship with God.” It is this need of religion in the soul
as essential to satisfy its truest and deepest longing which furnishes
the keynote of the argument. He insists that religion is as absolute a
reality, which we can feel and know in our spiritual life, as is the
bread we eat to sustain our physical life. Dr. Van Dyke considers the
subject under the heads of “A Real Religion Necessary;” “The Living
God;” “The Living Soul” “The Living Word;” “The Living Sacrifice;”
and “The Living Christ.” In the last, of course, we find the key-stone
and cap, as well, of the logic of his thesis. The work will give comfort
and satisfaction to many Christian souls, and is not unworthy of Dr.
Van Dyke as an accomplished stylist. Chastened, yet glowing,
subdued, yet strong, the book is one which should have a large
number of readers among those devoted to the interests of the
Church of Christ.

The Enchiridion of Wit: The Best Specimens of English Conversational


Wit. Philadelphia: J. B. Lippincott & Co.

This collection has aimed to avoid both the characteristics of the


jest-book or of table-talk. Its place is between the two, being
compiled from the annals of conversation, and comprising at the
same time only those jests and stories which possess the stamp of
wit as distinguished from humor or drollery. That the collection is
good, one needs only to read the pleasant prefatory essay, which is
very gracefully and brightly written, to feel sure that the taste and
knowledge of the writer or editor have been well displayed in his
work of selection. It goes without saying that many of the anecdotes
are old and familiar. Many of the very best things ever said in the
world, of course, are what we term “Joe Millers.” That they should
be otherwise, would argue but bad taste on the part of our
predecessors. But our present author has gleaned in many an
outlying field as well as in the well travelled road, and gives us very
satisfactory showing for his literary excursus in new directions. Some
of the stories in the book we do not remember to have seen before
in any similar work.
FOREIGN LITERARY NOTES.
The monument to Virgil at Pietole (which is supposed to be the
Andes of the Romans), near Mantua, was unveiled lately.

The death of a popular Russian novelist, B. M. Markievich, on the


30th of last month, is reported from St. Petersburg.

The original autographs of the love-letters addressed by John Keats


to Miss Fanny Brawne in the years 1819-20 will be sold by Messrs.
Sotheby, Wilkinson & Hodge the first week in March, together with
six unpublished autograph letters of Charles Lamb.

A pamphlet by Madame E. Coulombe is announced for immediate


publication by Mr. Elliot Stock. This lady was associated with
Madame Blavatsky for some years, and in this brochure tells what
she heard and saw of Madame Blavatsky and the Theosophists with
whom she came in contact in India and elsewhere.

Trinity College, Dublin, is about to start a new paper with the title
The Dublin University Review. The first number will appear on
February 1st, and the issue will be bi-monthly, except during the
long vacation. The paper will contain literary articles as well as
university news of every description, and will be owned by a limited
liability company.

The Incorporated Society of Authors propose to send a deputation to


the Prime Minister to urge the codification of the Copyright Acts,
which are fourteen in number. Several of the chief publishers, not of
books only, but also of prints and music, will be asked to join.
A conference of elementary teachers, international in its character,
has been summoned to meet at Havre. This is the first conference of
the kind which has been organized in France, and it is expected that
the Government will make a grant in aid of the expenses.

The article on Polish history and literature in the next volume of the
“Encyclopædia Britannica” will be from the pen of Mr. Morfill, who
will also contribute the articles on the Emperor Paul, and on Peter
the Great.

Mr. Lowe, correspondent of the Times at Berlin, is engaged in writing


a biography of Prince Bismarck, which will appear next spring.

M. Schlumberger, the well known numismatist, and M. Benoist have


lately been elected members of the Académie des Inscriptions et
Belles-Lettres.

An exhibition is to be held in the Imperial Library at Constantinople


of Turkish writing, bookbinding, and illumination, for which prizes are
to be given.

One of the most important scholastic reforms now in progress in


Turkey is that relating to the study of the Arabic language. As now
conducted, this study absorbs years in a desultory way which might
be applied to the acquisition of other branches of knowledge. With
the view to abridge the course of study without impairing its quality,
the Sultan has determined on founding a special medresseh for
teaching Arabic on a scientific basis, and for this purpose has
purchased from the funds of the civil list the property of the Guedik
Pasha Theatre at Constantinople.
The long lost and often found commentary on the “Atharva-veda”
seems at last on its way to publication. The whole of the
commentary has not yet been found, but two-thirds of it are now in
the hands of the pandits of Poona, who will prepare a critical
publication of both text and commentary. The text of the “Atharva-
veda” was published in the early days of Vedic scholarship by Roth
and Whitney, and the latter scholar has lately published a very useful
index.

We are enabled to state, says the Athenæum, that a popular edition


of Her Majesty's recent work, “More Leaves from the Journal of a
Life in the Highlands,” is in the press, and will be ready for
publication in the course of a few weeks. The new edition will
contain all the woodcut illustrations which appeared in the original
edition, together with wood-engravings of the portraits, and will be
uniform with the popular edition of the Queen's previous work,
“Leaves from the Journal of our Life in the Highlands.”

Mr. Alexander Del Mar, according to the Academy, formerly Director


of the Bureau of Statistics of the United States, whose History of the
Precious Metals was published in 1880, has in the press a work on
The History of Money from the Earliest Times to the Middle Ages,
upon which he has been occupied for many years past. It will shortly
be published by Messrs. Bell & Sons.

From the Academy we quote the following amusing paragraph:


“The Magazin für die Literatur des In- und Auslandes continues to be
unfortunate when it meddles with the English language. Many of our
readers will be acquainted with Victor Scheffel's charming German
song—referring, we believe, to Heinrich von Ofterdingen—which has
the refrain, 'Der Heini von Steier ist wieder im Land.' The Magazin of
January 10 publishes an 'English' translation of this poem, by
Johanna Baltz, from which we quote the following specimen:—
“'To finches and swallows tells sweet nightingale:
“The song of a violin fills woodland and vale!
Ye twitt'ners, ye singers, now silence your cant—
Hark, Heini von Steier returned to his land!”

“'Shoemaker is waving his furcap in glee:


“The merciful heaven forgets neven me!
Now shoes will be costly, soleleather gets scant—
Hark, Heini von Steier returned to his land.“'”

The eighty-ninth birthday of Dr. Ranke (December 21st) has excited


interest throughout Germany, and elicited many expressions of the
respect universally felt for him. The strength of the venerable
historian defies the increase of years, and he works daily at his
home in Berlin on the history which he hopes to complete.

Mr. C. E. Pascoe has issued a prospectus on the publication of


English books in America. He says in effect that, though the lack of
international copyright is one reason why English authors derive but
little profit from the sale of their works in America, another and
graver reason is, that as a class, they are in ignorance of the means
for getting the best out of existing conditions. The usual method of
procedure is for the English publisher to make proposals to an
American publisher, or for the representative of an American firm in
London to submit proposals to his principals in the United States. Mr.
Pascoe points to the danger of losing a lucrative sale that this
method entails. His prospectus, which is accompanied by letters
from American publishers and some well-known English authors, is
worth attention. Mr. Pascoe's address is 6 Southfields Road, West
Hill, Wandsworth, S. W.

An early and hitherto unknown Arabic work has lately been added to
the Museum Library. It is entitled “Kitāb al-Mohabbir”, and contains
various historical notices and traditions relating to the ancient Arabs
and to the time of Mohammed and his immediate successors. The
author, Abu Sa'id al-Hasan al-Sukkari, lived in the third century of
the Hijrah, and is well known as one of the earliest editors and
commentators of the old poets, but the present work appears
somehow to have escaped notice; it is neither mentioned in the
Fihrist, nor by Ibn Khallikan or Soyuti. The two last-named authors
state that Al-Sukkari died A.H. 275; but according to Ibn Kāni'
(Leyden Catalogue, vol. ii. p. 8) he lived on to A.H. 290. The present
work would show that the former date is decidedly wrong; for it
contains a brief sketch of the Abbasides brought down by Al-Sukkari
himself to the accession of Al-Mo'tadid, i.e., A.H. 279.

Among other recent additions to the Arabic collection, the following


are especially deserving of the attention of scholars: the earliest
extant history of the Moslem conquest of Egypt, Africa, and Spain,
by Ibn 'Abd al-Hakam, who died A.H. 257, a twelfth century copy;
“Zubdat al-Tawarikh,” a history of the Seljuk-dynasty, written shortly
after its extinction, about A.H. 620, by Sadr al-Din Abul Hasan Ali
Ibn Abul Fawaris Nasir Husaini, a fine and apparently unique copy of
the thirteenth century; “Kitab al-Osul,” an extensive and hitherto
unknown work on Arabic grammar by one of the earliest writers on
the subject, Ibn al-Sarraj, who died A.H. 316, handsomely written,
with all vowels, A.H. 651; a fine and valuable copy of the “Makamat
al-Hariri,” written by a grandson of the author, A.H. 557 (i.e., forty
years after Hariri's death), and consequently earlier than any copy of
that standard work known to exist in European libraries.

The numbers of ladies attending the King's College classes at


Observatory Avenue have been very high during the term that has
just ended. The entries were nearly 600, which is a larger number
than has been reached since the first year, 1878, when the classes
started, and the present house hardly affords room for such
numbers.
It is not generally known that the Times attains its hundredth year
on the 1st of January, 1885. The prevailing notion is that the year in
which it was founded was 1788, the truth being that the 940th
number of the journal appeared on the first day in that year. The
mistake is due to confounding a change in the title with the
foundation of the journal. The actual facts are set forth in an article
which Mr. Fraser Rae contributes to the January number of the
Nineteenth Century. Amongst other things which will attract notice in
that article is a verbatim copy of the inscription on the tablets affixed
in honor of the conduct of the Times in the case of Bogle v. Lawson
in 1841, by a committee of bankers and merchants of the City, in the
Royal Exchange, and over the entrance to the Times printing office.
As these tablets are placed where the inscriptions on them cannot
easily be read, and as copies of these inscriptions are not given in
the works dealing with the City, the copy in the Nineteenth Century
is a piece of historical information which will be novel to most
readers.

The last number of Shakspeariana contains the somewhat surprising


statement that Prof. Kuno Fischer is a convert to the Bacon-
Shakspere theory, and will lecture upon it at Heidelberg this winter.
From the same periodical we copy the following curious paragraph:

“A very remarkable discovery has been placed on record by the Hon.
Ignatius Donnelly, who claims to have proof positive that Bacon was
the author of Shakspere's plays. This is accomplished by means of a
cipher which Bacon twice describes, whereby one writing could be
infolded and hidden in another. The words of the hidden story have
a definite relation to the acts and scenes of the plays, which is
determined by counting. Attracted by 'I. Henry IV.'; II., i., ii., iv., and
IV., ii., in which he found the words 'Francis,' 'Bacon' (twice),
'Nicholas' (twice), 'Bacon's,' 'son,' 'master,' 'Kings,' 'exchequer,' 'St.
Albans'—the name of Bacon's place of residence—and, in IV., ii.,
'Francis' repeated twenty times on one page, Mr. Donnelly applied
his key to it, with the following result:—Elizabeth during the Essex
troubles became, as is known, incensed at the use made of the play
of 'Richard II.,' in which is represented the deposition and killing of
the King; and she made it one of the points of prosecution which
cost Essex his head, that he had hired the company of players to
which Shakspere belonged to represent it more than forty times in
open streets and in tavern yards, in order to prepare the public mind
for her own deposition and murder. History tells us that she caused
the arrest of Haywarde, who wrote a prose narrative of the
deposition of Richard II. and dedicated it to Essex, and he narrowly
escaped a State prosecution. Mr. Donnelly shows that at the same
time Shakspere was arrested as the author of the plays; he was
threatened with the torture, and disclosed to the officers of the
Crown the fact that Bacon was the real author of the plays. Bacon
threw himself on the protection of his uncle, Lord Burleigh, the great
Lord Treasurer, who saved him from exposure and prosecution, but
revealed the truth to Elizabeth; and this is the explanation of the
fact, that, as long as Elizabeth lived, she kept Bacon out of office
and in poverty.”
MISCELLANY.
Some Personal Recollections of George Sand.—The recent unveiling of
George Sand's statue at La Châtre has set people thinking about her
afresh. At no time since “Indiana” and “Lelia” first revealed the
existence of a new writer of transcendent power, has her place in
French literature, and her influence on the social problems of the
time, and the question whether her artistic creations will or will not
live, been canvassed with more energy than during the past few
weeks. Some personal recollections of George Sand given by Mrs.
Ellis, the authoress of “Sylvestra,” may therefore be of interest:
“Above twenty years ago,” writes Mrs. Ellis, “I spent three days in a
French hotel (at Tours) with George Sand, without knowing who she
was. She puzzled me all the time, and had in person something of
the same effect on me that her character—attractive and repulsive—
has still. She sat opposite me at a narrow table d'hôte—a tall, large,
strongly-built woman, with features in proportion to her size. Her
eyes were fine, but her force of appearance was rather physical than
intellectual. It must have been the brain beneath the strong features
which teased me as it did, to make out to myself who she could be.
She was mature, but in no decline of force, massive, grave, and
restful, with nothing Gallic about her. The dark hair, eyes, and tint
might have belonged to Italy or Spain, quite as well as to France,
and the bearing, better. Her dress might have been called 'dowdy.' It
was of the type of the travelling Englishwoman, as French eyes see
it, rather than French. I think her 'robe' was brown, which did not
become her at all. Crimson would have suited her. She wore an ugly,
large-brimmed, straw hat, with broad lace falling over the brim, at a
time when Frenchwomen had hardly begun to wear hats, and—if my
memory does not err—she wore it at dinner. Her companion was an
elderly and feeble man, seemingly more than seventy. There was
nothing in the appearance of the couple (viewing them as married
folk) unlike that of many other French pairs, when, as is so often the
case, the man 'ranges' himself at forty by the side of a young lady of
half his years. My perplexing neighbor understood what I said to my
husband in English, and offered me some little courteous attentions.
There was no real speech between us. If I had known it was George
Sand, I believe that I should not have spoken more, as I had not
long before read some unpleasing remarks in her autobiography on
the way in which she was annoyed by 'les Anglaises,' and on the
'étranges sifflements' which they introduced into the fine French
tongue! She and I were the only two women in the hotel who ever
went into a sort of reading-room adjoining the house to look at the
newspapers. I had nearly settled with myself that she was a lady
country squire, such as I used to see drive into Tours on market
days, when one morning, on going, as I used to do, to the Imperial
library, to draw from old illuminated MSS., my friend, the librarian, M.
d'Orange, said to me, 'Madame, do you know that you have George
Sand in your hotel?' When I went back, she had just gone with the
gentleman who had lent her his name to travel with, for she was
entered as his 'Comtesse' in the book of the hotel. He was a Radical
Deputy. I told my lively landlady, who declared that M. d'Orange
'n'en savait rien,' and opened her book to show me the names of M.
le Comte and Madame la Comtesse So-and-So. Then she said, 'If it
was George Sand,' her books, 'ma foi,' of which she had read one or
two—instancing a couple of the best—were not 'grande chose.'
When I got back to England, I looked at a fine lithographed portrait
of George Sand, and saw it was the woman. Perhaps it was for the
best that I had not known who she was, as my impression, which is
still vivid, remains of her as she seemed, and not such as my fancy
would at once have set to work to make her out. Thinking of her
afterward, I was reminded of that passage in her autobiography in
which she tells how, in a moment of misery, she tested her own
strength by lifting a large heavy stone, and said to herself in despair,
'And I may have to live forty years!' Also I thought of Alfred de
Musset's taunting her—she never forgot it—with having no esprit. Of
'esprit Gallois' she seems to have had little. The Northern races had
the uppermost in her making, I should say. I have a notion that the
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like