100% found this document useful (2 votes)
225 views65 pages

Get Node js Design Patterns Master best practices to build modular and scalable server side web applications 2nd Edition Casciaro free all chapters

js

Uploaded by

marjyteskez3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (2 votes)
225 views65 pages

Get Node js Design Patterns Master best practices to build modular and scalable server side web applications 2nd Edition Casciaro free all chapters

js

Uploaded by

marjyteskez3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 65

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Node js Design Patterns Master best practices to


build modular and scalable server side web
applications 2nd Edition Casciaro

https://textbookfull.com/product/node-js-design-patterns-
master-best-practices-to-build-modular-and-scalable-server-
side-web-applications-2nd-edition-casciaro/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Node js web development server side development with Node


10 made easy Fourth Edition. Edition David Herron

https://textbookfull.com/product/node-js-web-development-server-side-
development-with-node-10-made-easy-fourth-edition-edition-david-
herron/
textboxfull.com

Pro Express js Master Express js The Node js Framework For


Your Web Development Mardan Azat

https://textbookfull.com/product/pro-express-js-master-express-js-the-
node-js-framework-for-your-web-development-mardan-azat/

textboxfull.com

RESTful Web API Design with Node js 10 Learn to create


robust RESTful web services with Node js MongoDB and
Express js 3rd Edition English Edition Valentin Bojinov
https://textbookfull.com/product/restful-web-api-design-with-node-
js-10-learn-to-create-robust-restful-web-services-with-node-js-
mongodb-and-express-js-3rd-edition-english-edition-valentin-bojinov/
textboxfull.com

Learning Node js Development Learn the fundamentals of


Node js and deploy and test Node js applications on the
web 1st Edition Andrew Mead
https://textbookfull.com/product/learning-node-js-development-learn-
the-fundamentals-of-node-js-and-deploy-and-test-node-js-applications-
on-the-web-1st-edition-andrew-mead/
textboxfull.com
Django Design Patterns and Best Practices 2nd Edition Arun
Ravindran

https://textbookfull.com/product/django-design-patterns-and-best-
practices-2nd-edition-arun-ravindran/

textboxfull.com

Node js 8 the Right Way Practical Server Side JavaScript


That Scales 1st Edition Jim Wilson

https://textbookfull.com/product/node-js-8-the-right-way-practical-
server-side-javascript-that-scales-1st-edition-jim-wilson/

textboxfull.com

Node js for Embedded Systems Using Web Technologies to


Build Connected Devices 1st Edition Patrick Mulder

https://textbookfull.com/product/node-js-for-embedded-systems-using-
web-technologies-to-build-connected-devices-1st-edition-patrick-
mulder/
textboxfull.com

Node js MongoDB and Angular Web Development The definitive


guide to using the MEAN stack to build web applications
Developer s Library 2nd Edition Brad Dayley & Brendan
Dayley & Caleb Dayley
https://textbookfull.com/product/node-js-mongodb-and-angular-web-
development-the-definitive-guide-to-using-the-mean-stack-to-build-web-
applications-developer-s-library-2nd-edition-brad-dayley-brendan-
dayley-caleb-dayley/
textboxfull.com

Ultimate Node.js for Cross-Platform App Development: Learn


to Build Robust, Scalable, and Performant Server-Side
JavaScript Applications with Node.js (English Edition)
Kumar
https://textbookfull.com/product/ultimate-node-js-for-cross-platform-
app-development-learn-to-build-robust-scalable-and-performant-server-
side-javascript-applications-with-node-js-english-edition-kumar/
textboxfull.com
Table of Contents
Chapter 1: Welcome to the Node.js platform 1
The Node.js philosophy 1
Small core 2
Small modules 2
Small surface area 3
Simplicity and pragmatism 4
Introduction to Node 5 and ES2015 5
Arrow Function 5
Let and Const 7
Class syntax 8
Enhanced Object literals 9
Map and Set collections 11
WeakMap and WeakSet collections 13
Template Literals 13
The reactor pattern 14
I/O is slow 14
Blocking I/O 15
Non-blocking I/O 16
Event demultiplexing 17
The reactor pattern 19
The non-blocking I/O engine of Node.js – libuv 21
The recipe for Node.js 22
Summary 23
Chapter 2: Node.js Essential Patterns 25
The callback pattern 25
The continuation-passing style 26
Synchronous continuation-passing style 26
Asynchronous continuation-passing style 27
Non continuation-passing style callbacks 28
Synchronous or asynchronous? 29
An unpredictable function 29
Unleashing Zalgo 29
Using synchronous APIs 31
Deferred execution 32
Node.js callback conventions 33
Callbacks come last 33
Error comes first 34
Propagating errors 34
Uncaught exceptions 35
The module system and its patterns 37
The revealing module pattern 37
Node.js modules explained 37
A homemade module loader 38
Defining a module 40
Defining globals 40
module.exports vs exports 40
Function require is synchronous 41
The resolving algorithm 42
The module cache 43
Cycles 44
Module definition patterns 45
Named exports 45
Exporting a function 46
Exporting a constructor 47
Exporting an instance 48
Modifying other modules or the global scope 49
The observer pattern 50
The EventEmitter 51
Create and use an EventEmitter 52
Propagating errors 53
Make any object observable 53
Synchronous and asynchronous events 55
EventEmitter vs Callbacks 56
Combine callbacks and EventEmitter 57
Summary 58
Chapter 3: Asynchronous Control Flow Patterns With Callbacks 59
The difficulties of asynchronous programming 59
Creating a simple web spider 60
The callback hell 62
Using plain JavaScript 63
Callback discipline 64
Applying the callback discipline 64
Sequential execution 67
Executing a known set of tasks in sequence 67
Sequential iteration 68
Web spider version 2 68

[ ii ]
Sequential crawling of links 69
The pattern 70
Parallel execution 71
Web spider version 3 74
The pattern 75
Fixing race conditions with concurrent tasks 76
Limited parallel execution 77
Limiting the concurrency 78
Globally limiting the concurrency 79
Queues to the rescue 80
Web spider version 4 81
The async library 82
Sequential execution 82
Sequential execution of a known set of tasks 83
Sequential iteration 85
Parallel execution 86
Limited parallel execution 86
Summary 88
Index 89

[ iii ]
Welcome to the Node.js
1
platform
Some principles and design patterns literally define the Node.js platform and its ecosystem;
the most peculiar ones are probably its asynchronous nature and its programming style that
makes heavy use of callbacks. It's important that we first dive into these fundamental
principles and patterns, not only for writing correct code, but also to be able to take effective
design decisions when it comes to solving bigger and more complex problems.

Another aspect that characterizes Node.js is its philosophy. Approaching Node.js is in fact
way more than simply learning a new technology; it's also embracing a culture and a
community. We will see how this greatly influences the way we design our applications
and components, and the way they interact with those created by the community.

In addition to these aspects it's worth knowing that the latest versions of Node.js introduced
support for many of the features described by ES2015, which makes the language even
more expressive and enjoyable to use. It is important to embrace these new syntactical and
functional additions to the language to be able to produce more concise and readable code
and come up with alternative ways to implement the design patterns that we are going to
see throughout this book.

In this chapter, we will learn the following topics:

The Node.js philosophy, the “Node way”


Node 5 and ES2015
The reactor pattern: the mechanism at the heart of the Node.js asynchronous
architecture
Welcome to the Node.js platform

The Node.js philosophy


Every platform has its own philosophy-a set of principles and guidelines that are generally
accepted by the community, an ideology of doing things that influences the evolution of a
platform, and how applications are developed and designed. Some of these principles arise
from the technology itself, some of them are enabled by its ecosystem, some are just trends
in the community, and others are evolutions of different ideologies. In Node.js, some of
these principles come directly from its creator, Ryan Dahl, from all the people who
contributed to the core, from charismatic figures in the community, and some of the
principles are inherited from the JavaScript culture or are influenced by the Unix
philosophy.

None of these rules are imposed and they should always be applied with common sense;
however, they can prove to be tremendously useful when we are looking for a source of
inspiration while designing our programs.

You can find an extensive list of software development philosophies in


Wikipedia at
http://en.wikipedia.org/wiki/List_of_software_development
_philosophies

Small core
The Node.js core itself has its foundations built on a few principles; one of these is, having
the smallest set of functionality, leaving the rest to the so-called userland (or userspace),the
ecosystem of modules living outside the core. This principle has an enormous impact on the
Node.js culture, as it gives freedom to the community to experiment and iterate fast on a
broader set of solutions within the scope of the userland modules, instead of being imposed
with one slowly evolving solution that is built into the more tightly controlled and stable
core. Keeping the core set of functionality to the bare minimum then, not only becomes
convenient in terms of maintainability, but also in terms of the positive cultural impact that
it brings on the evolution of the entire ecosystem.

Small modules
Node.js uses the concept of module as a fundamental mean to structure the code of a
program. It is the brick for creating applications and reusable libraries called packages (a
package is also frequently referred to as just module; since, usually it has one single module
as an entry point). In Node.js, one of the most evangelized principles is to design small
modules, not only in terms of code size, but most importantly in terms of scope.

[2]
Welcome to the Node.js platform

This principle has its roots in the Unix philosophy, particularly in two of its precepts, which
are as follows:

“Small is beautiful.”
“Make each program do one thing well.”

Node.js brought these concepts to a whole new level. Along with the help of npm, the
official package manager, Node.js helps solving the dependency hell problem by making sure
that each installed package will have its own separate set of dependencies, thus enabling a
program to depend on a lot of packages without incurring in conflicts. The Node way, in
fact, involves extreme levels of reusability, whereby applications are composed of a
highnumber of small, well-focused dependencies. While this can be considered unpractical
or even totally unfeasible in other platforms, in Node.js this practice is encouraged. As a
consequence, it is not rare to find npm packages containing less than 100 lines of code or
exposing only one single function.

Besides the clear advantage in terms of reusability, a small module is also considered to be
the following:

Easier to understand and use


Simpler to test and maintain
Perfect to share with the browser

Having smaller and more focused modules empowers everyone to share or reuse even the
smallest piece of code; it's the Don't Repeat Yourself (DRY) principle applied at a whole
new level.

Small surface area


In addition to being small in size and scope, Node.js modules usually also have the
characteristic of exposing only a minimal set of functionality. The main advantage here is an
increased usability of the API, which means that the API becomes clearer to use and is less
exposed to erroneous usage. Most of the time, in fact, the user of a component is interested
only in a very limited and focused set of features, without the need to extend its
functionality or tap into more advanced aspects.

