100% found this document useful (3 votes)
29 views

Design Patterns in .NET 6: Reusable Approaches in C# and F# for Object-Oriented Software Design 3rd Edition Dmitri Nesteruk 2024 scribd download

Software

Uploaded by

ladandoody0c
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
29 views

Design Patterns in .NET 6: Reusable Approaches in C# and F# for Object-Oriented Software Design 3rd Edition Dmitri Nesteruk 2024 scribd download

Software

Uploaded by

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

Get ebook downloads in full at ebookmeta.

com

Design Patterns in .NET 6: Reusable Approaches in


C# and F# for Object-Oriented Software Design 3rd
Edition Dmitri Nesteruk

https://ebookmeta.com/product/design-patterns-in-
net-6-reusable-approaches-in-c-and-f-for-object-oriented-
software-design-3rd-edition-dmitri-nesteruk/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


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

Design Patterns in .NET: Reusable Approaches in C# and F#


for Object-Oriented Software Design 1st Edition Dmitri
Nesteruk
https://ebookmeta.com/product/design-patterns-in-net-reusable-
approaches-in-c-and-f-for-object-oriented-software-design-1st-edition-
dmitri-nesteruk/
ebookmeta.com

Design Patterns in Modern C++20: Reusable Approaches for


Object-Oriented Software Design 2nd Edition Dmitri
Nesteruk
https://ebookmeta.com/product/design-patterns-in-modern-c20-reusable-
approaches-for-object-oriented-software-design-2nd-edition-dmitri-
nesteruk/
ebookmeta.com

Design Patterns in Modern C++20: Reusable Approaches for


Object-Oriented Software Design 2nd Edition Dmitri
Nesteruk
https://ebookmeta.com/product/design-patterns-in-modern-c20-reusable-
approaches-for-object-oriented-software-design-2nd-edition-dmitri-
nesteruk-2/
ebookmeta.com

Get In My Swamp An Ogre Love Story G M Fairy

https://ebookmeta.com/product/get-in-my-swamp-an-ogre-love-story-g-m-
fairy/

ebookmeta.com
Litt's Drug Eruption & Reaction Manual, 28th Edition Neil
H. Shear

https://ebookmeta.com/product/litts-drug-eruption-reaction-
manual-28th-edition-neil-h-shear/

ebookmeta.com

The Eye of the Crown Routledge Research in Early Modern


History 1st Edition Kristin M.S. Bezio

https://ebookmeta.com/product/the-eye-of-the-crown-routledge-research-
in-early-modern-history-1st-edition-kristin-m-s-bezio/

ebookmeta.com

The Magnificent Mountain Women Adventures in the Colorado


Rockies 2nd Edition Janet Robertson

https://ebookmeta.com/product/the-magnificent-mountain-women-
adventures-in-the-colorado-rockies-2nd-edition-janet-robertson/

ebookmeta.com

Hard on the Boss 1st Edition Tarin Lex

https://ebookmeta.com/product/hard-on-the-boss-1st-edition-tarin-lex/

ebookmeta.com

Novel Engineering, K-8 : An Integrated Approach to


Engineering and Literacy 1st Edition Elissa Milto

https://ebookmeta.com/product/novel-engineering-k-8-an-integrated-
approach-to-engineering-and-literacy-1st-edition-elissa-milto/

ebookmeta.com
Alternative Societies For a Pluralist Socialism 1st
Edition Luke Martell

https://ebookmeta.com/product/alternative-societies-for-a-pluralist-
socialism-1st-edition-luke-martell/

ebookmeta.com
Design Patterns in .NET 6
Reusable Approaches in C# and F#
for Object-Oriented Software Design
Third Edition

Dmitri Nesteruk
Design Patterns in .NET 6: Reusable Approaches in C# and F# for Object-Oriented
Software Design
Dmitri Nesteruk
St. Petersburg, c.St-Petersburg, Russia

ISBN-13 (pbk): 978-1-4842-8244-1 ISBN-13 (electronic): 978-1-4842-8245-8


https://doi.org/10.1007/978-1-4842-8245-8