In Node.js, a very common pattern for defining modules is to expose only one piece of
functionality, such as a function or a constructor, while letting more advanced aspects or
secondary features become properties of the exported function or constructor. This helps
the user to identify what is important and what is secondary. It is not rare to find modules
that expose only one function and nothing else, for the simple fact that it provides a single,

[3]
Welcome to the Node.js platform

unmistakably clear entry point.

Another characteristic of many Node.js modules is the fact that they are created to be used
rather than extended. Locking down the internals of a module by forbidding any possibility
of an extension might sound inflexible, but it actually has the advantage of reducing the use
cases, simplifying its implementation, facilitating its maintenance, and increasing its
usability.

Simplicity and pragmatism


Have you ever heard of the Keep It Simple, Stupid (KISS) principle? Or the famous quote:

“Simplicity is the ultimate sophistication.”

– Leonardo da Vinci

Richard P. Gabriel, a prominent computer scientist coined the term worse is better to describe
the model, whereby less and simpler functionality is a good design choice for software. In
his essay,The rise of worse is better, he says:

“The design must be simple, both in implementation and interface. It is more important for
the implementation to be simple than the interface. Simplicity is the most important
consideration in a design.”

Designing a simple, as opposed to a perfect, feature-full software, is a good practice for


several reasons: it takes less effort to implement, allows faster shipping with less resources,
is easier to adapt, and is easier to maintain and understand. These factors foster the
community contributions and allow the software itself to grow and improve.

In Node.js, this principle is also enabled by JavaScript, which is a very pragmatic language.
It's not rare, in fact, to see simple functions, closures, and object literals replacing complex
class hierarchies. Pure object-oriented designs often try to replicate the real world using the
mathematical terms of a computer system without considering the imperfection and the
complexity of the real world itself. The truth is that our software is always an
approximation of the reality and we would probably have more success in trying to get
something working sooner and with reasonable complexity, instead of trying to create a
near-perfect software with a huge effort and tons of code to maintain.

Throughout this book, we will see this principle in action many times. For example, a
considerable number of traditional design patterns, such as Singleton or Decorator can have
a trivial, even if sometimes not foolproof implementation and we will see how an
uncomplicated, practical approach most of the time is preferred to a pure, flawless design.

[4]
Welcome to the Node.js platform

Introduction to Node 5 and ES2015


At the time of writing the most recent major versions of Node.js (Node 4 and Node 5) come
with a great addition to the language: a wide support for many of the new features
introduced in the ECMAScript 2015 specification (in short ES2015 and formerly known also
as ES6) which aims to make the language even more flexible and enjoyable.

Throughout this book, we will widely adopt some of these new features in the code
examples. These concepts are still fresh within the Node.js community so it's worth having
a quick look at the most important ES2015 specific features currently supported in Node.js.
Our version of reference is Node 5, more specifically version 5.1.

Many of these features will work correctly only when the strict mode is enabled. Strict
mode can be easily enabled by adding ause strict; statement at the very beginning of
your script. For the sake of brevity, we will not write this line in our code examples but you
should remember to add it to be able to run them correctly.

The following list is not meant to be exhaustive but just an introduction to the ES2015
features supported in Node, so that you can easily understand all the code examples in the
rest of this book.

Arrow Function
One of the most appreciated features introduced by ES2015 is the support for arrow
functions. Arrow function is a more concise syntax for defining functions, especially useful
when defining a callback. To better understand the advantages of this syntax let's see first
an example of a classic filtering on an array:
var numbers = [2, 6, 7, 8, 1];
var even = numbers.filter(function(x) {
return x%2 === 0;
});

This code above can be rewritten as follows using the arrow function syntax:
var numbers = [2, 6, 7, 8, 1];
var even = numbers.filter((x) => x%2 === 0);

The filter function can be defined inline, the keyword function is removed, leaving only
the list of parameters, which is followed by => (the arrow), which in turn is followed by the
body of the function. When the body of the function is just one line there's no need to write
the return keyword as it is applied implicitly. If we need to add more lines of code to the
body of the function, we can wrap them in curly brackets, but beware that in this case the

[5]
Welcome to the Node.js platform

return is not automatically implied, so it needs to be stated explicitly, as in the following


example:
var numbers = [2, 6, 7, 8, 1];
var even = numbers.filter((x) => {
if (x%2 === 0) {
console.log(x + ' is even!');
return true;
}
});

But there is another important feature to know about arrow functions: arrow functions are
bound to their lexical scope. This means that inside an arrow function the value of this is
the same as in the parent block. Let's clarify this concept with an example:
function DelayedGreeter(name) {
this.name = name;
}

DelayedGreeter.prototype.greet = function() {
setTimeout( function cb() {
console.log('Hello ' + this.name);
}, 500);
};

let greeter = new DelayedGreeter('World');


greeter.greet(); // will print "Hello undefined"

In this code we are defining a simple “greeter” prototype which accepts a name as
argument. Then we are adding the greet method to the prototype. This function is
supposed to print “Hello” and the name defined in the current instance after 500
milliseconds it has been called. But this function is broken because inside the timeout
callback function (cb), the scope of the function is different from the scope of the greet
method and the value of this is undefined.

Before Node.js introduced support for arrow functions, to fix this we needed to change the
greet function using bind as follows:

DelayedGreeter.prototype.greet = function() {
setTimeout( (function cb() {
console.log('Hello ' + this.name);
}).bind(this), 500);
};

But since we have now arrow functions and since they are bound to their lexical scope, we
can just use an arrow function as callback to solve the issue:

[6]
Welcome to the Node.js platform

DelayedGreeter.prototype.greet = function() {
setTimeout( () => console.log('Hello ' + this.name), 500);
};

This is a very handy feature, most of the time it makes our code more concise and
straightforward.

Let and Const


Historically JavaScript offered only function scope and global scope to control the lifetime
and the visibility of a variable. For instance if you declare a variable inside the body of an if
statement the variable will be accessible even outside the statement, whether or not the
body of the statement has been executed. Let's see it more clearly with an example:
if (false) {
var x = "hello";
}
console.log(x);

This code will not fail as we might expect and it will just print undefined in the console.
This behavior has been cause of many bugs and frustration and that is the reason why
ES2015 introduces the let keyword to declare variables that respect the block scope. Let's
replace var with let in our previous example:
if (false) {
let x = "hello";
}
console.log(x);

This code will raise a ReferenceError: x is not defined because we are trying to
print a variable that has been defined inside another block scope.

To give a more meaningful example we can use the let keyword to define a temporary
variable to be used as an index for a loop:
for (let i=0; i < 10; i++) {
// do something here
}
console.log(i);

As in the previous example, this code will raise a ReferenceError: i is not defined
error.

This protective behavior introduced with let allows us to write safer code, because if we
accidentally access variables that belong to another scope we will get an error that will

[7]
Welcome to the Node.js platform

allow us to easily spot the bug and avoid potentially dangerous side effects.

ES2015 introduces also the const keyword. This keyword allows to declare read-only
variables. Let's see a quick example:
const x = 'This will never change';
x = '...';

This code will raise a “TypeError: Assignment to constant variable” error because
we are trying to change the value of a constant.

Constants are extremely useful when you want to protect a value from being accidentally
changed in your code.

Class syntax
ES2015 introduces a new syntax to leverage prototypical inheritance in a way that should
sound more familiar to all the developers that come from classic object oriented languages
such as Java or C#. It's important to underline that this new syntax does not change the way
objects are managed internally by the JavaScript runtime, they still inherits properties and
functions through prototypes and not through classes. While this new alternative syntax
can be very handy and readable, as a developer is important to understand that it is just a
syntactic sugar.

Let's see how it works with a trivial example. First of all, let's describe a Person using the
classic prototype based approach:
function Person(name, surname, age) {
this.name = name;
this.surname = surname;
this.age = age;
}

Person.prototype.getFullName = function() {
return this.name + ' ' + this.surname;
}

Person.older = function(person1, person2) {


return (person1.age >= person2.age) ? person1 : person2;
}

As you can see a person has a name, a surname and an age. We are providing to our
prototype a helper function that allows us to easily get the full name of a person object and
a generic helper function accessible directly from the Person prototype that returns the

[8]
Welcome to the Node.js platform

older person between two Person instances given as input.

Let's see now how we can implement the same example using the new handy ES2015 class
syntax:
class Person {
constructor (name, surname, age) {
this.name = name;
this.surname = surname;
this.age = age;
}

getFullName () {
return this.name + ' ' + this.surname;
}

static older (person1, person2) {


return (person1.age >= person2.age) ? person1 : person2;
}
}

This syntax results more readable and straightforward to understand. We are explicitly
stating what is the constructor for the class and declaring the function older as a static
method.

Both implementations are completely interchangeable, but the real killer feature of the new
syntax is the possibility of extending the Person prototype using the extend and the
super keywords. Let's assume we want to create the PersonWithMiddlename class:

class PersonWithMiddlename extends Person {


constructor (name, middlename, surname, age) {
super(name, surname, age);
this.middlename = middlename;
}

getFullName () {
return this.name + ' ' + this.middlename + ' ' + this.surname;
}
}

What is worth noticing in this second example is that the syntax really resembles what is
common in other object oriented languages. We are declaring the class from which we want
to extend, we define a new constructor that can call the parent one using the keyword
super and we override the getFullName method to add support for our middle name.

[9]
Welcome to the Node.js platform

Enhanced Object literals


As long with the new class syntax, ES2015 introduced an enhanced object literals syntax.
This syntax offers a shorthand to assign variables and functions as members of the object,
allows to define computed member names at creation time and also handy setters and
getters methods.

Let's make all of this clear with some examples:


let x = 22;
let y = 17;
let obj = { x, y };

obj will be an object containing the keys x and y, respectively with the values 22 and 17.

We can do the same thing with functions:


module.exports = {
square (x) {
return x * x;
},
cube (x) {
return x * x * x;
}
};

In this case we are writing a module that exports the functions square and cube mapped to
properties with the same name. Notice that we don't need to specify the keyword
function.

Let's see in another example how we can use computed property names:
let namespace = '-webkit-';
let style = {
[namespace + 'box-sizing'] : 'border-box',
[namespace + 'box-shadow'] : '10px 10px 5px #888888'
};

In this case the resulting object will contain the properties -webkit-box-sizing and -
webkit-box-shadow.

Let's see now how we can use the new setter and getter syntax by jumping directly to an
example:
let person = {
name : 'George',
surname : 'Boole',

[ 10 ]
Welcome to the Node.js platform

get fullname () {
return this.name + ' ' + this.surname;
},

set fullname (fullname) {


let parts = fullname.split(' ');
this.name = parts[0];
this.surname = parts[1];
}
}

console.log(person.fullname); // "George Boole"


console.log(person.fullname = 'Alan Turing'); // "Alan Turing"
console.log(person.name); // "Alan"

In this example we are defining three properties, two normal name and surname and a
computed property fullname through the set and get syntax. As you can see from the
result of the console.log calls, we can access the computed property as if it was a regular
property inside the object for both reading and writing the value. It's worth noticing that the
second call to console.log prints “Alan Turing”. This happens because by default every
set function returns the value that is returned by the get function for the same property, in
this case get fullname.

Map and Set collections


As JavaScript developers we are used to create hash maps using plain objects. ES2015
introduces a new prototype called Map that is specifically designed to leverage hash map
collections in a more secure, flexible and intuitive way. Let's see a quick example:
let profiles = new Map();
profiles.set('twitter', '@adalovelace');
profiles.set('facebook', 'adalovelace');
profiles.set('googleplus', 'ada');

profiles.size; // 3
profiles.has('twitter'); // true
profiles.get('twitter'); // "@adalovelace"
profiles.has('youtube'); // false
profiles.delete('facebook');
profiles.has('facebook'); // false
profiles.get('facebook'); // undefined
for (let entry of profiles) {
console.log(entry);
}

[ 11 ]
Welcome to the Node.js platform

As you can see the Map prototype offers several handy methods like set, get, has and
delete and the size attribute. We can also iterate through all the entries using the for
... of syntax. Every entry in the loop will be an array containing the key as first element
and the value as second element. This interface is very intuitive and self-explanatory.

But what makes maps really interesting is the possibility of using functions and objects as
keys of the map and this was something that is not entirely possible using plain objects,
because with objects all the keys are automatically casted to strings. This opens new
opportunities, for example we can build a micro testing framework leveraging this feature:
let tests = new Map();
tests.set(() => 2+2, 4);
tests.set(() => 2*2, 4);
tests.set(() => 2/2, 1);

for (let entry of tests) {

console.log((entry[0]() === entry[1]) ? ' ' : ' ');


}

As you can see in this last example, we are storing functions as keys and expected results as
values. Then we can iterate through our hash map and execute all the functions. It's also
worth noticing that when we iterate through the map all the entries respect the order in
which they have been inserted, this is also something that was not always guaranteed with
plain objects.

Along with Map, ES2015 also introduces the Set prototype. This prototype allows us to
easily construct sets, which means lists with unique values.
let s = new Set([0, 1, 2, 3]);

s.add(3); // will not be added


s.size; // 4
s.delete(0);
s.has(0); // false

for (let entry of s) {


console.log(entry);
}

As you can see in this example the interface is quite similar to the one we have just seen for

[ 12 ]
Welcome to the Node.js platform

Map. We have the methods add (instead of set), has and delete and the property size.
We can also iterate through the set and in this case every entry is a value, in our example it
will be one of the numbers in the set. Finally, sets can also contain objects and functions as
values.

WeakMap and WeakSet collections


ES2015 defines also a weak version of the Map and the Set prototypes called WeakMap and
WeakSet.

WeakMap is quite similar to Map in terms of interface, there are only two main differences:
there is no way to iterate all over the entries and it allows to have only objects as keys.
While this might seem as a limitation there is a good reason behind it, in fact the distinctive
feature of WeakMap is that it allows objects used as keys to be garbage collected when the
only reference left is inside a WeakMap. This is extremely useful when we are storing some
metadata associated to an object that might get deleted during the regular lifetime of the
application. Let's see an example:
let obj = {};
let map = new WeakMap();
map.set(obj, {metadata: "some_metadata"});
console.log(map.get(obj)); // {metadata: "some_metadata"}
obj = undefined; // now obj and metadata will be cleaned up in the next gc
cycle

In this code we are creating a plain object called obj. Then we store some metadata for this
object in a new WeakMap called map. We can access this metadata with the map.get method.
Later, when we cleanup the object by assigning its variable to undefined, the object will be
correctly garbage collected and its metadata removed from the map.

Similarly, to WeakMap, WeakSet is the weak version of Set: it exposes the same interface of
Set but it allows to store only objects and cannot be iterated. Again the difference with Set
is that WeakSet allows objects to be garbage collected when their only reference left is in the
weak set.

It's important to understand that WeakMap and WeakSet are not better or worse than Map
and Set, they are simply more suitable for different use cases.

Template Literals
ES2015 offers a new alternative and more powerful syntax to define strings: the template

[ 13 ]
Welcome to the Node.js platform