Copyright © 2022 by Dmitri Nesteruk


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Joan Murray
Development Editor: Laura Berendson
Coordinating Editor: Jill Balzano
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza,
Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@
springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole
member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc
is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback,
or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub (https://github.com/Apress). For more detailed information, please visit http://www.
apress.com/source-code.
Printed on acid-free paper
The forces of light shall overcome the forces of darkness.
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii

Introduction������������������������������������������������������������������������������������������������������������xix

Part I: Introduction����������������������������������������������������������������������������������������� 1
Chapter 1: The SOLID Design Principles������������������������������������������������������������������� 3
Single Responsibility Principle������������������������������������������������������������������������������������������������������ 3
Open-Closed Principle������������������������������������������������������������������������������������������������������������������ 6
Liskov Substitution Principle������������������������������������������������������������������������������������������������������� 13
Interface Segregation Principle�������������������������������������������������������������������������������������������������� 15
Parameter Object������������������������������������������������������������������������������������������������������������������� 20
Dependency Inversion Principle�������������������������������������������������������������������������������������������������� 21

Chapter 2: The Functional Perspective������������������������������������������������������������������� 25


Function Basics��������������������������������������������������������������������������������������������������������������������������� 25
Functional Literals in C#������������������������������������������������������������������������������������������������������������� 27
Storing Functions in C#��������������������������������������������������������������������������������������������������������������� 28
Functional Literals in F#�������������������������������������������������������������������������������������������������������������� 30
Composition�������������������������������������������������������������������������������������������������������������������������������� 32
Functional-Related Language Features�������������������������������������������������������������������������������������� 33

Part II: Creational Patterns��������������������������������������������������������������������������� 35


Chapter 3: Builder��������������������������������������������������������������������������������������������������� 37
Scenario�������������������������������������������������������������������������������������������������������������������������������������� 37
Simple Builder����������������������������������������������������������������������������������������������������������������������������� 40
Fluent Builder������������������������������������������������������������������������������������������������������������������������������ 41

v
Table of Contents

Static Initialization���������������������������������������������������������������������������������������������������������������������� 41
Communicating Intent����������������������������������������������������������������������������������������������������������������� 42
Nested Builder and Immutability������������������������������������������������������������������������������������������������� 44
Composite Builder����������������������������������������������������������������������������������������������������������������������� 45
Builder Marker Interfaces����������������������������������������������������������������������������������������������������������� 49
Stepwise Builder (Wizard)����������������������������������������������������������������������������������������������������������� 51
Builder Parameter����������������������������������������������������������������������������������������������������������������������� 56
Builder Extension with Recursive Generics�������������������������������������������������������������������������������� 58
Lazy Functional Builder��������������������������������������������������������������������������������������������������������������� 62
Builder-Decorator������������������������������������������������������������������������������������������������������������������������ 65
Scoping Builder Method�������������������������������������������������������������������������������������������������������������� 68
DSL Construction in F#���������������������������������������������������������������������������������������������������������������� 69
Summary������������������������������������������������������������������������������������������������������������������������������������ 70

Chapter 4: Factories����������������������������������������������������������������������������������������������� 73
Scenario�������������������������������������������������������������������������������������������������������������������������������������� 73
Factory Method��������������������������������������������������������������������������������������������������������������������������� 75
Asynchronous Factory Method��������������������������������������������������������������������������������������������������� 76
Factory���������������������������������������������������������������������������������������������������������������������������������������� 77
Inner Factory������������������������������������������������������������������������������������������������������������������������������� 78
Physical Separation��������������������������������������������������������������������������������������������������������������� 79
Abstract Factory�������������������������������������������������������������������������������������������������������������������������� 79
Delegate Factories in IoC������������������������������������������������������������������������������������������������������������ 83
Object Tracking and Bulk Replacements������������������������������������������������������������������������������������� 85
Object Tracking���������������������������������������������������������������������������������������������������������������������� 85
Bulk Modifications����������������������������������������������������������������������������������������������������������������� 87
Functional Factory���������������������������������������������������������������������������������������������������������������������� 90
Summary������������������������������������������������������������������������������������������������������������������������������������ 91

vi
Table of Contents

Chapter 5: Prototype����������������������������������������������������������������������������������������������� 93
Deep vs. Shallow Copying����������������������������������������������������������������������������������������������������������� 93
ICloneable Is Bad������������������������������������������������������������������������������������������������������������������������ 94
Deep Copying via Copy Construction������������������������������������������������������������������������������������������ 96
Note on Record Classes�������������������������������������������������������������������������������������������������������������� 97
Deep Copying with a Special Interface��������������������������������������������������������������������������������������� 97
Deep Copying and Inheritance����������������������������������������������������������������������������������������������� 98
Deep Copying Guidelines���������������������������������������������������������������������������������������������������������� 102
Trivially Copyable Types������������������������������������������������������������������������������������������������������� 103
Arrays���������������������������������������������������������������������������������������������������������������������������������� 103
Common Collection Types���������������������������������������������������������������������������������������������������� 104
MemberwiseClone Is Not Terrible���������������������������������������������������������������������������������������� 105
Summary���������������������������������������������������������������������������������������������������������������������������������� 106
Serialization������������������������������������������������������������������������������������������������������������������������������ 107
Prototype Factory���������������������������������������������������������������������������������������������������������������������� 109
Source Generators�������������������������������������������������������������������������������������������������������������������� 110
Summary���������������������������������������������������������������������������������������������������������������������������������� 111

Chapter 6: Singleton��������������������������������������������������������������������������������������������� 113


Singleton by Convention����������������������������������������������������������������������������������������������������������� 113
Classic Implementation������������������������������������������������������������������������������������������������������������� 114
Lazy Loading and Thread Safety������������������������������������������������������������������������������������������ 115
Reusable Base Class����������������������������������������������������������������������������������������������������������� 116
The Trouble with Singleton������������������������������������������������������������������������������������������������������� 117
Per-Thread Singleton���������������������������������������������������������������������������������������������������������������� 121
Ambient Context������������������������������������������������������������������������������������������������������������������������ 122
Uses in the .NET Framework����������������������������������������������������������������������������������������������� 126
Singletons and Inversion of Control������������������������������������������������������������������������������������������ 127
Monostate��������������������������������������������������������������������������������������������������������������������������������� 128
Multiton������������������������������������������������������������������������������������������������������������������������������������� 129
Summary���������������������������������������������������������������������������������������������������������������������������������� 130

vii
Table of Contents

Part III: Structural Patterns������������������������������������������������������������������������ 131


Chapter 7: Adapter����������������������������������������������������������������������������������������������� 133
Scenario������������������������������������������������������������������������������������������������������������������������������������ 133
Adapter������������������������������������������������������������������������������������������������������������������������������������� 135
Adapter Temporaries����������������������������������������������������������������������������������������������������������������� 136
The Problem with Hashing�������������������������������������������������������������������������������������������������������� 140
Property Adapter (Surrogate)���������������������������������������������������������������������������������������������������� 142
Generic Value Adapter��������������������������������������������������������������������������������������������������������������� 144
Adapter in Dependency Injection���������������������������������������������������������������������������������������������� 152
Bidirectional Adapter����������������������������������������������������������������������������������������������������������������� 155
Adapters in the .NET Framework���������������������������������������������������������������������������������������������� 156
Summary���������������������������������������������������������������������������������������������������������������������������������� 157

Chapter 8: Bridge�������������������������������������������������������������������������������������������������� 159


Conventional Bridge������������������������������������������������������������������������������������������������������������������ 159
Dynamic Prototyping Bridge����������������������������������������������������������������������������������������������������� 163
Summary���������������������������������������������������������������������������������������������������������������������������������� 166

Chapter 9: Composite������������������������������������������������������������������������������������������� 167


Grouping Graphic Objects��������������������������������������������������������������������������������������������������������� 167
Neural Networks����������������������������������������������������������������������������������������������������������������������� 170
Shrink Wrapping the Composite����������������������������������������������������������������������������������������������� 173
Composite Specification����������������������������������������������������������������������������������������������������������� 175
Summary���������������������������������������������������������������������������������������������������������������������������������� 178

Chapter 10: Decorator������������������������������������������������������������������������������������������ 179


The Basics of Delegation���������������������������������������������������������������������������������������������������������� 180
Points and Lines������������������������������������������������������������������������������������������������������������������������ 182
Adapter-Decorator��������������������������������������������������������������������������������������������������������������������� 185
Simulating Multiple Inheritance������������������������������������������������������������������������������������������������ 185
Multiple Inheritance with Interfaces����������������������������������������������������������������������������������������� 186

viii
Table of Contents

Multiple Inheritance with Default Interface Members�������������������������������������������������������������� 189


Dynamic Decorator Composition����������������������������������������������������������������������������������������������� 191
Decorator Cycle Policies����������������������������������������������������������������������������������������������������������� 194
Static Decorator Composition��������������������������������������������������������������������������������������������������� 200
Functional Decorator����������������������������������������������������������������������������������������������������������������� 201
Summary���������������������������������������������������������������������������������������������������������������������������������� 202

Chapter 11: Façade����������������������������������������������������������������������������������������������� 205


Magic Squares�������������������������������������������������������������������������������������������������������������������������� 206
Building a Trading Terminal������������������������������������������������������������������������������������������������������� 211
An Advanced Terminal��������������������������������������������������������������������������������������������������������������� 212
Where’s the Façade?���������������������������������������������������������������������������������������������������������������� 214
IoC Modules������������������������������������������������������������������������������������������������������������������������������ 216
Summary���������������������������������������������������������������������������������������������������������������������������������� 218

Chapter 12: Flyweight������������������������������������������������������������������������������������������ 219


User Names������������������������������������������������������������������������������������������������������������������������������� 219
Text Formatting������������������������������������������������������������������������������������������������������������������������� 222
Using Flyweights for Interop����������������������������������������������������������������������������������������������������� 225
Summary���������������������������������������������������������������������������������������������������������������������������������� 226

Chapter 13: Proxy������������������������������������������������������������������������������������������������� 227


Protection Proxy������������������������������������������������������������������������������������������������������������������������ 227
Property Proxy��������������������������������������������������������������������������������������������������������������������������� 229
Composite Proxy: SoA/AoS�������������������������������������������������������������������������������������������������������� 232
Composite Proxy with Array-Backed Properties����������������������������������������������������������������������� 235
Virtual Proxy������������������������������������������������������������������������������������������������������������������������������ 237
Communication Proxy��������������������������������������������������������������������������������������������������������������� 240
Dynamic Proxy for Logging������������������������������������������������������������������������������������������������������� 242
Composite Proxy����������������������������������������������������������������������������������������������������������������������� 245
Summary���������������������������������������������������������������������������������������������������������������������������������� 248

ix
Table of Contents

Chapter 14: Value Object�������������������������������������������������������������������������������������� 251


Two-Dimensional Point������������������������������������������������������������������������������������������������������������� 252
Percentage Value���������������������������������������������������������������������������������������������������������������������� 253
Units of Measure����������������������������������������������������������������������������������������������������������������������� 255
Summary���������������������������������������������������������������������������������������������������������������������������������� 257

Part IV: Behavioral Patterns����������������������������������������������������������������������� 259


Chapter 15: Chain of Responsibility��������������������������������������������������������������������� 261
Scenario������������������������������������������������������������������������������������������������������������������������������������ 261
Method Chain���������������������������������������������������������������������������������������������������������������������������� 262
Broker Chain����������������������������������������������������������������������������������������������������������������������������� 265
Functional Chain of Responsibility�������������������������������������������������������������������������������������������� 270
Summary���������������������������������������������������������������������������������������������������������������������������������� 271

Chapter 16: Command������������������������������������������������������������������������������������������ 273


Scenario������������������������������������������������������������������������������������������������������������������������������������ 273
Implementing the Command Pattern���������������������������������������������������������������������������������������� 274
Undo Operations����������������������������������������������������������������������������������������������������������������������� 276
Composite Commands (aka Macros)���������������������������������������������������������������������������������������� 279
Functional Command���������������������������������������������������������������������������������������������������������������� 283
Queries and Command-Query Separation�������������������������������������������������������������������������������� 285
Summary���������������������������������������������������������������������������������������������������������������������������������� 285

Chapter 17: Interpreter����������������������������������������������������������������������������������������� 287


Integer Parsing�������������������������������������������������������������������������������������������������������������������������� 288
Numeric Expression Evaluator�������������������������������������������������������������������������������������������������� 289
Lexing���������������������������������������������������������������������������������������������������������������������������������� 290
Parsing�������������������������������������������������������������������������������������������������������������������������������� 292
Using Lexer and Parser������������������������������������������������������������������������������������������������������� 296
Interpretation in the Functional Paradigm�������������������������������������������������������������������������������� 296
Transpiler���������������������������������������������������������������������������������������������������������������������������������� 300
Summary���������������������������������������������������������������������������������������������������������������������������������� 302

x
Table of Contents

Chapter 18: Iterator���������������������������������������������������������������������������������������������� 305


Array-Backed Properties����������������������������������������������������������������������������������������������������������� 306
Let’s Make an Iterator��������������������������������������������������������������������������������������������������������������� 309
Improved Iteration��������������������������������������������������������������������������������������������������������������������� 312
Iterator Specifics����������������������������������������������������������������������������������������������������������������������� 314
Iterator Adapter������������������������������������������������������������������������������������������������������������������������� 315
Composite Iteration������������������������������������������������������������������������������������������������������������������� 317
Summary���������������������������������������������������������������������������������������������������������������������������������� 319

Chapter 19: Mediator�������������������������������������������������������������������������������������������� 321


Chat Room�������������������������������������������������������������������������������������������������������������������������������� 321
Mediator with Events���������������������������������������������������������������������������������������������������������������� 326
Introduction to MediatR������������������������������������������������������������������������������������������������������������ 330
Service Bus as Mediator����������������������������������������������������������������������������������������������������������� 332
Summary���������������������������������������������������������������������������������������������������������������������������������� 333

Chapter 20: Memento������������������������������������������������������������������������������������������� 335


Bank Account���������������������������������������������������������������������������������������������������������������������������� 335
Undo and Redo�������������������������������������������������������������������������������������������������������������������������� 337
Memento and Command����������������������������������������������������������������������������������������������������������� 340
Summary���������������������������������������������������������������������������������������������������������������������������������� 341

Chapter 21: Null Object����������������������������������������������������������������������������������������� 343


Scenario������������������������������������������������������������������������������������������������������������������������������������ 343
Intrusive Approaches���������������������������������������������������������������������������������������������������������������� 345
Nullable Virtual Proxy���������������������������������������������������������������������������������������������������������� 346
Null Object�������������������������������������������������������������������������������������������������������������������������������� 347
Null Object Singleton���������������������������������������������������������������������������������������������������������������� 348
Dynamic Null Object������������������������������������������������������������������������������������������������������������������ 349
Drawbacks��������������������������������������������������������������������������������������������������������������������������� 350
Summary���������������������������������������������������������������������������������������������������������������������������������� 351

xi
Table of Contents

Chapter 22: Observer�������������������������������������������������������������������������������������������� 353


Events��������������������������������������������������������������������������������������������������������������������������������������� 353
Weak Event Pattern������������������������������������������������������������������������������������������������������������������� 355
Event Streams��������������������������������������������������������������������������������������������������������������������������� 357
Property Observers������������������������������������������������������������������������������������������������������������������� 361
Basic Change Notification��������������������������������������������������������������������������������������������������� 361
Bidirectional Bindings��������������������������������������������������������������������������������������������������������� 363
Property Dependencies������������������������������������������������������������������������������������������������������� 366
Views����������������������������������������������������������������������������������������������������������������������������������� 372
Case Study: Quadratic Equation Solver������������������������������������������������������������������������������� 374
Circular Recalculation Limitations��������������������������������������������������������������������������������������� 376
Observable Collections������������������������������������������������������������������������������������������������������������� 377
Observable LINQ������������������������������������������������������������������������������������������������������������������ 378
Declarative Subscriptions in Autofac���������������������������������������������������������������������������������������� 378
Summary���������������������������������������������������������������������������������������������������������������������������������� 382

Chapter 23: State�������������������������������������������������������������������������������������������������� 383


State-Driven State Transitions�������������������������������������������������������������������������������������������������� 384
Enum-Based State Machine������������������������������������������������������������������������������������������������������ 387
Switch-Based State Machine���������������������������������������������������������������������������������������������������� 390
Encoding Transitions with Switch Expressions������������������������������������������������������������������������� 392
State Machines with Stateless������������������������������������������������������������������������������������������������� 394
Types, Actions, and Ignoring Transitions������������������������������������������������������������������������������ 395
Reentrancy Again����������������������������������������������������������������������������������������������������������������� 396
Hierarchical States�������������������������������������������������������������������������������������������������������������� 397
More Features��������������������������������������������������������������������������������������������������������������������� 397
Concurrent State Machines������������������������������������������������������������������������������������������������������� 398
Implicit State Machines������������������������������������������������������������������������������������������������������������ 399
Summary���������������������������������������������������������������������������������������������������������������������������������� 399

xii
Table of Contents

Chapter 24: Strategy��������������������������������������������������������������������������������������������� 401


Dynamic Strategy���������������������������������������������������������������������������������������������������������������������� 401
Static Strategy�������������������������������������������������������������������������������������������������������������������������� 404
Equality and Comparison Strategies����������������������������������������������������������������������������������������� 406
Functional Strategy������������������������������������������������������������������������������������������������������������������� 408
Declarative Strategies��������������������������������������������������������������������������������������������������������������� 409
Summary���������������������������������������������������������������������������������������������������������������������������������� 410

Chapter 25: Template Method������������������������������������������������������������������������������� 411


Game Simulation����������������������������������������������������������������������������������������������������������������������� 411
Template Method Mixin������������������������������������������������������������������������������������������������������������� 413
Functional Template Method����������������������������������������������������������������������������������������������������� 415
Summary���������������������������������������������������������������������������������������������������������������������������������� 416

Chapter 26: Visitor������������������������������������������������������������������������������������������������ 417


Intrusive Visitor������������������������������������������������������������������������������������������������������������������������� 418
Reflective Visitor����������������������������������������������������������������������������������������������������������������������� 419
Extension Methods?������������������������������������������������������������������������������������������������������������ 422
Functional Reflective Visitor (C#)����������������������������������������������������������������������������������������� 424
Functional Reflective Visitor (F#)����������������������������������������������������������������������������������������� 426
Improvements���������������������������������������������������������������������������������������������������������������������� 427
What Is Dispatch?��������������������������������������������������������������������������������������������������������������������� 428
Dynamic Visitor������������������������������������������������������������������������������������������������������������������������� 430
Classic Visitor���������������������������������������������������������������������������������������������������������������������������� 432
Abstract Classes and Virtual Methods��������������������������������������������������������������������������������� 435
Reducing Boilerplate����������������������������������������������������������������������������������������������������������� 437
Implementing an Additional Visitor�������������������������������������������������������������������������������������� 437
Type Checks Are Unavoidable��������������������������������������������������������������������������������������������������� 439
Acyclic Visitor���������������������������������������������������������������������������������������������������������������������������� 441
Visitable Null Object������������������������������������������������������������������������������������������������������������������ 443

xiii
Table of Contents

Visitor Adapter��������������������������������������������������������������������������������������������������������������������������� 447


Reductions and Transforms������������������������������������������������������������������������������������������������������ 450
Functional Visitor in F#�������������������������������������������������������������������������������������������������������������� 454
Summary���������������������������������������������������������������������������������������������������������������������������������� 455

Index��������������������������������������������������������������������������������������������������������������������� 457

xiv
About the Author
Dmitri Nesteruk is a quantitative analyst, developer, course
instructor, book author, and an occasional conference
speaker. His interests lie in software development
and integration practices in the areas of computation,
quantitative finance, and algorithmic trading. His
technological interests include C# and C++ programming
as well as high-­performance computing using technologies
such as CUDA and FPGAs.

xv
Other documents randomly have
different content
and comical person of whom he writes. There is a vein of cruelty or
of selfishness in some of the others who follow one another through
his pages. The worst of them is the “phenomenally brutal”
sportsman who, along with Mr. Douglas, gave a dead rat to a sow to
eat:

She engulfed the corpse methodically, beginning at the


end, working her way through breast and entrails while her
chops dripped with gore, and ending with the tail, which gave
some little trouble to masticate, on account, of its length and
tenuity. Altogether decidedly good sport....

That is disgusting, but it is interesting. We may say the same of the


sardonic account of the way in which lizards are played with in Italy:

It is not very amusing to be either a snake or a lizard in


Italy. Lizards are caught in nooses and then tied by one leg
and made to run on the remaining three; or secured by a
cord round the neck and swung about in the air—mighty good
sport, this; or deprived of their tails and given to the baby or
cat to play with; or dragged along at the end of a string, like
a reluctant pig that is led to market. There are quite a
number of ways of making a lizard feel at home.

On the whole, one prefers to read Mr. Douglas on the subject of


wine, or on the rarity of the use of red things (wine excepted) in
Italy, or on the little flames that are supposed to be seen at night
over the graves in cemeteries. Mr. Douglas may be gross at times,
but he is never a bore. He gives us a meal of many courses, and
allows none of the courses to last too long. But it would be a more
enjoyable meal if we did not hear in the crabbed laughter of our host
the undertones of despair—the despair that comes of “considering
your neighbour, what an imbecile he is,” and failing to realise that in
order to enjoy his imbecility to the full you must first see him a little
lower than the angels. Cervantes did this. Dickens did it. Mr.
Chesterton does it. That is why they are not “for the fastidious in
particular.”
XV
M. ANDRÉ GIDE MAKES A JOKE

Lady Rothermere does not measure her praise of M. Gide, whose


Prometheus Illbound she has translated into English. His is “a mind,”
she declares, “which must be ranked among the greatest of the
world’s literature.” “Must” is a challenging word. Of how many
contemporary writers dare we use it in this sense? Dare we use it of
Anatole France, or Bergson, or Hardy, or Shaw, or d’Annunzio, or
Croce? We should be foolhardy, indeed, much as we rightly admire
these authors, to put any of them just yet into the pantheon that
contains the images of Plato and Shakespeare and Voltaire. Call no
man happy till he is dead, says an old proverb. It would be still wiser
to call no man one of the world’s greatest writers till he has been
dead a hundred years. One cannot, if one is a quite human being,
judge one’s contemporaries with the same impartial scrutiny with
which one judges the mighty dead. The great man gives to his own
age much to which posterity is indifferent, and gives to posterity
much to which his own age may even be hostile. Tennyson served
his age as a giant, and he was accepted as a giant by most of the
fine critics of his age, from Edgar Allan Poe downwards. If an
occasional critic such as Edward FitzGerald came to have doubts
about Tennyson, it was because he himself stood monastically aloof
from the age. It is one of the functions of criticism, no doubt, to
separate the temporary from the immortal elements in the work of
contemporary writers. But this is one of the counsels of perfection in
criticism. The thing has never been infallibly done. Sainte-Beuve was
as ridiculous in writing about Balzac as Lamb was about Shelley. Not
that even posterity is capable of pronouncing what we call final
judgments. We have a way of turning to posterity in despair for a
true verdict on authors. Alas! posterity, though it has not the same
reasons for erroneous judgments, is (like ourselves) of a variable
and uncertain mind. Posterity has made strange blunders about
Euripides, about Ronsard, about Donne, about Pope. Good authors
constantly have to be rescued from the neglect of posterity. All we
can be sure of is that an author who appeals to a succession of
generations has given us something of the true gold of literature.
Even if each new generation to some extent re-estimates the world’s
classics, it usually leaves them secure in the position of classics. Or
almost secure, for who knows whether the world will not one day
cease to read Lucian or Virgil, or The Pilgrim’s Progress?
As for contemporary literature, how much of it is there that we
dare confidently add to the ranks even of the minor classics? One is
sure of a certain number of lyrics, notably those of Mr. Yeats. But in
prose one has to be more cautious. Prose, as Sir Arthur Quiller-
Couch lamented the other day, has fallen upon styleless days, and
without style it is difficult to live for ever. Plutarch has survived with
a minimum of it, and so has Marcus Aurelius, and so has Balzac. But
on the whole, it must be admitted that most of the great writers,
whether in prose or poetry, wrote well. M. Gide, it must be admitted,
writes admirably, though not wonderfully. Lady Rothermere does not
communicate the delicacies of his style in Prometheus Illbound, but
one could not read even this translation without feeling that the
author is a man of skill and wit in words. I doubt, however, whether
there is enough style in it to give it a place on a shelf with the
world’s important books. Lady Rothermere does not assert, indeed,
that Prometheus Illbound is itself a masterpiece. She claims for it
only that it is “the expression of the humorous side” of one of the
world’s greatest minds. The humour, it seems to me, is too elusive to
proceed from a great mind. Great minds, if they are humorous at all,
are humorous in such a way that the ordinary man can see at least a
part of the joke. M. Gide makes jokes for the favoured few. Many a
man who is amused by the jokes of Plato and of Gibbon will be
merely bewildered by the jokes of M. Gide. He enjoys the swift
change of episode as Sterne does, but, whereas Sterne always saves
the situation by giving us comic human beings passing across his
haphazard stage, M. Gide does not create human beings at all. Lady
Rothermere admits that “his world is a world of abstract ideas, under
the action of which most of his characters move as marionettes.”
She quotes: “Time and space are the boards which, with the help of
our minds, have been set up by the innumerable truths of the
universe as a stage for their own performances. And there we play
our parts like determined, convinced, devoted, and voluptuous
marionettes.” This dilettante and purely intellectual attitude to life is,
I believe, impossible to a great mind. It is very tedious to hear
sentimental people repeating the platitude that “great thoughts
come from the heart”; but the platitude happens to be true.
Shakespeare, it may be replied, in some of his moods saw the world
as a stage and an “insubstantial pageant.” On the other hand, he
never saw men and women as marionettes. He was always
interested in character, and M. Gide is not. M. Gide is interested in
problems. He is interested in ideas. He is not interested in men and
women. He is a philosopher at play. Even when he introduces a
tragic element into his work, as in Le Roi Candaule, we feel that the
whole thing is a game, an experiment. A great deal of modern
French literature makes one think of clever men amusing themselves
in a laboratory. The French are Epicureans of ideas. They test creeds
and philosophies and scepticisms with an exquisite freshness of
curiosity. They seek after truth itself as an amusement. In no other
nation can men talk so admirably of the universe while smoking
cigarettes. In England, if a man talks of God, he either lights a pipe
or stops smoking.
In Prometheus Illbound M. Gide has lit a cigarette, a rather
fragrant cigarette, at the sun. There is perhaps something a little
disproportionate in the action, something, too, a little audacious; but
he does it, if the phrase is not too stale, with a fine gesture, and as
he puffs at it, the glow of his cigarette seems to throw a tiny light on
the immense problems of human existence. He is cosmic in his
interests, if Parisian in his manners. He has Zeus and Prometheus
and the eagle among his chief characters. Zeus, like M. Gide himself,
is an experimentalist. He evidently rules the universe for the
sensations with which it provides him. At least, when we find him
walking along the most famous of the Parisian boulevards, he has
just made up his mind to perform a perfectly gratuitous act—an act
which not only will bring no return but will have no motive. In this
mood, he drops a handkerchief in the street, and, when a thin
gentleman named Cocles gives it back to him, he invites him to write
the address of anyone he pleases on an envelope so that he may
send a £20 note to him. The thin gentleman writes the name of
Damocles which he has seen by accident, and Zeus strikes him on
the face and disappears. He sends Damocles the £20 note, however.
Damocles becomes worried as to where the anonymous note has
come from and why. His good fortune, instead of satisfying him, only
raises problems in his mind. He does not know to whom he owes it
or what to do with it. The last we see of him, he is babbling
incoherent questions about it on his death-bed.
Some time before this, however, Prometheus has arrived, and
dined with Cocles and Damocles in a Paris restaurant. He finds
Cocles discoursing in perplexity on the meaningless blow he had
received from the unknown stranger, and he himself unwittingly
becomes the cause of a second and still more distressing accident to
Cocles. The conversation having turned on his eagle, Cocles and
Damocles express their desire to see it, and Prometheus calls it from
afar, whereupon “bursting through the window, it put out Cocles’ eye
with one stroke with its wing, and then, chirruping as it did so,
tenderly indeed but imperiously, fell with a swoop upon Prometheus’
right side. And Prometheus forthwith undid his waistcoat and offered
his liver to the bird.” For the moment, however, we may leave
Prometheus. The important event just now is the damage to Cocles’
eye. Neither the undeserved blow nor the accident to his eye
ultimately causes misery as the undeserved £20 causes Damocles
misery. When he sees Damocles’ misery on his death-bed, Cocles
comments: “There you see the fate of a man who has grown rich by
another’s suffering.” “But is it true that you suffer?” Prometheus asks
him. “From my eye occasionally,” said Cocles, “but from the blow no
more; I prefer to have received it. It does not burn any more; it has
revealed to me my goodness. I am flattered by it; I am pleased
about it. I never cease to think that my pain was useful to my
neighbour and that it brought him £20.” “But the neighbour is dying
of it,” said Prometheus.... It is clear that M. Gide has not taken it as
his province to justify the ways of God to man. I fancy he suspects
Zeus of having acted without a motive on many previous occasions
before the strange adventure of the boulevard. He is also clearly
amused by the workings of the human conscience. If Damocles had
not had a conscience, he would not have died.
Cocles and Damocles, however, are only minor characters in this
thin fantastic story. Prometheus is the real hero, though the
accidents do not happen to him. He has only his eagle and his habit
of lecturing about it. But it is his lectures about his eagle that give
the book its meaning. His eagle is really a figure in an allegory—an
allegory on a new plan. In the old-fashioned allegory one was more
conscious of what the allegorical figures meant, than of the figures
themselves. It was as if the author had tied labels round their necks.
M. Gide realizes that we have got beyond such ancient simplicities.
He consequently gives his figures no labels, but bids us “Guess!” and
we go on guessing till the end of the story. He has constructed a
puzzle, and, though we do not know whether it is worth solving or
not, he contrives to make us immensely curious about it and
immensely determined to solve it. Most people, when they have read
his story, will ask, “What does he mean? What is this eagle of
Prometheus?” Why does he first say that everyone has an eagle and
that one must nourish one’s eagle? And why does he in the end kill
his eagle and make a meal of it? And does M. Gide approve of the
last proceeding? I see that the majority of critics identify the eagle
with the human conscience. I think it is more than that. It is
everything that prevents man from resting satisfied with a pagan
philosophy of acceptance before the world’s beauty. It is that fury in
the human breast that makes men desire progress. It is the moral
consciousness of the race that leads men into profound self-denials
and profounder questionings. When Prometheus kills and eats his
eagle, he grows fat and cheerful. Does M. Gide then look back
regretfully on the moral history of mankind? On the contrary. The
eagle was found to be delicious, and at dessert they all drank his
health. “‘Has he, then, been useless?’ asked one. ‘Do not say that,
Cocles!—his flesh has nourished us. When I questioned him he
answered nothing; but I eat him without bearing him a grudge: if he
had made me suffer less, he would have been less fat; less fat he
would have been less delectable.’ ‘Of his past beauty, what is there
left?’ ‘I have kept all his feathers.’” “It is with one of them,” adds M.
Gide, “that I write this little book.” Yes, M. Gide is a moralist, though
a gay one, and Prometheus Illbound is a tract. He, too, desires
progress—even if it be progress somewhere beyond and away from
progress. His book is an amusing, though not a very amusing,
parable. It will appeal to those who prefer subtle little thoughts to
vehement great ones.
FINALE
THE CRITIC
People often forget that criticism, like poetry, is of many kinds. The
critics themselves are, perhaps, the worst transgressors in the
matter. They are divided into almost as many sects as the
theologians, and every sect but one regards its own standards as the
very rules of salvation. This would not matter so much if it did not
lead to the excommunication of all the critics who cannot subscribe
to the same creed. There is nothing more absurd in the history of
literature than the severities of the excommunicating sort of critic. A
critic has the right to condemn any work, critical or other, which is
bad of its kind. He has not the right to say that only his own kind of
criticism is good. There are as many ways of writing about books as
of writing about flowers. The poet reveals to us a different flower
from the flower of the botanist. Wordsworth’s “small celandine” is
not seen through the same eyes as the plant of which the botanist
tells us: “The lesser celandine is a species of Ranunculus (R.
Ficarus), a small low-growing herb with smooth heart-shaped leaves
and bright yellow flowers about an inch across, borne each on a
stout stalk springing from a leaf-axil.” There is yet another sort of
writer on flowers whose work is a charming compound of poetry,
science and any sort of relevant gossip, whether philological or
herbalist—who will inform us, for instance, that Ranunculus is a
diminutive of rana, “a frog,” which has the same damp, marshy
haunts as the flower, and that Nicholas Culpepper held that even to
carry the plant about one’s body next the skin helped to cure piles.
These are but three out of scores of ways of writing about flowers,
and it is mere sectarianism to deny the excellence of any of them.
It is, of course, open to the man of science to declare that
Wordsworth was not a botanist. It is possible, indeed, that
Wordsworth did not know that his “host of golden daffodils”
belonged to the natural order Amaryllidaceæ. This, however, would
be to quarrel about words. Wordsworth and the man of science alike
give an honest report of the flowers they have seen, and for my part
I find Wordsworth’s report the more interesting. It is much the same
with books as with flowers. The scientific critic shakes his head over
the imaginative treatment of books. His ideal critic would write about
books in the spirit of a Linnæus rather than of a Wordsworth. This, I
think, is to take a narrow view of criticism. Criticism is an art which
has developed in a score of different directions, and it is best to use
the word in a sense that includes them all. Criticism—good criticism,
at least—is almost any sort of good writing about books by a man or
woman of taste. Criticism, says the dictionary, is the art of judging.
As a matter of fact, criticism is something more than that. The good
critic does a great deal more than deliver judgments on books and
authors. He may at times play the part of the defending counsel
rather than that of the judge. There are occasions on which he
makes no attempt to hide the warmth of his feelings. He cannot
announce a masterpiece as though a summary of pros and cons
expressed what it meant to him. That is why I like to think of a critic
as a portrait-painter rather than a judge. The portrait-painter reveals
the character of his subject. He does not label or analyse it so much
as set before us a synthesis of all the most interesting things he has
seen, felt and thought in observing it. The judgment is always there,
but it may be implicit rather than explicit. The author sits to the critic
for his portrait. Even the book may be said—if we may put a slight
constraint on language—to sit to the critic for its portrait. In criticism
the character-sketch of the book or author is as important as any
technical analysis. Criticism is a magic mirror, in which a work of art
is reflected with a new emphasis and in new relations. The critic
must bathe his subject in the light of his own mind—his taste, his
enthusiasm, his moral ideas, his knowledge. Hence criticism is an
extremely personal thing. It relates, if one may adapt Anatole
France’s famous phrase, the adventures of masterpieces in the soul
of the critic, or—to put it a little more precisely—in the intellectual
and imaginative world of the critic.
It is said that, if we adopt this view, we are denying the
existence of any standards in criticism. This is not so. One may
believe in the conscience while admitting that moral standards
fluctuate. Similarly, one may believe in the literary conscience while
admitting that literary standards fluctuate. There is an eternal
difference between good and evil, but what seems good to one
generation may seem evil to another, and it is possible to recognise
the goodness of a man, such as an Old Testament polygamist or a
Scottish Sabbatarian, whose moral standards are in conflict with
ours. We can hold to our own moral standards while realising that
they are not the only conceivable moral standards. There is, no
doubt, a perfect moral standard somewhere, but only a perfect spirit
could perceive it. The rest of us can but do our best, and we cannot
even do that. Milton was right when he made “all-judging Jove” the
one supreme critic of literature. Meanwhile, the standards of
sublunar critics are but guesses. The critic who claims that they are
more is simply a dogmatist who climbs into a pulpit when he should
be going on a pilgrimage.
Brunetière accused Anatole France of having no standards, and
it is possible that Anatole France does not subscribe to any Thirty-
nine Articles of criticism. But if to have a conscience is to have
standards, and if taste is conscience in the æsthetic world, who can
deny that Anatole France has very fine literary standards indeed? It
is obvious that he all the time measures an author by the excellence
of all the authors he has loved, just as most of us get our standards
of character from the love and veneration we have felt for good
men. This love of excellence is indisputably the first of all the
requisites of a critic—love of excellence and acquaintance with
excellence. The critic’s first standard is his enthusiasm for the great
writers. “By ‘poetry,’ in these pages,” says Sir Arthur Quiller-Couch in
one of his books of criticism, “I mean what has been written by
Homer, Dante, Shakespeare and some others.” It is an admirable
definition. It puts us in touch with the writer’s standards at once. It
suggests, too, the reflection that all the good critics have been men
who agreed in the main with posterity in regard to literature. They
have accepted the tradition. Even the revolutionary critics, such as
Coleridge, have accepted the tradition for the most part, while
advancing on it. It is scarcely possible for a man so whimsical or
irreverent of the tradition as Samuel Butler to be a good critic. Nor is
the man who cannot enter into the tradition that puts Homer and
Dante and Shakespeare among the greatest of the poets capable of
criticising the free verse of our own day. There is clearly, however, a
danger in traditionalism. To criticise not in the spirit but in the letter
of the tradition is to become a formalist, a pedant, and it is probable
that the French injured their literature in the seventeenth century by
their too literal respect for the Greeks. The critic must have respect
for the life of his own times as well as for the writings of the dead.
He cannot safely yield to the belief that great literature is a temple
that has already been built. If he does not know that creation is still
going on, he is little more than a guide to the ruins of classical
architecture.
The critic must be governed by his sense of life, both in men and
in books. The sense of the past alone is not enough. Even as he
reads Æschylus or Shakespeare, it is his sense of life, not his sense
of the past, that is the more important. Hence the best critics have
been men in whom the sense of life, which is the imaginative artist’s
sense, has been strong. They have been, for the most part, men
who have also attempted with some success other forms of literature
—poets, novelists, essayists, such as Coleridge, Sainte-Beuve, Lamb,
Matthew Arnold and Anatole France. The old sneer that the critics
are men who have failed in literature might almost be reversed, so
far as the good critics are concerned. The good critics are men who
have succeeded in literature.
A good critic tells us as interesting things about his subject as
Gilbert White tells us about a bird. It is essentially the same kind of
illuminated observation that enables Gilbert White to write well
about a blackcap and Anatole France to write well about Pierre Loti.
“With an exquisitely delicate skin,” we are told of Loti, “he feels
nothing deeply. While all the pleasures and sorrows of the world leap
around him like dancing girls before a Rajah, his soul remains empty
and depressed, indolent and unoccupied. Nothing has entered it.
This is an excellent disposition for the writing of pages which perturb
the reader.” To deny the possession of critical standards to a writer
whose work is full of imaginative criticism such as this is to speak of
standards as though they were a sort of plumbline existing entirely
outside the imagination of the critic. It is to fail to see that, as
Anatole France says, “every book has as many different aspects as it
has readers and a poem like a landscape, is transformed in all the
eyes that see it, in all the souls that conceive it.” It is the object of
the critic to enable us to share this magical transformation with him,
not to issue immutable decrees. Anatole France, it may be,
exaggerates the personal element in criticism at the expense of the
traditional. He compares himself to a man who goes about “placing
rustic benches in the sacred woods and near the fountains of the
Muses.” “It demands neither system nor learning,” he declares, “and
only requires a pleasant astonishment before the beauty of things.
Let the village dominie, the land surveyor, measure the road and set
up the milestones!” This is extravagant and fanciful, but it shows us
at least the bright side of the moon of criticism. The other side of
the moon is useful, but it is not the side that gives us light.
THE END
A Selection from the
Catalogue of

G. P. PUTNAM’S SONS


Complete Catalogues sent
on application
The
Art of Reading
By
Sir Arthur Quiller-Couch

Editor, novelist, poet, and critic, Sir
Arthur Quiller-Couch is one of the most
versatile as well as distinguished living men
of letters. His are fresh viewpoints, opening
up ever new possibilities of appreciation for
the reader at the same time that they
educate his judgment.

G. P. Putnam’s Sons
New York London
On the Art of
Writing
By
Sir Arthur Quiller-Couch
In a fresh and untrammeled manner the
author deals with the craftsmanship as well
as the content of letters. The scope of the
volume is indicated by the appended chapter
titles: “The Practice of Writing,” “On the
Difference between Verse and Prose,”
“Interlude,” “On Jargon,” “On the Special
Difficulty of Prose,” “On the Lineage of
English Literature,” “English Literature in our
Universities.”

G. P. Putnam’s Sons
New York London
Studies in
Literature
Second Series
By
Sir Arthur Quiller-Couch
A new collection of essays which
demonstrates the author’s peculiar ability to
say something original about even the most
threadbare subject. J. C. Squire in The
Observer (London) says: “The man is rare
who, with Sir Arthur’s combination of sense
and sensibility, learning and levity, love of
the exquisite and sympathy with the normal,
can range over the whole field of ancient
and modern literature and vitalize whatever
he touches.” This volume includes essays on
Byron, Shelley, Milton, Chaucer,
Shakespeare, and “The Victorian Age.”

G. P. Putnam’s Sons
New York London
Books and Folks
By
Edward N. Teall
“Writing after having had unusual
experience with books and people, and in a
vein that is as creditable to the books as it
must be pleasing to the people, his treatise
is of great value.”
Evening Post, July 9, 1921.
“In a time when so many literary
counsellors are drawing attention to the
freakish, the rebellious writers, and to the
ones who would pioneer new styles and
methods it is refreshing to have at hand a
book that speaks lovingly for the art of
letters, the whole art, and for the individual
and unbiased appreciation.
“... The book is a most acceptable library
companion. There’s no pretense and no
posing in all of its pages.”—Oakland Tribune,
July 10, 1921.

G. P. Putnam’s Sons
New York London
Transcriber’s Notes
Punctuation, hyphenation, and spelling were made
consistent when a predominant preference was found in the
original book; otherwise they were not changed.
Simple typographical errors were corrected; unbalanced
quotation marks were remedied when the change was
obvious, and otherwise left unbalanced.
Page 139: “way-born” should be “way-worn”.
*** END OF THE PROJECT GUTENBERG EBOOK BOOKS AND
AUTHORS ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™

You might also like