literals. This syntax uses back ticks (`) as delimiters and offers several benefits compared to
regular quoted (') or double-quoted (") delimited strings. The main ones are that template
literals syntax can interpolate variables or expressions using ${expression} inside the string
(this is the reason why this syntax is called “template”) and that strings can finally be
multiline. Let's see a quick example:
let name = "Leonardo";
let interests = ["arts", "architecture", "science", "music",
"mathematics"];
let birth = { year : 1452, place : 'Florence' };
let text = `${name} was an Italian polymath interested in many topics such
as ${interests.join(', ')}.
He was born in ${birth.year} in ${birth.place}.`;
console.log(text);

This code will print:


Leonardo was an Italian polymath interested in many topics such
as arts, architecture, science, music, mathematics.
He was born in 1452 in Florence.

A more extended and up to date list of all the supported ES2015 features is
available in the official Node.js documentation:
https://nodejs.org/en/docs/es6/

The reactor pattern


In this section, we will analyze the reactor pattern, which is the heart of the Node.js
asynchronous nature. We will go through the main concepts behind the pattern, such as the
single-threaded architecture and the non-blocking I/O, and we will see how this creates the
foundation for the entire Node.js platform.

I/O is slow
I/O is definitely the slowest among the fundamental operations of a computer. Accessing
the RAM is in the order of nanoseconds (10e-9 seconds), while accessing data on the disk or
the network is in the order of milliseconds (10e-3 seconds). For the bandwidth, it is the same
story; RAM has a transfer rate consistently in the order of GB/s, while disk and network
varies from MB/s to, optimistically, GB/s. I/O is usually not expensive in terms of CPU,
but it adds a delay between the moment the request is sent and the moment the operation
completes. On top of that, we also have to consider thehuman factor; often, the input of an

[ 14 ]
Welcome to the Node.js platform

application comes from a real person, for example, the click of a button or a message sent in
a real-time chat application, so the speed and frequency of I/O don't depend only on
technical aspects, and they can be many orders of magnitude slower than the disk or
network.

Blocking I/O
In traditional blocking I/O programming, the function call corresponding to an I/O request
will block the execution of the thread until the operation completes. This can go from a few
milliseconds, in case of a disk access, to minutes or even more, in case the data is generated
from user actions, such as pressing a key. The following pseudocode shows a typical
blocking read performed against a socket:
//blocks the thread until the data is available
data = socket.read();
//data is available
print(data);

It is trivial to notice that a web server that is implemented using blocking I/O will not be
able to handle multiple connections in the same thread; each I/O operation on a socket will
block the processing of any other connection. For this reason, the traditional approach to
handle concurrency in web servers is to kick off a thread or a process (or to reuse one taken
from a pool) for each concurrent connection that needs to be handled. This way, when a
thread gets blocked for an I/O operation it will not impact the availability of the other
requests, because they are handled in separate threads.

The following image illustrates this scenario:

[ 15 ]
Welcome to the Node.js platform

The preceding image lays emphasis on the amount of time each thread is idle, waiting for
new data to be received from the associated connection. Now, if we also consider that any
type of I/O can possibly block a request, for example, while interacting with databases or
with the filesystem, we soon realize how many times a thread has to block in order to wait
for the result of an I/O operation. Unfortunately, a thread is not cheap in terms of system
resources, it consumes memory and causes context switches, so having a long running
thread for each connection and not using it for most of the time, is not the best compromise
in terms of efficiency.

Non-blocking I/O
In addition to blocking I/O, most modern operating systems support another mechanism to
access resources, called non-blocking I/O. In this operating mode, the system call always
returns immediately without waiting for the data to be read or written. If no results are
available at the moment of the call, the function will simply return a predefined constant,
indicating that there is no data available to return at that moment.

For example, in Unix operating systems, the fcntl() function is used to manipulate an
existing file descriptor to change its operating mode to non-blocking (with the O_NONBLOCK
flag). Once the resource is in non-blocking mode, any read operation will fail with a return
code, EAGAIN, in case the resource doesn't have any data ready to be read.

The most basic pattern for accessing this kind of non-blocking I/O is to actively poll the
resource within a loop until some actual data is returned; this is called busy-waiting. The
following pseudocode shows you how it's possible to read from multiple resources using

[ 16 ]
Welcome to the Node.js platform

non-blocking I/O and a polling loop:


resources = [socketA, socketB, pipeA];
while(!resources.isEmpty()) {
for(i = 0; i < resources.length; i++) {
resource = resources[i];
//try to read
var data = resource.read();
if(data === NO_DATA_AVAILABLE)
//there is no data to read at the moment
continue;
if(data === RESOURCE_CLOSED)
//the resource was closed, remove it from the list
resources.remove(i);
else
//some data was received, process it
consumeData(data);
}
}

You can see that, with this simple technique, it is already possible to handle different
resources in the same thread, but it's still not efficient. In fact, in the preceding example, the
loop will consume precious CPU only for iterating over resources that are unavailable most
of the time. Polling algorithms usually result in a huge amount of wasted CPU time.

Event demultiplexing
Busy-waiting is definitely not an ideal technique for processing non-blocking resources, but
luckily, most modern operating systems provide a native mechanism to handle concurrent,
non-blocking resources in an efficient way; this mechanism is called synchronous event
demultiplexer or event notification interface. This component collects and queues I/O
events that come from a set of watched resources, and block until new events are available
to process. The following is the pseudocode of an algorithm that uses a generic synchronous
event demultiplexer to read from two different resources:
socketA, pipeB;
watchedList.add(socketA, FOR_READ); //[1]
watchedList.add(pipeB, FOR_READ);
while(events = demultiplexer.watch(watchedList)) { //[2]
//event loop
foreach(event in events) { //[3]
//This read will never block and will always return data
data = event.resource.read();
if(data === RESOURCE_CLOSED)
//the resource was closed, remove it from the watched list

[ 17 ]
Welcome to the Node.js platform

demultiplexer.unwatch(event.resource);
else
//some actual data was received, process it
consumeData(data);
}
}

These are the important steps of the preceding pseudocode:

1. The resources are added to a data structure, associating each one of them with a
specific operation, in our example a read.
2. The event notifier is set up with the group of resources to be watched. This call is
synchronous and blocks until any of the watched resources is ready for a read.
When this occurs, the event demultiplexer returns from the call and a new set of
events is available to be processed.
3. Each event returned by the event demultiplexer is processed. At this point, the
resource associated with each event is guaranteed to be ready to read and to not
block during the operation. When all the events are processed, the flow will block
again on the event demultiplexer until new events are again available to be
processed. This is called the event loop.

It's interesting to see that with this pattern, we can now handle several I/O operations
inside a single thread, without using a busy-waiting technique. The following image shows
us how a web server would be able to handle multiple connections using a synchronous
event demultiplexer and a single thread:

The previous image helps us understand how concurrency works in a single-threaded


application using a synchronous event demultiplexer and non-blocking I/O. We can see

[ 18 ]
Welcome to the Node.js platform

that using only one thread does not impair our ability to run multiple I/O bound tasks
concurrently. The tasks are spread over time, instead of being spread across multiple
threads. This has the clear advantage of minimizing the total idle time of the thread, as
clearly shown in the image. This is not the only reason for choosing this model. To have
only a single thread, in fact, also has a beneficial impact on the way programmers approach
concurrency in general. Throughout the book, we will see how the absence of in-process
race conditions and multiple threads to synchronize, allows us to use much simpler
concurrency strategies.

In the next chapter, we will have the opportunity to talk more about the concurrency model
of Node.js.

The reactor pattern


We can now introduce the reactor pattern, which is a specialization of the algorithms
presented in the previous section. The main idea behind it is to have a handler (which in
Node.js is represented by a callback function) associated with each I/O operation, which
will be invoked as soon as an event is produced and processed by the event loop. The
structure of the reactor pattern is shown in the following image:

[ 19 ]
Welcome to the Node.js platform

This is what happens in an application using the reactor pattern:

1. The application generates a new I/O operation by submitting a request to the


Event Demultiplexer. The application also specifies a handler, which will be
invoked when the operation completes. Submitting a new request to the Event
Demultiplexer is a non-blocking call and it immediately returns the control back
to the application.
2. When a set of I/O operations completes, the Event Demultiplexer pushes the new
events into the Event Queue.
3. At this point, the Event Loop iterates over the items of the Event Queue.
4. For each event, the associated handler is invoked.
5. The handler, which is part of the application code, will give back the control to
the Event Loop when its execution completes (5a). However, new asynchronous
operations might be requested during the execution of the handler (5b), causing

[ 20 ]
Welcome to the Node.js platform

new operations to be inserted in the Event Demultiplexer (1), before the control is
given back to the Event Loop.
6. When all the items in the Event Queue are processed, the loop will block again on
the Event Demultiplexer which will then trigger another cycle.

The asynchronous behavior is now clear: the application expresses the interest to access a
resource at one point in time (without blocking) and provides a handler, which will then be
invoked at another point in time when the operation completes.

A Node.js application will exit automatically when there are no more


pending operations in the Event Demultiplexer, and no more events to be
processed inside the Event Queue.

We can now define the pattern at the heart of Node.js.

Pattern (reactor): handles I/O by blocking until new events are available from a set of
observed resources, and then reacting by dispatching each event to an associated handler.

The non-blocking I/O engine of Node.js – libuv


Each operating system has its own interface for the Event Demultiplexer: epoll on Linux,
kqueue on Mac OS X, andI/O Completion Port API (IOCP) on Windows. Besides that, each
I/O operation can behave quite differently depending on the type of the resource, even
within the same OS. For example, in Unix, regular filesystem files do not support non-
blocking operations, so, in order to simulate a non-blocking behavior, it is necessary to use a
separate thread outside the Event Loop. All these inconsistencies across and within the
different operating systems required a higher-level abstraction to be built for the Event
Demultiplexer. This is exactly why the Node.js core team created a C library called libuv,
with the objective to make Node.js compatible with all the major platforms and normalized
the non-blocking behavior of the different types of resource; libuv today represents the
low-level I/O engine of Node.js.

Besides abstracting the underlying system calls, libuv also implements the reactor pattern,
thus providing an API for creating event loops, managing the event queue, running
asynchronous I/O operations, and queuing other types of tasks.

A great resource to learn more about libuv is the free online book created
by Nikhil Marathe, which is available at
http://nikhilm.github.io/uvbook/

[ 21 ]
Welcome to the Node.js platform

The recipe for Node.js


The reactor pattern and libuv are the basic building blocks of Node.js, but we need the
following three other components to build the full platform:

A set of bindings responsible for wrapping and exposing libuv and other low-
level functionality to JavaScript.
V8, the JavaScript engine originally developed by Google for the Chrome
browser. This is one of the reasons why Node.js is so fast and efficient. V8 is
acclaimed for its revolutionary design, its speed, and for its efficient memory
management.
A core JavaScript library (called node-core) thatimplements the high-level
Node.js API.

Finally, this is the recipe of Node.js, and the following image represents its final
architecture:

[ 22 ]
Welcome to the Node.js platform

Summary
In this chapter, we have seen how the Node.js platform is based on a few important
principles that provide the foundation to build efficient and reusable code. The philosophy
and the design choices behind the platform have, in fact, a strong influence on the structure
and behavior of every application and module we create. Often, for a developer moving
from another technology, these principles might seem unfamiliar and the usual instinctive

[ 23 ]
Welcome to the Node.js platform

reaction is to fight the change by trying to find more familiar patterns inside a world which
in reality requires a real shift in the mindset.

On one hand, the asynchronous nature of the reactor pattern requires a different
programming style made of callbacks and things that happen at a later time, without
worrying too much about threads and race conditions. On the other hand, the module
pattern and its principles of simplicity and minimalism creates interesting new scenarios in
terms of reusability, maintenance, and usability.

Finally, besides the obvious technical advantages of being fast, efficient, and based on
JavaScript, Node.js is attracting so much interest because of the principles we have just
discovered. For many, grasping the essence of this world feels like returning to the origins,
to a more humane way of programming for both size and complexity and that's why
developers end up falling in love with Node.js. The introduction of ES2015 makes things
even more interesting and open new scenarios for being able to embrace all these
advantages with an even more expressive syntax.

In the next chapter, we will get into deep of the two basic asynchronous patterns used in
Node.js: the callback pattern and the event emitter. We will also understand the difference
between synchronous and asynchronous code and how to avoid to write unpredictable
functions.

[ 24 ]
Node.js Essential Patterns
2
Embracing the asynchronous nature of Node.js is not trivial at all, especially if coming from
a language such as PHP where it is not usual to deal with asynchronous code.

With synchronous programming we are used to imagine code as a series of consecutive


computing steps defined to solve a specific problem. Every operation is blocking which
means that only when an operation is completed it is possible to execute the next one. This
approach makes the code easy to understand and debug.

Instead, in asynchronous programming some operations like reading a file or performing a


network request can be executed asynchronously in the background. When an
asynchronous operation is performed, the next one is executed immediately, even if the
previous (asynchronous) operation has not finished yet. The operations pending on the
background can complete at any time and the whole application should be programmed to
react in the proper way when an asynchronous finishes.

While this non-blocking approach can guarantee superior performances compared to an


always-blocking scenario, it provides a paradigm that is hard to picture in mind and that
can get really cumbersome when dealing with more advanced applications that requires
complex control flows.

Node.js offers a series of tools and design patterns to deal optimally with asynchronous
code and it's important to learn how to use them to gain confidence with asynchronous
coding and write applications that are both performant and easy to understand and debug.

In this chapter, we will see two of the most important asynchronous patterns: callback and
event emitter.

The callback pattern


Random documents with unrelated
content Scribd suggests to you:
“I daresay, but it’s a funny way of showing it. You’d think they’d
have the sense to see, old people like them, that of course I know
more about him than they do.”
“But you know, he wants to go to school himself—really he does. He
says so.”
“I know,” said Rose briefly and bitterly.
“Well, then——?”
“Oh, of course, they’ve made him keen, telling him about the games
and all the rest of it. He didn’t want to go to school till it was put
into his head. You can make a child think it wants anything, even
castor oil, if you bluff it enough.”
“But school isn’t a nasty thing, like castor oil,” said Diana, with a sort
of ingenious stupidity.
“Chuck it,” Rose advised briefly. “You and me aren’t talking the same
language. We shouldn’t understand one another if we went on
jawring till we turned black in the face.”
No such disastrous consummation was achieved, but Miss Grierson-
Amberly seemed quite unable to abandon the discussion.
“But I do understand you, really and truly I do. Only it seems to me,
if you’ll forgive me for saying such a thing, that it would be more
unselfish of you to let Cecil do what he wants, and what everybody
else thinks best for him, than just to try and make him do what you
like. I’m afraid I’m expressing it stupidly, but I daresay you’ll
understand. After all, if one loves any one, one wants the best thing
for them, doesn’t one? And you know, boys learn heaps of things at
school that one simply can’t give them at home—playing the game
generally, and esprit de corps, and all that sort of thing.”
“I’ve heard every bit of this before, and I daresay it’s all quite true.
But as long as Ces remains what he is, he’ll go to no school. I’d as
soon send an epileptic child to school as him.”
“Oh, how can you!” The distress in Diana’s voice was most
unmistakably genuine. “Indeed, indeed, I’m certain you’re
exaggerating the whole thing most dreadfully. And even if he is as
naughty as you think, surely school would be the very——”
“Naughty!” Rose, like an explosion, repeated. “Who said he was
naughty? I’ll thank you to keep your advice about my boy till you’ve
got one of your own. You’ll know a bit more about it by that time,
perhaps.”
For the second time, Diana coloured deeply; but after a moment she
said unresentfully:
“I’m afraid I’ve vexed you, and I’m so awfully sorry. I really only said
it because I’ve known the Aviolets all my life, and Cecil is such a
dear little boy.”
The last words mollified Rose instantly.
“It’s all right. I’m sorry, too, if I was rude. Don’t let’s talk about it any
more.”
They made spasmodic conversation upon indifferent subjects until
Squires was reached. Rose, tired and out of spirits, trailing slowly
upstairs, heard Diana’s voice incautiously raised in Lady Aviolet’s
morning-room.
“I hope I’ve done some good, Cousin Catherine. I’ve been reading
the Riot Act, but of course——”
The door was closed, and Rose proceeded on her way, muttering
sub-audibly, “Damn her impudence!”
Her perceptions, acute, if inarticulate, sensed in Diana Grierson-
Amberly all the blind, limitless cruelty of the obtuse. She felt
strangely weak and frightened at the thought of it, as though
knowing that from that cruelty of the unimaginative there is no
appeal.
In the nursery, she found Cecil strutting about, reciting a sort of
saga, with the intensely disapproving eyes of Miss Wade fixed upon
him in a horrified stare.
“An’ there was elephants there, and a tiger, and—and horses as big
as lions; and they all lay down in front of me until I said, ‘Up!’ Like
that I said it, very loud and grand—‘UP!’ I said. That was in
Colombo, once.”
“Hallo, Ces,” Rose said rather wearily. She guessed, from the
expression of the governess, what was coming.
“I’m glad you’ve just happened to come in, Mrs. Aviolet. There’s a
little boy here who hardly seems to know the difference between
pretence and reality, I’m afraid.”
“What’s the matter?” Rose demanded ungraciously. She would not
even look at Miss Wade, and she kept one hand on Cecil’s forehead,
stroking back his thick, soft hair.
“Oh, I hope nothing’s the matter,” Miss Wade declared with sudden,
spurious brightness. “I’m sure Cecil will tell you himself that he’s only
been talking nonsense.”
“I’m not talking nonsense——”
“If you mean that rubbish I heard as I came in, about elephants and
tigers, it was nonsense, Ces, and you know it. You weren’t trying to
make Miss Wade believe it was true, were you? You wouldn’t be so
silly, a big boy like you.”
The appeal to Cecil’s vanity seemed to make him hesitate. At last he
gave an uncertain little laugh, and said: “No, Mummie. I only said it
for fun. It was just something I was inventing.”
Rose kissed him in sudden, passionate thankfulness.
“My precious! That’s a good boy!”
“It’s a pity, isn’t it, that Cecil should think it amusing to invent things
that never happened,” said Miss Wade mildly, “especially as we know
that he isn’t always quite as brave as he ought to be about telling
the exact truth. But I’m glad he’s been straightforward this time.”
Rose did not think that she looked glad.
“If Cecil may go into the garden for a while, Mrs. Aviolet, I should be
glad to speak to you.”
“All right.”
Rose made no attempt at all at displaying an amiability which she
was far from feeling.
“As we’re on the subject,” said the little governess nervously, “I
thought I’d really better speak to you. Cecil is a dear little boy and
I’m very fond of him, but I really don’t know what to do about his
want of truth. I’m sorry to have to say it, Mrs. Aviolet, but he’s
untruthful—downright untruthful.”
“Have you just found it out or did his grandmother tell you so?” Rose
asked truculently.
“Lady Aviolet never mentioned such a thing to me, nor did any one
else. I am in the habit of forming my own opinions as to the
character of my pupils. I am a student of child-psychology,” said Miss
Wade with dignity. “It is a most serious fault, and one that cannot be
corrected too young.”
“If you’re thinking of his nonsense just now, Miss Wade——”
The governess interrupted her firmly. “No, that has nothing to do
with it. I have been meaning to speak to you for some little while. I
should have thought little or nothing of his wild inventions of
imaginary adventures, if I had not, more than once, found him out in
a direct untruth.”
Rose groaned almost involuntarily.
“You knew of this fault already?”
“Yes, of course I did.”
“He is so young, and such a dear little boy, and so good otherwise
that I feel sure he can be corrected. But I must ask you, Mrs.
Aviolet, to let me have a free hand in dealing with this.”
“No.”
“I beg your pardon, Mrs. Aviolet?”
“I said, ‘No.’”
Miss Wade looked quite confounded.
“Now do you suppose,” Rose impatiently inquired, “that I should give
anybody a free hand, as you call it, in punishing my own child? What
am I his mother for, if I’m to go giving free hands to other people all
over the place? But you can tell me what your idea is—unless it’s
school, which, I may tell you, I’ve heard enough about—and a bit
over.”
“Cecil is hardly fit for school until he has learnt to speak the truth.”
“That’s the first word of sense I’ve heard spoken about it yet. Well,
fire ahead.”
“Mrs. Aviolet, I do not wish you to take it upon my word alone, and
therefore I will refer you to my authority. Monroe on the ‘Moral
Education of Children.’”
“And what has Monroe got to say about it?”
“‘There are two faults, and two only, for which corporal punishment
should be inflicted: deliberate cruelty, and deliberate untruth. We
need not add that it should be made perfectly clear to the child that
the punishment is not given in anger, still less in revenge.’” Miss
Wade relinquished the head voice by which she had denoted that
she was quoting, and resumed her natural rather nasal accents.
“I am deeply distressed at having to say it, but Cecil will never
realize the full gravity of this dreadful fault unless he is punished in
such a way that he will remember it. I have tried reasoning with
him, and coaxing him, and scolding him, and he is always sorry, but
it produces no real effect at all. Indeed, Mrs. Aviolet, I dislike the
idea more than I can tell you, and I have never in my life had to
punish a pupil in such a manner before, but I should be failing in my
duty if—if——”
Miss Wade faltered and produced her handkerchief, choked by what
Rose instantly recognized as a perfectly real emotion.
“Oh, don’t cry! Anyway, you know, it wouldn’t be you who’d have to
do it. You’re not nearly strong enough. Besides, you’d never go
through with it. I shouldn’t myself. I should sob and howl—roar, in
fact. But it’s a man’s job.”
Miss Wade looked at her with an air of rather resentful
astonishment.
“Then you have contemplated the idea of corporal punishment
already?”
“Spare the rod and spoil the child. Of course I have, Miss Wade.”
“In general, I am thoroughly opposed to the system of corporal
punishment,” said Miss Wade gloomily. “I follow Dr. Monroe’s
teaching, and he is quite averse to it. But, as he says himself,
persistent lying and persistent cruelty are in a class apart and must
be dealt with accordingly.”
“I’ll think about it.”
“I hope that the occasion may not present itself, but if it does, Mrs.
Aviolet, if Cecil tells a direct lie again, then I must ask you either to
deal with him on the lines that I have indicated, or else to let his
uncle do so.”
“Ask for something you’re a bit more likely to get, I should,” Rose
advised the outraged little governess. “If Cecil tells a direct lie, as
you call it, again, he shall be whipped. We’ve tried everything else,
and it may as well be that. But it’ll be me who’ll settle when it’s
done, and how, and who by. And another thing—I’m going to give
Ces fair warning about it. Perhaps it’ll help him to be careful, poor
lamb.”
She turned to go.
“One moment, Mrs. Aviolet, if you please. Has Cecil ever been—
castigated—before?”
“He’s been hit by his father,” said Rose briefly. “He’s never had
exactly what you might call a state whipping, so perhaps the
disgrace might make an impression on him. But I hope to goodness
we shan’t have to do it.”
She let the door slam on Miss Wade’s solemn reiteration of the hope,
already feeling that exasperation had committed her to a course of
action that her inner self disapproved.
Yet the thought of punishing little Cecil by beating him did not
horrify her. Her own mother had administered hearty and impetuous
slaps throughout Rose’s childhood, in moments of impatience, and
afterwards, as heartily and as impetuously, had smothered her with
kisses and given her slices of new bread thickly covered with jam.
Rose had borne no malice for the slaps, although they had always
caused her to roar lustily, for Mrs. Smith’s heavy-handed blows had
never been half-hearted affairs, and she had enjoyed the kisses and
the bread-and-jam.
“No bunkum from Dr. Monroe’s little books on Moral Education about
Mother!” Rose reminded herself, and smiled in a loving retrospective
appreciation of her parent’s thoroughness.
VIII
Two days later, Diana Grierson-Amberly left Squires, and Rose
received an answer to her letter.
298 Ovington Street,
London, S. W.
My dear Niece,
Yours of the 6th to hand, for which I thank you. I am
willing to receive you and the boy as you suggest, at any
date convenient to yourself, on a short visit. There will be
no need for you to help in the shop, as the time will be so
limited.
I have given much anxious thought and prayer to yourself
and to your child, my dear Rose, left alone in worldly
surroundings as I fear you are. If you have discovered the
hollowness and falseness of mere earthly grandeur, turn
your thoughts to that which never fails, if sought in true
humbleness of spirit. I will gladly advise you to the best of
my poor powers, but there is but One true Counsellor for
us all.
Kindly advise later as to date and hour of arrival.
Yours, etc.,
Alfred Smith.
A certain lack of enthusiasm as to the projected visit, apparent in
Uncle Alfred’s letter, no less than the careful underlining of his
pietistic sentiments, recalled him with singular vividness to the mind
of his niece as she read.
“It’ll be something, to get away from here,” she consoled herself.
After all, Uncle Alfred had nearly always been kind, in his own
strange way. She and her mother had laughed at him, but Mrs.
Smith had always steadily upheld Uncle Alfred’s claim to affection
and gratitude, because for many years he had given them a home.
And he had been nicer to Rose after her mother’s death, she
remembered.
“And, anyway, he won’t talk about ‘plans for the day’ at breakfast
every blessed morning, and I shall have Ces to sleep in my room
again.” She laughed out loud for very joy at the thought. There was
a foolish and inexplicable hope in her heart that if she and Cecil once
got away from Squires, they need never go back there. To herself,
Rose added in all honesty a modification of her ardent wish to cut
adrift from everything that the Aviolets stood for:
“After all, I daresay Lord Charlesbury would look us up in London.
And it would be much nicer to see him away from all of them.”
In spite of herself, she was nervous at the thought of making her
new plan known to Lady Aviolet, and she therefore did so in a casual
and blustering manner that gave the announcement an air of
unreality.
“Oh—did I tell you I’d heard from my uncle? He’s Mr. Alfred Smith,
who has a business in Ovington Street. (Well, it’s a pawnbroking
business, really.) I haven’t seen him since I married—and thought of
going up to him.”
“Did you, my dear? The train service is very good, so you have only
to let me know which day suits you and the carriage can take you to
the station for the early train, and meet you again at the six o’clock,
or the half-past eight, if you prefer it.”
“Oh, well, thank you very much, but I meant to stay there,” Rose
said awkwardly.
“Would that be necessary?”
“I should like it,” Rose replied defiantly.
Her mother-in-law was unmoved. “As you prefer, my dear.”
“I should want to take Cecil, of course.”
“Indeed? Do you think it any real kindness to disturb him? He seems
very happy, and looks so well. Besides, he is getting on nicely at his
lessons, and it seems hard on Miss Wade that they should be
interrupted.”
“She could have a holiday for a bit.”
“She has hardly been with us long enough to expect that.
Irregularity is so unsettling to a child, too. I hope you will be
unselfish enough to leave Cecil here, Rose, while you pay your visit.”
Lady Aviolet fixed her pale eyes upon Rose as she spoke, and they
expressed melancholy, in the very slight degree in which their flaccid
shallows ever expressed anything.
“I am Cecil’s grandmother, my dear, and so I am going to take upon
myself to tell you that you are a very selfish mother to the boy. I see
that you’re very fond of him—I quite see that—but you seem to have
so little idea of the tremendous sacrifices that motherhood demands.
Take this question of going away: you may say that you want Cecil
with you, because you can’t bear to be away from him, but don’t
you see that you’re only thinking of yourself? If you thought more of
Cecil, and less of yourself, you’d see the folly and unkindness of
disturbing and upsetting him by a change just when he is settling
down to a regular routine for the first time in his little life. And
London isn’t healthy for children like the country is. It won’t do him
any good.”
Lady Aviolet’s implacable, unselfconscious certainty of the complete
rightness of her own point of view daunted Rose curiously. Through
her mind there floated, incoherently, words and phrases that should
express her resentment. Difficulties—they always made difficulties—
nothing was ever allowed to happen without these complications of
argument, disapproval, condemnation ... things that ought to be
simple, made difficult. It was tiring ... and it made one angry too.
And how could any one decide that someone else was selfish, in that
arbitrary way? But she was unable to formulate her thoughts in
words, and stood shifting her weight from one foot to the other, like
a schoolgirl that is being scolded.
At last she said in a sulky tone that might, equally, have emanated
from the schoolgirl:
“I don’t see that at all. I’ve looked after Ces ever since he was born,
and I suppose I know what’s best for him.”
She was angrily aware, as she spoke, of the futility of the assertion.
So, apparently, was Lady Aviolet.
“That is as it may be, my dear. And of course you will do as you
think best. I can only advise you. But I should have thought that for
little Cecil’s own sake, you might be willing to forget yourself. I hope
I don’t expect to find old heads on young shoulders, but I should
have thought you had seen enough of life to realize that we mothers
have to sacrifice a great deal for our children. And they very often
disappoint us at the end of it all. But at least there is the comfort of
having done all one can.”
Rose, by an unwonted effort, repressed the retort that she longed to
utter. If the self-sacrifice of their mother had been responsible for
the ultimate evolution of the personalities of Ford and Jim Aviolet,
her most ardent wish would be never to emulate such disastrous
abnegation for the benefit of Cecil.
“Well, I’m sorry you don’t like the idea, but I’m afraid I’ve made up
my mind,” she said, abruptly and ungraciously.
“Then there is no more to be said, my dear. Perhaps you will be able
to explain matters to Miss Wade so that she does not resign her
situation, but you are acting with great unfairness towards her. If
Cecil is to be taken out of her hands like this, and his whole time
upset, you cannot expect her to have any real authority over the
child. I was beginning to hope that he was improving in every
respect under her management.”
Lady Aviolet’s intonation made it clear that her “every” meant “one.”
“Her latest idea is that he ought to be whipped for telling a story.”
“Painful though that would be, it might be the truest kindness to the
poor little fellow himself in the end. But I hope we need not consider
the question at all. I really do hope and believe that, under Miss
Wade’s management, Cecil is losing his weakness.”
Lady Aviolet’s hope—a plant of frail and ill-supported growth—was
not destined to fulfilment.
Rose appeared in the Lucians’ drawing-room one afternoon with
swollen eyelids, and said miserably to Henrietta:
“They’ve made me punish Cecil. At least, I suppose it wasn’t them
that made me, but I’ve had to do it. And yet I don’t really believe in
whipping a child—I was going dead against my own instinct, and I
knew it in a sort of way, but it seemed the only thing I hadn’t tried.”
“What happened?”
“Ces—poor darling—told a perfectly flat lie to Ford, of all people, and
that beast wanted to punish him himself, but, of course, I said I
wouldn’t allow that, and that I was the proper person to do it. But in
the end Sir Thomas did. I said he might, because I knew it would
impress Ces far more—and, besides, I knew I should howl and cry if
I had to hit his darling little body.”
Rose laughed tremulously, and openly put her handkerchief to her
eyes.
“Poor lamb, how did he take it?” Henrietta Lucian asked.
“He didn’t cry,” Rose said proudly. “He’s a plucky little fellow, and
he’s proud, too. I knew he wouldn’t make a sound, and he didn’t.
Even his grandfather said he’d been brave over it. Sir Thomas was
fairly decent about the whole thing, I will say. He gave Ces a talking
to about truth and all that, but it was very short, and then he gave
him six cuts with a little cane and left him. And I didn’t go to him.”
“Very brave of you, and I should think quite right.”
“It was hard,” Rose admitted.
“I’m so sorry for you, about the whole thing. Maurice and I often
talk about it. He’s interested, you know. I’m pretty sure he thinks it
isn’t little Cecil’s fault, in a way, but more like a congenital
misfortune.”
“He’s so brave about other things, it’s difficult to understand. I
suppose he’s had a rotten bringing up, poor darling, and that’s my
fault as much as any one’s. Don’t you think a marriage like mine is a
great mistake?”
“In what way?” Henrietta temporized.
“Marrying into a different class.”
“It’s apt to create difficult situations, I suppose.”
“You may say so!” Mrs. Aviolet remarked in heartfelt accents. “But it
isn’t only that—though to my dying day I don’t suppose I shall ever
see what they’re driving at, half the time—it’s the children. Inheriting
two lots of instincts, so to speak, poor little things. I know quite well
that my mother-in-law thinks poor little Cecil’s trouble is all owing to
his belonging what-you-may-call to the people, one side of him. In a
way, I suppose I agree. The high-and-mighty Aviolets were never
anything but honourable, were they?”
“In the conventional sense of the word, perhaps not,” said Miss
Lucian.
“The conventional sense of the word is all they want,” said Rose
simply, quite without irony.
She was very glad when the time came for her to take Cecil to
London. He had been wildly and defiantly naughty since his
punishment, but he had not again been untruthful.
“Wilful naughtiness is one thing, and underhand ways are another,”
Miss Wade primly observed. “I can understand a child—a boy
especially—being spoilt and disobedient from time to time, but there
is something terrible about a child that is habitually untruthful. It
seems so unnatural.”
“I think little Cecil’s disgrace the other day has shown him what a
frightful thing untruth is,” Lady Aviolet said. “I hope we may never
have to repeat such a thing.”
“It was evidently what the boy needed,” Sir Thomas said curtly.
It struck Rose that all of them unconsciously relied upon their own
powers of observation to tell them what effect the experiment in
discipline had had upon Cecil.
Hardly aware of the elementary psychological instinct that prompted
her, Rose trusted neither to their perceptions nor to her own. She
tried to find out from the little boy, himself, what their punishment
had meant to him.
“You won’t let them say ever again that you tell stories, will you,
darling? If one does slip out, come and tell Mother, and I promise no
one shall be angry or punish you. Only tell me about it.”
“Yes, Mummie.”
He was not looking at her.
“I had to ask Grandpa to whip you the other day, Ces, but it made
me very unhappy.”
“I’m so sorry, Mummie.” He had put his arms round her neck and
was kissing her eagerly. She hugged him.
“Sweetheart! You know we had to do something to make you
remember, and you will remember now, won’t you?”
“Yes. I didn’t cry when Grandpa hit me with his cane.”
“I know you didn’t, my own brave little man.”
“I wanted to scream out loud—it hurt so.”
She involuntarily tightened her hold round him.
“I was brave, wasn’t I, Mummie?” he asked her wistfully.
“Very brave, my darling.”
She could not deny him the acknowledgment, and it was only
afterwards that she realized herself to have been dimly puzzled by
his insistence.
Rose told Miss Wade that she was to have a holiday, and the
governess was quite as much offended as Lady Aviolet had predicted
that she would be, and offered to resign her situation. Rose only
wished that she possessed the courage to accept the offer.
The night before they went to London, she spoke to Ford, who had
detained her, with his air of suave autocracy, as she was following
Lady Aviolet upstairs.
“One moment, Rose. I want to know how soon you are likely to
bring Cecil back from town?”
Rose opened her brown eyes very widely, and spoke with a
purposely exaggerated astonishment.
“Why?”
“Because Cecil’s movements concern me, as his guardian,” said Ford
calmly.
“I’m his mother, thank you.”
Ford smiled very pleasantly.
“Oh, yes, you have equal rights of guardianship, of course. I had no
intention of implying anything else.”
“Equal!” Her voice held unbounded scorn.
“Quite equal.”
She swung round and faced him, her hands on her hips in an
attitude that had been frequently characteristic of her mother, her
head a little thrust forward.
“What utter nonsense you talk, Ford! You may call yourself Cecil’s
guardian till the cows come home, but a child belongs to its mother,
I’d have you know.”
“Ladies know so little about the English law,” Ford murmured. “Are
you really not aware, Rose, that in law a child has only one parent—
its father? If Jim were alive, he would have, strictly speaking, the
right to take Cecil away from you altogether, if he pleased. I’m not
for an instant suggesting that he would have thought of such a thing
—naturally—but I see you altogether fail to realize your position. It
has been ruled, very wisely, I think, that the father of a child can
appoint a guardian to act with the surviving parent, after his own
death. Now a mother has no such power. She can only appoint a
guardian after the death of both herself and the father. So you see
that your ownership of Cecil is very limited.”
Rose had turned white.
“If that’s the law of the land, it’s enough to make one sick. But I
don’t believe it.”
She did believe it, however. Ford was invariably accurate, and his
manner had carried conviction with it.
“Then I strongly advise you to inform yourself on the matter. It has
really seemed quite necessary for me to mention these facts that
you find so unpleasant, owing to your very persistently hostile
attitude to me, Rose. You appear to imagine that my attempts at
directing matters in which Cecil is concerned, rank as interference
pure and simple. So it seems to me better that I should state my
case frankly, and make you understand that I have quite a
substantial claim behind me.”
“Cecil’s grandparents——” Her voice shook so much from anger and
dismay that she could not go on.
“Have nothing to do with it, strictly speaking. The issue lies between
you and me, whilst Cecil is under sixteen, and I feel sure that we
shall work together more amicably after my little explanation. All I
ask you to remember is that our rights of guardianship”—his pause
stressed the words—“are equal. Yours and mine.”
“Damn Jim!” said Rose passionately. “And damn the laws of this
country, too, if they’re as unjust as all that.”
“H’sh—h’sh—h’sh——” He raised a slim hand authoritatively. “Forgive
me if I say that you yourself have done, and are doing, more than
any one to convince me of poor Jim’s wisdom in having appointed
me joint guardian with you to his son. No woman is fit to bring up a
boy entirely unaided, in my humble opinion.”
“She can bring him into the world unaided, though,” said Rose
bitterly. “It looks to me like all kicks and no halfpence, for the
woman, according to you.”
“Spare me a discussion on Woman’s Rights, Rose, I beg of you. The
subject holds not the least interest for me, and, moreover, I feel
convinced that we should differ widely in our views. All I ask you to
do is to let me know when Cecil is to return to his usual routine.”
“When I please, and not a day or a minute sooner,” said Mrs. Aviolet
with unconcealed temper blazing in her eyes and heightening the
pitch of her always high-pitched voice.
Ford shrugged his shoulders at the ill-breeding and turned away.
They exchanged no farewells on the following day.
In Rose’s mind was an unspecified determination that she and her
child would not return to Squires on the same terms as before, and
vague dreams of independence and freedom possessed her as the
train carried them towards London.
Cecil was openly delighted at the prospect of holidays and new
surroundings. He had only once before been taken by her to London
from Squires, for the purpose of visiting the dentist, and his
reminiscences of the occasion, his continual questions and
exclamations, pleased Rose as much as they did himself, in her
sudden exhilaration of spirits.
At the terminus, they engaged a hansom cab, symbolical to Rose of
“treats” that her mother had given her during her schooldays. In
spite of the excited little boy beside her, she could almost have
believed herself a schoolgirl again, her married life, Ceylon, and the
months spent at Squires, had all become equally misty and unreal.
She wondered if Uncle Alfred would have changed, and could hardly
realize that it was years since she had seen him.
“Mummie,” said Cecil, “will Uncle Alfred be nice? Will he like me?”
“If you’re good,” Rose made the traditional reply.
“Has he got a nice house?”
A faint misgiving assailed her. “It won’t be like Squires, you know,
darling. Not a big house.”
“But there’ll be a garden?”
“Well—no. But I’ll take you to the park sometimes.”
“Shall I be able to play cricket there?”
“Perhaps. Look, Ces, this is the Brompton Road.”
He looked eagerly out at the lighted thoroughfare. “Isn’t it noisy,
Mummie?”
“I suppose it is. I don’t know. One gets used to it pretty quickly. But
Uncle Alfred lives in a smaller street than this, and it’ll be quieter
there.”
The cab turned into a side street, then entered a narrower road
again, and finally drew up before a corner house at the furthest end
of the street.
“Goodness! Here we are!” said Rose. She fumbled excitedly for her
purse. “Get out, Ces. No, wait—let me get out first, and I’ll help you.
Hold the umbrella, like a good boy.”
“It’s raining, Mummie.”
“Never mind, we’ll be indoors in a minute. I’ll ring the area bell,
Cabby, and someone’ll give you a hand with the trunk.”
Rose pulled vigorously at the bell handle on the iron railings that
surmounted the area, but before the jangling reverberations had
ceased, a man had hurried out on to the pavement, now glistening
with wet.
“Mrs. Aviolet?”
“Hullo—why, it’s never Artie Millar! How are you?”
“I’m quite well, thank you, Mrs. Aviolet.”
They shook hands, and Rose said, “This is my kid—Cecil. Makes you
feel time’s gone on a bit, doesn’t it?”
“I should never have guessed it but for this young gentleman,” Mr.
Millar declared gallantly. “You haven’t altered in the very least.”
“Gammon!” said Mrs. Aviolet with a jovial heartiness that she had
seldom permitted herself at Squires. “Give the cabby a hand with the
box, will you? Is Uncle A. in the shop?”
“Upstairs. There’s a sitting-room on the first floor, now-a-days.
Here’s the girl, she’ll show you the way.”
“A girl too! Whatever next?” murmured Rose.
She paid the cabman, took Cecil’s hand, and followed the small maid
into the house. Cecil’s eyes widened as they went through the shop,
with a counter down one side of it, glass show-cases on the other,
an iron safe beyond the counter, and a match-board partition across
one half of the room. Beyond this, again, was a dark and steep
staircase, which they ascended.
“Why is it so dark, Mummie?”
“Hush! There’s Uncle Alfred.”
A short, stout figure loomed at the top of the stairs, and a small
white imperial scrubbed Rose’s face. With Cecil, Uncle Alfred only
shook hands.
“Come in, come in!”
His plump, curiously white hand, with a very large signet ring
gleaming on the little finger, waved them into the room. It was not
at all like any room at Squires. It was hung with a blue paper
powdered all over by large silver stars, and there was a round table
bearing an aspidistra in a pot on a ruffled lace mat, several books,
and an enormous Bible.
A lighted gas-jet hung from the middle of the ceiling and illuminated
the only two pictures, one above the mantelpiece, and the other one
at the far end of the room.
Both were coloured lithographs, framed alike in black-and-gilt wood,
one representing a fleshly Jewish woman drawing water at a well,
the other one depicting the prophet Daniel, erect and haughty,
amongst a crouching company of innocuous-looking lions.
“You haven’t changed, Uncle Alfred, not one bit.”
“Unless it’s to put on flesh, I daresay not. Well, I can’t say as much
for you, Rose. You look fully your age,” said Uncle Alfred cheerfully.
“Well, I’ve been through a lot, one way and another. And my age is
only twenty-five, so I don’t mind if I do look it.”
Mrs. Smith had early impressed upon Rose the advisability of
“standing up to” Uncle Alfred, and her exhortation had fallen upon
receptive ears. Quite instinctively, the old habit of years ago
resumed its sway.
Uncle Alfred turned his attentive, shrewd eyes, light green, like a
cat’s, upon little Cecil. His teeth were so prominent that the front
ones jutted out far beyond his lower lip. Even when he was serious,
as he usually was, and when, as now, he smiled—a rather slow,
wary smile—almost the whole row was exposed.
“How old are you, young sir?”
“I’m nearly eight.” Cecil always preferred this form to the more direct
declaration that he was seven years old.
“And do you know your catechism?”
“Some of it.”
“Very good. I shall examine you one of these days.”
Cecil looked rather alarmed. Miss Wade had taught him the meaning
of “examination.”
“No, not now. We are going to have supper now.”
“Do you still have supper in the old basement, Uncle A.?”
“No, Rose,” said Uncle Alfred with dignity. “My servant inhabits the
basement, and meals are served to me and my assistants in the
dining-room.”
“Assistants?”
“I have two assistants—Artie Millar, who has served me very well
indeed, and is now my salesman, and a young lad, who does the
work that Artie used to do when he first came here.”
“You must have done well with the business,” said Rose, impressed.
“The Lord has prospered me—to a certain extent,” Uncle Alfred
admitted. “If you will go upstairs to the room next to the store-room
you will find it ready for yourself and your child. What is his name?”
“Cecil, Uncle.”
“Neither Scriptural nor historical,” said Uncle Alfred sweepingly. “Take
him upstairs and wash his hands, and then we can sit at table
together.”
Rose obeyed, feeling fifteen years old again.
“Oh, Ces, it’s the very room mother and I had. There’s the old
picture of ‘The Soul’s Awakening’—look, Ces, isn’t it pretty?—but he’s
got new furniture. I wonder who’s been in here since I slept here
last.”
“Where’s the nursery, Mummie?”
“Where—oh, well, darling, you’re going to sleep in here with
Mummie, you know. Won’t that be fun?”
“Yes,” said Cecil rather doubtfully. “And where shall I play, and do my
lessons?”
“You’ll see to-morrow. Now wash your hands quickly—never mind a
sponge; I’ll unpack afterwards, and there’s a towel here.”
“It’s a very thick towel,” said Cecil, examining the coarse cotton
fibre, “and there’s no hot water.”
“Cold will do,” said Rose curtly.
For the first time it occurred to her that the months Cecil had spent
at Squires were as a lifetime to his childishness. He had come to
take the material comforts, to which Rose was naturally indifferent,
for granted. And it appeared that to him they were not indifferent.
He was very good during supper, but the cold mutton and salad did
not attract him, and the cheese that concluded the meal, Rose would
not let him eat. She remembered with a pang of remorse his mug of
fresh milk and his plate of biscuits, brought on a tray to the nursery
at Squires every evening.
“But I’ll be able to fix it all up with Uncle A. to-morrow,” she thought.
For her own part, she felt herself to have come home again. There
had hardly been a moment at Squires when she had not known
constraint of spirit, and her dependence upon entertainers whom
she whole-heartedly disliked had galled her incessantly.
Both Millar and the young assistant, a pale-faced youth introduced to
her as Felix Menebees, had supper with them.
As soon as the meal was over, Rose took Cecil upstairs and put him
to bed.
He was quiet, and seemed rather inclined to cry, but Rose effectually
checked this by a promise of the Zoo, and by undertaking to come to
bed herself in a very short time.
He had become accustomed to a night-light and she was obliged to
leave the gas lighted—the electric light was confined to the shop
downstairs—after making him promise that he would not touch it.
“I hope Uncle A. won’t find out,” Rose thought, with the old,
apprehensive feeling of half-amused guilt.
In the sitting-room, Uncle Alfred was reading The Pawnbrokers’
Gazette. The boy Felix had already gone downstairs, presumably to
Artie Millar’s old sleeping quarters in the shop beside the safe, and
Millar himself, the pawnbroker informed his niece, now lived in
lodgings at Wimbledon and only came in to business daily.
“Is he married?” Rose inquired. Certain old recollections, that did not
amount to emotions, had stirred within her at the sight of her first
fancy.
“He is a very God-fearing youth,” said Uncle Alfred, and after a
pause sufficient to mark the significance of the word, he added
solemnly, “now-a-days. He is not married.”
They exchanged hardly any other conversation, but Rose felt, with a
relief as profound as it was inexplicit, that she and her strange,
undemonstrative relative were mutually gratified at resuming a tie
that, however severely strained by incongruities of temperament,
was yet securely founded upon some essential similarity of outlook.
“Whatever else Uncle Alfred is, he’s alive,” Rose reflected. “And those
Aviolets at Squires are as dead as mutton—every blessed one of
them.”
IX
It appeared paradoxical that, whereas Rose had resented Squires
largely on Cecil’s account, she found the familiar life in Ovington
Street, agreeable to herself, resented by her little boy.
After the novelty of the first two days, he fretted and was
discontented. Rose took him for walks, but when it rained he was
obliged to remain in the sitting-room, with no amusement beyond a
small musical box that played “Rousseau’s Dream” over and over
again, and some old bound numbers of The Quiver.
He missed the garden at Squires, the animals, the rides and drives
to which he had become accustomed. As his mother ruefully
perceived, he even missed his governess, little Miss Wade. He was
not exactly naughty, but lifeless and fretful, and Rose began to see,
at first dimly and unwillingly, that her fanciful plan of resuming
existence over the pawnbroker’s shop was not destined to mature.
The routine of that life was little changed from the days when she
remembered it first.
Breakfast was at eight, and by nine o’clock, Millar had arrived and
Felix Menebees had taken the steel door of the shop off its hinges,
pushed up the steel blinds, and taken away their grooved supports
to the yard at the back of the house. Every day Felix cleaned the
windows, threw sawdust on the floor, and swept it up again. The
endless task of cleaning and polishing the plate and silver in stock
was also his, and Rose gave him the assistance that she had
sometimes, in the past, given to Artie Millar. Dinner was at mid-day,
and the afternoon work was almost a repetition of the morning’s. At
seven the pledge-office shut, and at eight the shop.
It seemed to Rose that even Uncle Alfred’s clients were identical with
those she had known years ago. The same shabby women seemed
to come in, with the same small pieces of jewellery, faithfully put
into pawn every Thursday morning and redeemed every Saturday
afternoon. The same depressed and earnest-looking Jews brought in
praying-shawls, brass candlesticks, and small brass mortars and
pestles, the latter to be redeemed only in time for the Passover. Even
the self-same arguments, that had once taken place between Uncle
Alfred and various of his clientèle, now took place between them and
Artie Millar.
“How much?”
“Thirty bob.”
“Just a moment.”
The moment was the one, or frequently the four or five, during
which Millar would examine the gold ring brought by the customer,
and find it, in the majority of cases, just below the market weight
required for the sum asked.
“Is twenty-five shillings any good to you?”
“No. I want thirty shillings badly. The fact is, the lady friend I’m
lodging with is laid up, and I’ve had to get in one or two little things,
and there’s been a trouble, like, with the landlord....”
The assistant always ruthlessly cut short these interpolations that as
invariably awoke in Rose an eager thrill of interested curiosity.
“Sorry, can’t let you have more than twenty-five shillings; it’s not
heavy enough.”
“Could you make it twenty-seven and six?”
Impossible, to Rose, to disappoint that last humble attempt at a
compromise. But Artie Millar never seemed to find any difficulty in
disassociating sentiment from business.
“Can’t be done. Twenty-five is all I can manage.”
“Very well, let’s have it.”
The client always succumbed, and Artie Millar always concluded by
calling out impassively:
“Felix, make out this ticket.”
He seldom asked whether or no the penny for the ticket were
forthcoming. His experienced eye told him, apparently, whether it
would be produced, or, without words, must be deducted from the
money handed over the counter in exchange for the trinket.
Rose felt a little surprised sometimes, recalling her early affair with
Millar. Her view of him was now singularly devoid of glamour, and
she wondered at the complete absence of the magnetic attraction
that each had once had for the other.
“It was youth, I suppose,” she told herself rather wistfully.
It had been youth, also, that had caused her to fall in love with
graceless Jim Aviolet, and give herself to him in marriage.
“As bad a day’s work as ever I did in my life,” Rose now summed up
that episode to herself with a sigh, adding always with remorseful
loyalty, “except for Ces.”
She had Cecil with her all day now, and at night he slept in a cot
drawn across the foot of her bed. She felt him to be hers again, as
she had never felt him so at Squires, and rejoiced fiercely.
Nevertheless it dawned upon her slowly, but certainly, that Cecil was
neither as well nor as happy as he had been at Squires.
Healthy he had always been, but he was not a robust child, and in
rather less than a week the difference in diet, the cramped
accommodation, and, perhaps, most of all, the absence of country
air and exercise, had taken some of the colour from his face and
drawn dark lines beneath his eyes.
“Grandmama would say I was selfish, fast enough, if she saw him
now, and I’m not sure she’d be so far out as she generally is, either,”
Rose reflected desperately.
She consulted Uncle Alfred.
“About how I’m to live, Uncle,” she began abruptly. “What would you
say would be a good way for me making money?”
“I thought your husband’s family were providing for you?”
“I mean, supposing I didn’t want them to go on providing for me.”
“Why should I suppose you wishful of casting aside that which the
Lord has raised up for the widow and the orphan? Be thankful for
their assistance, and do nothing to forfeit it, is my advice to you.”
The Scriptural turns of phrase employed by Mr. Smith rarely
interfered with the eminent practicalness of his point of view.
“You don’t know what the life is like, at that place. I’d go mad if I
had to go on there year after year. They never do anything but go
for walks in the mud and talk about their beastly gardens and their
horrid animals.”
“Fashionable folk are very godless, I understand,” said Uncle Alfred.
“I wouldn’t so much mind their being godless—and they aren’t, all—
my mother-in-law is as ‘pi’ as can be—but they all seem to me to be
half alive. There’s a girl there that they all seem dotty about—I
daresay she’ll marry Ford one of these days. Well, I give you my
word, Uncle, she’s a perfect fool. She can mess about with dogs and
things, and shoot, and they all think she’s clever, just because of
that. It shows you what they’re like, doesn’t it?”
“You need not adapt yourself to their standards,” Uncle Alfred said,
uncompromising rather than tactful. “But I presume that when your
boy once goes to school you will make your home elsewhere.”
“I haven’t made up my mind about Cecil going to school.”
“It is your duty to ensure the advantages of a good education for
him, Rose. Did I understand that there is a governess engaged
especially for him?”
“Yes. The best of everything is their motto, I will say that for them.”
“H’m. Are they interested in antiques—china and the like?”
“They’ve got more antiques in the house, and have had for about a
thousand years, than goes through the shop in a twelvemonth,”
returned Rose with candour.
“You can take some catalogues with you when you go back,” said
her uncle, unmoved.
“All right. If I do go back.”
“If?”
“Uncle, I do want to bring up Cecil my own way, and I’ve been
wondering if him and me need go back to Squires at all.”
“My dear niece, listen to me. You are flying in the face of Providence
when you suggest quarrelling with those who are prepared to give
your child all the advantages to which he is entitled, but which you
yourself are not in a position to bestow upon him. Wealth is dross
compared to the riches of the Spirit, and the highest in the land are
but as the beasts of the field that perish, if they know not Christ,”
said Uncle Alfred with great rapidity, “but you should look upon all
these things as being means to an end. You can do a great deal for
others with riches at your command.”
His eyes glistened covetously, and Rose remembered her mother’s
tolerant verdict that Uncle Alfred was always on the near side, unless
it was for a Foreign Mission.
“Haven’t they offered to send Cecil to a good school?”
“Not so much offered, as taken it for granted that I’d want him to
go.”
“It is most handsome—most handsome. I consider you a very
fortunate woman, Rose. And if, when the boy has gone to school,
you wish to return to your old quarters here, I am perfectly prepared
to come to an arrangement with you.”
“I’m sure it’s very kind of you, Uncle Alfred, but the fact is, I’m not
keen on Ces going to any of their precious schools. What I’m
wondering is if him and me couldn’t get off somewhere on our own,
and if the Aviolets get their monkey up and cut off my allowance,
what I can do to earn enough money for us both.”
“Nothing,” said Uncle Alfred crisply. “Nothing. Untrained young
women with no especial aptitude can only earn their living in one
profession, and that is not one which I could pollute your ears by
mentioning.”
“Goodness, Uncle A., you do pass the most far-fetched remarks,” his
niece exclaimed, stifling a laugh.
“Let me hear no more nonsense as to your husband’s relations. God
is not mocked, and it would be neither more nor less than deliberate
mockery to reject the provision that He has obviously made for you
and your child. You must bow to His decrees, and let me tell you
that the task, in your case, should be a particularly easy one.”
There was a tone of finality about Uncle Alfred’s delivery of his
exordium that Rose knew of old.
His verdict, once given, would never be recalled.
“However, thank goodness, I know Uncle A.,” his niece reflected. “His
bark’s worse than his bite, and he’d keep us here, worst come to the
worst, if I could scrape up money for our board. Only what can I do
with Cecil?”
When she had been away for nearly a fortnight, a letter came from
Squires. The sight of the thick blue-grey notepaper, with the
stamped address on the corner, brought the atmosphere of the place
for an instant into the crowded, untidy bedroom, full of cheap and
ugly furniture, where Rose stood and read it.
My dear Rose,
I had hoped to hear from you before this. Could you let
me know what day you and Cecil are returning, as I must
write to Miss Wade?
I hope the boy is well, and not giving you too much
trouble, with no one to relieve you of him. We quite miss
him here, and I do not like to think of him in London fogs,
which I see by the papers are beginning now. Quite fine
weather here since you left, though not much sun, and
the poor garden is beginning to look dull.
Yours affectionately,
Catherine Aviolet.
P. S. Ford has been down to Hurst, the preparatory school
we thought of for Cecil, and was very favourably
impressed. He is anxious to talk it all over with you.
Rose was roused to one of her sudden, vehement furies.
“That settles it! I won’t go back there, nor let Cecil either.”
She dashed into the shop, where Felix Menebees had just put up the
shutters.
“Is Mr. Millar there?”
“Here, Mrs. Aviolet.”
“I say, I want to ask you something. Is it true that a person—a
child’s guardian—has equal rights with the child’s mother?”
“In what respect, Mrs. Aviolet?”
“Any respect,” said Rose impatiently. “If he’s appointed by the child’s
father’s will, I mean.”
“Felix, bring me Whittaker’s Almanac,” commanded Millar.
“Oh, will it be there? I never thought of that. It might tell me a lot of
things. May I have it?”
“Certainly. If I can be of any assistance——?”
“No, no, I know you’re busy.”
Rose snatched the volume from the hands of Felix Menebees and
took it away.
That night she asked Cecil, who was awake and restless when she
came to bed:
“Wouldn’t you like to come right away with Mummie somewhere?”
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like