0% found this document useful (0 votes)
5 views

Mastering PHP design patterns develop robust and reusable code using a multitude of design patterns for PHP 7 Ali - Quickly download the ebook to never miss any content

The document promotes a collection of ebooks focused on design patterns and best practices for various programming languages, including PHP and JavaScript. It highlights specific titles such as 'Mastering PHP Design Patterns' and 'Mastering JavaScript Design Patterns,' providing links for instant downloads. The content emphasizes the importance of robust, reusable code and offers insights into software engineering skills and project management techniques.

Uploaded by

ghoorimankeu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Mastering PHP design patterns develop robust and reusable code using a multitude of design patterns for PHP 7 Ali - Quickly download the ebook to never miss any content

The document promotes a collection of ebooks focused on design patterns and best practices for various programming languages, including PHP and JavaScript. It highlights specific titles such as 'Mastering PHP Design Patterns' and 'Mastering JavaScript Design Patterns,' providing links for instant downloads. The content emphasizes the importance of robust, reusable code and offers insights into software engineering skills and project management techniques.

Uploaded by

ghoorimankeu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Explore the full ebook collection and download it now at textbookfull.

com

Mastering PHP design patterns develop robust and


reusable code using a multitude of design patterns
for PHP 7 Ali

https://textbookfull.com/product/mastering-php-design-
patterns-develop-robust-and-reusable-code-using-a-multitude-
of-design-patterns-for-php-7-ali/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

PHP 8 Objects, Patterns, and Practice: Mastering OO


Enhancements, Design Patterns, and Essential Development
Tools Zandstra
https://textbookfull.com/product/php-8-objects-patterns-and-practice-
mastering-oo-enhancements-design-patterns-and-essential-development-
tools-zandstra/
textbookfull.com

Design Patterns in PHP and Laravel 1st Edition Kelt


Dockins

https://textbookfull.com/product/design-patterns-in-php-and-
laravel-1st-edition-kelt-dockins/

textbookfull.com

MASTERING JAVASCRIPT DESIGN PATTERNS create scalable and


reliable applications with advanced Javascript design
patterns using reliable code 3rd Edition Tomas Corral
Cosas
https://textbookfull.com/product/mastering-javascript-design-patterns-
create-scalable-and-reliable-applications-with-advanced-javascript-
design-patterns-using-reliable-code-3rd-edition-tomas-corral-cosas/
textbookfull.com

Design Patterns in Modern C++: Reusable Approaches for


Object-Oriented Software Design 1st Edition Dmitri
Nesteruk
https://textbookfull.com/product/design-patterns-in-modern-c-reusable-
approaches-for-object-oriented-software-design-1st-edition-dmitri-
nesteruk/
textbookfull.com
Puppet Best Practices Design Patterns for Maintainable
Code 1st Edition Chris Barbour

https://textbookfull.com/product/puppet-best-practices-design-
patterns-for-maintainable-code-1st-edition-chris-barbour/

textbookfull.com

Design Patterns in .NET Core 3: Reusable Approaches in C#


and F# for Object-Oriented Software Design 2nd Edition
Dmitri Nesteruk
https://textbookfull.com/product/design-patterns-in-net-
core-3-reusable-approaches-in-c-and-f-for-object-oriented-software-
design-2nd-edition-dmitri-nesteruk/
textbookfull.com

Java Design Patterns A tour of 23 gang of four design


patterns in Java 1st Edition Vaskaran Sarcar

https://textbookfull.com/product/java-design-patterns-a-tour-
of-23-gang-of-four-design-patterns-in-java-1st-edition-vaskaran-
sarcar/
textbookfull.com

Java design patterns a tour of 23 gang of four design


patterns in Java 1st Edition Vaskaran Sarcar

https://textbookfull.com/product/java-design-patterns-a-tour-
of-23-gang-of-four-design-patterns-in-java-1st-edition-vaskaran-
sarcar-2/
textbookfull.com

Design Patterns by Tutorials Learning design patterns in


Swift 4 2 Joshua Greene

https://textbookfull.com/product/design-patterns-by-tutorials-
learning-design-patterns-in-swift-4-2-joshua-greene/

textbookfull.com
Mastering PHP Design Patterns

Develop robust and reusable code using a multitude of


design patterns for PHP 7

Junade Ali

BIRMINGHAM - MUMBAI
Mastering PHP Design Patterns
Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be caused
directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: September 2016

Production reference: 1230916

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78588-713-0
www.packtpub.com
Credits

Author Copy Editor

Junade Ali Safis Editing

Reviewer Project Coordinator

Sworup Shakya Suzanne Coutinho

Commissioning Editor Proofreader

Kunal Parikh Safis Editing

Acquisition Editor Indexer

Chaitanya Nair Tejal Daruwale Soni

Content Development Editor Production Coordinator

Nikhil Borkar Aparna Bhagat

Technical Editor Cover Work

Hussain Kanchwala Aparna Bhagat


About the Author
Junade Ali was a technical lead at some of the UK's leading digital agencies and has also
worked using PHP in mission-critical road-safety systems. He loves pushing PHP to its
innovative limits. Having started his career as a web development apprentice, he still
remains engaged in the academic computer science community.

Junade, an avid contributor to the PHP community, has also spoken at PHPTek and the
Lead Developer Conference. In addition to this, Junade was interviewed by Cal Evans for
Voices of the ElePHPant, and he has appeared on the PHP Roundtable. In this spirit, Junade
is proud of his local PHP user group: PHPWarks. Currently, Junade works at CloudFlare as
a polymath, and helps make the Internet more secure and faster.

Outside of development, Junade has an interest in law and political campaigns and is a
published author on constitutional law.
About the Reviewer
Sworup Shakya has worked as a web developer for more than ten years. He started his
career as a Flash ActionScript developer, before moving on to ASP.NET MVC, and finally to
PHP. During his time as a developer, Sworup worked extensively with frameworks, be it
ASP.NET MVC or AngularJS or Laravel. However, while he was working as an
ActionScript developer, he had to create one, which gave him knowledge of design patterns
and OOP concepts that has helped him improve in order to be able to work on the
frameworks he had to work on later.

Sworup received his Bachelor of Information Technology degree from Purbanchal


University in Nepal. He currently works with Zimris Technologies Nepal Pvt. Ltd., a
subsidiary of Zimris, LLC, as a senior developer.

Sworup likes to keep on top of the current technologies, keeping an eye on StackOverflow,
Laracasts forums, and occasional podcasts. He posts on these mediums whenever he can
and is looking to start a technical blog documenting his experiences at http://sworup.com.
np/. You can reach him at sworup.shakya@gmail.com.

I would like to thank Suzanne Coutinho, Francina Pinto and Chaitanya Nair of Packt Publishing for
giving me this opportunity and helping me through the review process. I would like to thank my
friends, family and colleagues for their unconditional support.
www.PacktPub.com
For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at service@packtpub.com for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and
eBooks.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt
books and video courses, as well as industry-leading tools to help you plan your personal
development and advance your career.

Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Table of Contents
Chapter 1: Why "Good PHP Developer" Isnt an Oxymoron 8
Coding style – the PSR standards 11
Revising object-oriented programming 11
Polymorphism 11
Traits (multiple inheritance) 16
Scalar type hints 19
Limiting debug access to private/protected properties 21
Setting up the environment with Composer 23
The Gang of Four (GoF) 26
Creational design patterns 27
Dependency injection 27
Structural design patterns 28
Behavioral design patterns 28
Architectural patterns 28
Summary 29
Chapter 2: Anti-Patterns 30
Why anti-patterns matter 31
Not invented here syndrome 34
Third-party dependencies with Composer 36
God objects 40
Environment variables in PHP source 43
Singletons (and why you should be using dependency injection) 44
Dependency injection 45
Database as IPC 45
Auto-increment database IDs 46
Cronjob imitating service 47
Software in place of architecture 47
Interface Bloat 49
Cart before the horse 51
Separation of development and operations 52
Excessive separation of development responsibilities 52
Error suppression operator 53
Blind faith 54
Sequential coupling 55
The big rewrite 58
Automated tests 59
Service splitting 60
Perfectly staged migrations 61
Tester-Driven Development 62
Bloated optimization 62
Analysis paralysis 63
Bikeshedding 63
Premature optimization 63
Uneducated manager syndrome 64
Wrong rocky foundations 64
Long methods 65
Magic numbers 70
Summary 70
Chapter 3: Creational Design Patterns 72
Software design process 72
Simple Factory 74
Factory Method 78
Abstract Factory pattern 82
Lazy initialization 90
Builder pattern 93
Prototype pattern 97
Summary 102
Chapter 4: Structural Design Patterns 103
Agile software architecture 104
Decorator 105
Adapter 108
Class Adapter 108
Object Adapter 110
FlyWeight 113
Composite 117
Bridge 120
Proxy pattern 123
Facade 127
Summary 130
Chapter 5: Behavioral Design Patterns 132
Personality traits for passionate programmers 133
Observer pattern (SplObserver/SplSubject) 135

[ ii ]
Iterators 139
IteratorAggregate 139
Iterator 141
The many iterators of PHP 142
Generators 143
Template Method design pattern 148
Chain of Responsibility 152
Strategy design pattern 159
Specification design pattern 163
Scheduled Task pattern 167
Summary 168
Chapter 6: Architectural Patterns 170
Model-View-Controller (MVC) 170
Service-oriented architecture 172
Microservices 173
Asynchronous queueing 177
Message Queue pattern (Getting started with RabbitMQ) 177
Publish-Subscriber pattern 187
Summary 191
Chapter 7: Refactoring 192
What is refactoring? 192
Test, test, and test again 193
Code smells 194
Long methods and duplicated code 195
Large class 197
Replacing complex logical statements and switch statements with
polymorphism or the Strategy Pattern 198
Duplicating code following a single control structure 200
Long Parameter List and primitive obsession 200
Indecent exposure 203
Feature envy 204
Inappropriate intimacy 206
Deeply nested statements 206
Remove assignments to parameters 207
Comments 208
Encapsulating Composite with Builder 208
Replacing hard-coded notifications with Observer 209
Replacing one/many distinctions with Composite 209

[ iii ]
Separate versions with Adapters 210
What do I tell my manager? 210
Summary 211
Chapter 8: How to Write Better Code 212
Nature of a HTTP request 212
RESTful API design 231
Stateless nature 231
Versioning 231
Filtering 232
Sorting 232
Searching 232
Limiting fields 233
Returning new fields 233
When in doubt – KISS 233
Software development life cycle 234
On Scrum, and real Agility 235
You need to sack people sometimes 237
Lean project management 239
YAGNI and defering decisions 239
Monitoring 240
Tests fight legacy 241
Behavior-Driven Development 243
Summary 250
Index 252

[ iv ]
Preface
Have you ever been to a PHP conference? If not, I’d highly recommend it, it is the closest
you can get to a living and breathing PHP community. A few weeks ago, I flew from
London to St. Louis, Misouri, to speak at php[tek] (the PHP conference run by
php[architect]). After the conference, there was a small tradition within the PHP community
known as WurstCon. Essentially, hundreds of PHP conference attendees cram themselves
into a small hot dog shop and host a hot dog convention, often to the complete surprise of
the staff there. Likewise, community nights at PHP events are the warmest and most
accepting community occasions you’ll ever run into; the PHP community is surely one that
other development language communities envy.

As of PHP 7, the PHP project has changed dramatically; but what I love, remains strong.
The warmth you will feel at any PHP conference, the openness in the documentation, and
adoption in the language. Yes, there are practices that are undoubtedly bad within PHP
itself; however, think of what the PHP community has recently achieved, ranging from
PHPUnit to Composer. Throughout this book, bear in mind the improvements in PHP 7, a
few of which I’ll share with you. The trajectory of the project is now certainly upwards, and
let’s not forget that this wasn’t always true. The PHP community has learned its lessons
from the past, whilst the language maintains the flexibility to write what is bad.

This book will seek to impart strong software engineering skills to you with the focus on
implementing them in PHP. At the time of publishing this book, there is a certain void and
a necessity for this kind of material. This book seeks to be the lighthouse that will not only
demonstrate software design theory, but also seek to impart practical information of real
value to improve the quality and maintainability of the code you write. This book leaves no
stone unturned throughout the software development cycle and will seek to confront the
reasons as to why the majority of software projects fail whilst also addressing design,
redesign, and safeguard effective code.

This book goes beyond traditional design patterns as envisaged by the Gang of Four and
details the practices that passionate PHP developers need to be successful as software
engineers or leads on detailed PHP projects. This book will introduce you to the core
knowledge required to understand project management techniques, why the majority
software development projects fail, and why you can make yours a success.
Preface

Originally, I gave thought to writing a book on PHP when Mandi Rose, who I worked with
previously, suggested I put together a book on the practices I’ve learned with PHP.
Needless to say, at the time that suggestion was made, the best of my career was
undoubtedly ahead of me; when the opportunity actually arose to write something like this,
I felt I had learned dramatically more as time progressed. By no means should you see this
book as the be-all and end-all of PHP practices; instead, you should use it to increase your
knowledge base on PHP, but by no means limit it to this. In this book, I aim to give
something, however small, back to the PHP community; after reading this book, I would
encourage you to get stuck in and share what you’ve learned with others.

Later in this book, I will advocate Extreme Programming as a methodology and courage as
a key value of this methodology. I will ask you to bear in mind the explanation of courage
in The Values of Extreme Programming: “We will tell the truth about progress and
estimates. We don't document excuses for failure because we plan to succeed. We don't fear
anything because no one ever works alone. We will adapt to changes whenever they
happen.” This is, of course, some key advice we should all follow and seek to genuinely
understand risks instead of cowering behind them. For many of us, the code we write
during parts of our career is the highest expression of our labor. Indeed, the late nights
turning into early mornings we spend debugging and developing are what ultimately allow
us to demonstrate the fruits of our labor. In essence, as software engineers, the code we
write defines who we are, as such we should be open to constantly refining and refactoring
our processes, which is what this book aims to support you in doing. I am incredibly
honored that you chose to allow me to help you to reach this end.

What this book covers


Chapter 1, Why "Good PHP Developer" Isn't an Oxymoron, introduces the concept of design
patterns as recurring solutions to commonly arising problems.

Chapter 2, Anti-Patterns, introduces how patterns can lead to decidedly negative


consequences.

Chapter 3, Creational Design Patterns, discusses Gang of Four design patterns, namely those
surrounding object creation.

Chapter 4, Structural Design Patterns, covers how multiple classes and objects can be
combined to deliver a clearer interface.

[2]
Preface

Chapter 5, Behavioral Design Patterns, explains how to increase the flexibility of


communication between objects by identifying patterns that can help with communication
between them.

Chapter 6, Architectural Patterns, revolves around resolving common issues related to the
architecture of a web application/system, potentially outside the code base itself.

Chapter 7, Refactoring, shows how to redesign code that has already been written to
improve maintainability.

Chapter 8, How to Write Better Code, covers a range of concepts that haven’t been discussed
elsewhere, and it also concludes with some advice for developers.

What you need for this book


An installation of PHP 7 will serve you well throughout this book. You should be prepared
to alter your development environment as needed throughout this book; we will address
the installation of various tools as we encounter them.

This book is not for the despairingly hostile or those who are passively antagonistic to
approaching new software engineering principles. It is not for those who seek to be lone
warriors, either. When altering a given code base, you must seek to improve the code of the
entire code base and everyone who works on it. You must be willing to take personal
responsibility of the code you write and not blame external factors. Code maintainability
cannot be improved unilaterally on shared code bases; you must write your code with the
intention of maintaining code quality for those who maintain it after you. Additionally, seek
to go into this book with the mindset of being able to share what you’ve learned, whether it
is with those in your teams, your user groups, or the larger PHP community. In other
words, approach this book with the end in mind; approach this book with the stated aim of
improving your code and those in the code base you maintain.

Who this book is for


This book is certainly aimed at the PHP developer looking to learn about the complete set of
skills needed to be a software engineer, in particular, some lessons from software design;
this book will seek to educate you on how your code can be made more extensible and
easier to develop on. This book seeks to take your code beyond just being a bag of functions
and classes, instead preferring well-designed, well-written, and well-tested code.

[3]
Preface

You will need a working knowledge of PHP and enough to build an application, but by no
means do you have to be a total expert at everything in PHP; a working knowledge of the
basics of software engineering will certainly give you a heads up.

You must encounter this book with an open mind and a willingness to have your
preconceptions about software development challenged. This book will confront some
truths about how you may be failing personally as a developer; it is vital that you approach
this book with a willingness to take these principles onboard.

This book presents a set of software development patterns and principles that you can
adopt. It is vital that you understand where these patterns should and shouldn’t be applied;
this will be explained throughout the book, especially in the last chapter.

A key tenet of reading this book is understanding what PHP is for and what it isn’t. I expect
you to enter this book understanding what problems you expect PHP to solve and what
you expect to use other software development languages to solve.

Conventions
In this book, you will find a number of text styles that distinguish between different kinds
of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The
index.php file now yields this result".

A block of code is set as follows:


<?php

abstract class Notifier


{
protected $to;

public function __construct(string $to)


{
$this->to = $to;
}

abstract public function validateTo(): bool;

abstract public function sendNotification(): string;

[4]
Preface

Any command-line input or output is written as follows:


echo $richard->hasPaws;

New terms and important words are shown in bold. Words that you see on the screen, for
example, in menus or dialog boxes, appear in the text like this: "direct your web browser to
your chosen web server and you should see Hello world! pop up on screen."

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or disliked. Reader feedback is important for us as it helps us
develop titles that you will really get the most out of.

To send us general feedback, simply e-mail feedback@packtpub.com, and mention the


book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you
to get the most from your purchase.

Downloading the example code


You can download the example code files for this book from your account at http://www.p
acktpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.c
om/support and register to have the files e-mailed directly to you.

[5]
Preface

You can download the code files by following these steps:

1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box.
5. Select the book for which you're looking to download the code files.
6. Choose from the drop-down menu where you purchased this book from.
7. Click on Code Download.

You can also download the code files by clicking on the Code Files button on the book's
webpage at the Packt Publishing website. This page can be accessed by entering the book's
name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:

WinRAR / 7-Zip for Windows


Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPubl
ishing/Mastering-PHP-Design-Patterns/. We also have other code bundles from our
rich catalog of books and videos available at https://github.com/PacktPublishing/.
Check them out!

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you find a mistake in one of our books—maybe a mistake in the text or the
code—we would be grateful if you could report this to us. By doing so, you can save other
readers from frustration and help us improve subsequent versions of this book. If you find
any errata, please report them by visiting http://www.packtpub.com/submit-errata,
selecting your book, clicking on the Errata Submission Form link, and entering the details
of your errata. Once your errata are verified, your submission will be accepted and the
errata will be uploaded to our website or added to any list of existing errata under the
Errata section of that title.

[6]
Preface

To view the previously submitted errata, go to https://www.packtpub.com/books/conten


t/support and enter the name of the book in the search field. The required information will
appear under the Errata section.

Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At
Packt, we take the protection of our copyright and licenses very seriously. If you come
across any illegal copies of our works in any form on the Internet, please provide us with
the location address or website name immediately so that we can pursue a remedy.

Please contact us at copyright@packtpub.com with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable
content.

Questions
If you have a problem with any aspect of this book, you can contact us
at questions@packtpub.com, and we will do our best to address the problem.

[7]
Why "Good PHP Developer"
1
Isnt an Oxymoron
Back in 2010, MailChimp published a post on their blog, entitled Ewww, You Use PHP? In
this blog post, they described the horror when they explained their choice of PHP to
developers who consider the phrase good PHP programmer an oxymoron. In their rebuttal
they argued that their PHP wasn't your grandfathers PHP and that they use a sophisticated
framework. I tend to judge the quality of PHP on the basis of, not only how it functions, but
how secure it is and how it is architected. This book focuses on ideas of how you should
architect your code. The design of software allows for developers to ease the extension of
the code beyond its original purpose, in a bug-free and elegant fashion.

As Martin Fowler put it:

“Any fool can write code that a computer can understand. Good programmers write code
that humans can understand.”

This isn't just limited to code style, but how developers architect and structure their code.
I've encountered many developers with their noses constantly stuck in the documentation,
copying and pasting bits of code until it works; hacking snippets together until it works.
Moreover, I far too often see the software development process rapidly deteriorate as
developers ever more tightly couple their classes with functions of ever increasing length.

Software engineers mustn't just code software; they must know how to design it. Indeed
often a good software engineer, when interviewing other software engineers will ask
questions about the design of the code itself. It is trivial to get a piece of code that will
execute, and it is also benign to question a developer as to whether strtolower or
str2lower is the correct name of a function (for the record, it's strtolower). Knowing the
difference between a class and an object doesn't make you a competent developer; a better
interview question would, for example, be how one could apply subtype polymorphism to
Why "Good PHP Developer" Isnt an Oxymoron

a real software development challenge. Failure to assess software design skills dumbs down
an interview and results in there being no way to differentiate between those who are good
at it, and those who aren't. These advanced topics will be discussed throughout this book,
by learning these tactics, you will better understand what the right questions to ask are
when discussing software architecture.

Moxie Marlinspike once tweeted the following:

“As a software developer, I envy writers, musicians, and filmmakers. Unlike software,
when they create something it is really done, forever”.

When developing software, we mustn't forget we are authors, not just of instructions for a
machine, but we are also authoring something that we later expect others to extend upon.
Therefore, our code mustn't just be targeted at machines, but humans also. Code isn't just
poetry for a machine, it should be poetry for humans also.

This is, of course, better said than done. In PHP, this may be found especially difficult given
the freedom PHP offers developers on how they may architect and structure their code. By
the very nature of freedom, it may be both used and abused, so it is true with the freedom
offered in PHP.

Therefore, it is increasingly important that developers understand proper software design


practices to ensure their code maintains the long term maintainability. Indeed, another key
skill lies in refactoring code, improving the design of existing code to make it easier to extend
in the long term.

Technical debt, the eventual consequence of poor system design, is something that I've
found comes with the career of a PHP developer. This has been true for me whether it has
been dealing with systems that provide advanced functionality or simple websites. It
usually arises because a developer elects to implement a bad design for a variety of reasons;
this is when adding functionality to an existing codebase or taking poor design decisions
during the initial construction of software. Refactoring can help us address these issues.

SensioLabs (the creators of the Symfony framework) have a tool called Insight that allows
developers to calculate the technical debt in their own code. In 2011, they did an evaluation
of technical debt in various projects using this tool; rather unsurprisingly they found that
WordPress 4.1 topped the chart of all platforms they evaluated with them claiming it would
take 20.1 years to resolve the technical debt that the project contains.

[9]
Why "Good PHP Developer" Isnt an Oxymoron

Those familiar with the WordPress core may not be surprised by this, but this issue of
course is not only associated to WordPress. In my career of working with PHP, from
working with security critical cryptography systems to working with systems that work
with mission critical embedded systems, dealing with technical debt comes with the job.
Dealing with technical debt is not something to be ashamed of for a PHP developer, indeed
some may consider it courageous. Dealing with technical debt is no easy task, especially in
the face of an ever more demanding user base, client, or project manager; constantly
demanding more functionality without being familiar with the technical debt the project
has associated to it.

I recently e-mailed the PHP Internals group as to whether they should consider deprecating
the error suppression operator @. When any PHP function is prepended by an @ symbol, the
function will suppress an error returned by it. This can be brutal, especially where that
function renders a fatal error that stops the execution of the script, making debugging a
tough task. If the error is suppressed, the script may fail to execute without providing
developers a reason as to why this is. Usage of this operator may be described as an anti-
pattern in some situations, something we will cover in Chapter 4, Structural Design Patterns.

Despite the fact that no one objected to the fact that there were better ways of handling
errors (try/catch, proper validation) than abusing the error suppression operator and
that deprecation should be an eventual aim of PHP, it is the case that some functions return
needless warnings even though they already have a success/failure value. This means that
due to technical debt in the PHP core itself, this operator cannot be deprecated until a lot of
other prerequisite work is done. In the meantime, it is down to developers to decide the best
methodologies of handling errors. Until the inherent problem of unnecessary error
reporting is addressed, this operator cannot be deprecated. Therefore, it is down to
developers to be educated as to the proper methodologies that should be used to address
error handling and not to constantly resort to using an @ symbol.

Fundamentally, technical debt slows down development of a project and often leads to code
being deployed that is broken as developers try and work on a fragile project.

When starting a new project, never be afraid to discuss architecture as architecture meetings
are vital to developer collaboration; as one Scrum Master I've worked with said in the face
of criticism that “meetings are a great alternative to work”, he said “meetings are
work…how much work would you be doing without meetings?”.

In the rest of this chapter, we will cover the following points:

Coding style – the PSR standards


Revising object-oriented programming
Setting up the environment with Composer

[ 10 ]
Why "Good PHP Developer" Isnt an Oxymoron

Who are the Gang of Four?

Coding style – the PSR standards


When it comes to coding style, I would like to introduce you to the PSR standards created
by the PHP Framework Interop Group. Namely, the two standards that apply to coding
standards are PSR-1 (Basic Coding Style) and PSR-2 (Coding Style Guide). In addition to
this, there are PSR standards that cover additional areas, for example, as of today; the PSR-4
standard is the most up-to-date autoloading standard published by the group. You can find
out more about the standards at http://www.php-fig.org/.

Coding style being used to enforce consistency throughout a code base is something I
strongly believe in. It does make a difference to your code readability throughout a project.
It is especially important when you are starting a project (chances are you may be reading
this book to find out how to do that right) as your coding style determines the style the
developers following you in working on this project will adopt. Using a global standard
such as PSR-1 or PSR-2 means that developers can easily switch between projects without
having to reconfigure their code style in their IDE. Good code style can make formatting
errors easier to spot. Needless to say that coding styles will develop as time progresses, to
date I elect to work with the PSR standards.

I am a strong believer in the phrase: always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live. It isn't known who wrote this phrase
originally, but it's widely thought that it could have been John Woods or potentially Martin
Golding.

I would strongly recommend familiarizing yourself with these standards before proceeding
in this book.

Revising object-oriented programming


Object-oriented programming is more than just classes and objects; it's a whole
programming paradigm based around objects (data structures) that contain data fields and
methods. It is essential to understand this; using classes to organize a bunch of unrelated
methods together is not object orientation.

Assuming you're aware of classes (and how to instantiate them), allow me to remind you of
a few different bits and pieces.

[ 11 ]
Why "Good PHP Developer" Isnt an Oxymoron

Polymorphism
Polymorphism is a fairly long word for a fairly simple concept. Essentially, polymorphism
means the same interface is used with a different underlying code. So multiple classes could
have a draw function, each accepting the same arguments, but at an underlying level, the
code is implemented differently.

In this section, I would like to talk about Subtype Polymorphism in particular (also known
as Subtyping or Inclusion Polymorphism).

Let's say we have animals as our supertype; our subtypes may well be cats, dogs, and
sheep.

In PHP, interfaces allow you to define a set of functionality that a class that implements it
must contain, as of PHP 7 you can also use scalar type hints to define the return types we
expect.

So for example, suppose we defined the following interface:


interface Animal
{
public function eat(string $food) : bool;

public function talk(bool $shout) : string;


}

We could then implement this interface in our own class, as follows:


class Cat implements Animal {
}

If we were to run this code without defining the classes we would get an error message as
follows:
Class Cat contains 2 abstract methods and must therefore be declared
abstract or implement the remaining methods (Animal::eat, Animal::talk)

Essentially, we are required to implement the methods we defined in our interface, so now
let's go ahead and create a class that implements these methods:
class Cat implements Animal
{
public function eat(string $food): bool
{
if ($food === "tuna") {
return true;
} else {

[ 12 ]
Why "Good PHP Developer" Isnt an Oxymoron

return false;
}
}

public function talk(bool $shout): string


{
if ($shout === true) {
return "MEOW!";
} else {
return "Meow.";
}
}
}

Now that we've implemented these methods, we can then just instantiate the class we are
after and use the functions contained in it:
$felix = new Cat();
echo $felix->talk(false);

So where does polymorphism come into this? Suppose we had another class for a dog:
class Dog implements Animal
{
public function eat(string $food): bool
{
if (($food === "dog food") || ($food === "meat")) {
return true;
} else {
return false;
}
}

public function talk(bool $shout): string


{
if ($shout === true) {
return "WOOF!";
} else {
return "Woof woof.";
}
}
}

Now let's suppose we have multiple different types of animals in a pets array:
$pets = array(
'felix' => new Cat(),
'oscar' => new Dog(),

[ 13 ]
Why "Good PHP Developer" Isnt an Oxymoron

'snowflake' => new Cat()


);

We can now actually go ahead and loop through all these pets individually in order to run
the talk function. We don't care about the type of pet because the talk method that is
implemented in every class we get is by virtue of us having extended the Animals interface.

So let's suppose we wanted to have all our animals run the talk method. We could just use
the following code:
foreach ($pets as $pet) {
echo $pet->talk(false);
}

No need for unnecessary switch/case blocks in order to wrap around our classes, we just
use software design to make things easier for us in the long-term.

Abstract classes work in a similar way, except for the fact that abstract classes can contain
functionality where interfaces cannot.

It is important to note that any class that defines one or more abstract classes must also be
defined as abstract. You cannot have a normal class defining abstract methods, but you can
have normal methods in abstract classes. Let's start off by refactoring our interface to be an
abstract class:
abstract class Animal
{
abstract public function eat(string $food) : bool;

abstract public function talk(bool $shout) : string;

public function walk(int $speed): bool {


if ($speed > 0) {
return true;
} else {
return false;
}
}
}

You might have noticed that I have also added a walk method as an ordinary, non-abstract
method; this is a standard method that can be used or extended by any classes that inherit
the parent abstract class. They already have their implementation.

Note that it is impossible to instantiate an abstract class (much like it's not possible to
instantiate an interface). Instead, we must extend it.

[ 14 ]
Why "Good PHP Developer" Isnt an Oxymoron

So, in our Cat class let's remove the following:


class Cat implements Animal

We will replace it with the following code:


class Cat extends Animal

That's all we need to refactor in order to get classes to extend the Animal abstract class. We
must implement the abstract functions in the classes as we outlined for the interfaces, plus
we can use the ordinary functions without needing to implement them:
$whiskers = new Cat();
$whiskers->walk(1);

As of PHP 5.4 it has also become possible to instantiate a class and access a property of it in
one system. PHP.net advertised it as: Class member access on instantiation has been added, e.g.
(new Foo)->bar(). You can also do it with individual properties, for example, (new
Cat)->legs. In our example, we can use it as follows:

(new \IcyApril\ChapterOne\Cat())->walk(1);

Just to recap a few other points about how PHP implemented OOP, the final keyword
before a class declaration or indeed a function declaration means that you cannot override
such classes or functions after they've been defined.

So, let's try extending a class we have named as final:


final class Animal
{
public function walk()
{
return "walking...";
}
}

class Cat extends Animal


{
}

This results in the following output:


Fatal error: Class Cat may not inherit from final class (Animal)

Similarly, let's do the same except at a function level:


class Animal
{

[ 15 ]
Why "Good PHP Developer" Isnt an Oxymoron

final public function walk()


{
return "walking...";
}
}

class Cat extends Animal


{
public function walk () {
return "walking with tail wagging...";
}
}

This results in the following output:


Fatal error: Cannot override final method Animal::walk()

Traits (multiple inheritance)


Traits were introduced in PHP as a mechanism for introducing Horizontal Reuse. PHP
conventionally acts as a single inheritance language, because of the fact that you can't
inherit more than one class into a script.

Traditional multiple inheritance is a controversial process that is often looked down upon
by software engineers.

Let me give you an example of using Traits first hand; let's define an abstract Animal class
that we want to extend into another class:
class Animal
{
public function walk()
{
return "walking...";
}
}

class Cat extends Animal


{
public function walk () {
return "walking with tail wagging...";
}
}

[ 16 ]
Why "Good PHP Developer" Isnt an Oxymoron

So now let's suppose we have a function to name our class, but we don't want it to apply to
all our classes that extend the Animal class, we want it to apply to certain classes
irrespective of whether they inherit the properties of the abstract Animal class or not.

So we've defined our functions like so:


function setFirstName(string $name): bool
{
$this->firstName = $name;
return true;
}

function setLastName(string $name): bool


{
$this->lastName = $name;
return true;
}

The problem now is that there is no place we can put them without using Horizontal Reuse,
apart from copying and pasting different bits of code or resorting to using conditional
inheritance. This is where Traits come to the rescue; let's start off by wrapping these
methods in a Trait called Name:
trait Name
{
function setFirstName(string $name): bool
{
$this->firstName = $name;
return true;
}

function setLastName(string $name): bool


{
$this->lastName = $name;
return true;
}
}

So now that we've defined our Trait, we can just tell PHP to use it in our Cat class:
class Cat extends Animal
{
use Name;

public function walk()


{
return "walking with tail wagging...";

[ 17 ]
Why "Good PHP Developer" Isnt an Oxymoron

}
}

Notice the use of the Name statement? That's where the magic happens. Now you can call
the functions in that Trait without any problems:
$whiskers = new Cat();
$whiskers->setFirstName('Paul');
echo $whiskers->firstName;

All put together, the new code block looks as follows:


trait Name
{
function setFirstName(string $name): bool
{
$this->firstName = $name;
return true;
}

function setLastName(string $name): bool


{
$this->lastName = $name;
return true;
}
}

class Animal
{
public function walk()
{
return "walking...";
}
}

class Cat extends Animal


{
use Name;

public function walk()


{
return "walking with tail wagging...";
}
}

$whiskers = new Cat();


$whiskers->setFirstName('Paul');
echo $whiskers->firstName;

[ 18 ]
Another Random Document on
Scribd Without Any Related Topics
The news told, Nicolas looks stem and we begin to talk business.
If an outsider were then to hear how freely Nicolas uses the jargon,
he would be inclined to think that he was a scholar, posing as a
soldier. By the way, the rumours of the university-porter's erudition
are very exaggerated. It is true that Nicolas knows more than a
hundred Latin tags, can put a skeleton together and on occasion
make a preparation, can make the students laugh with a long
learned quotation, but the simple theory of the circulation of the
blood is as dark to him now as it was twenty years ago.
At the table in my room, bent low over a book or a preparation,
sits my dissector, Peter Ignatievich. He is a hardworking, modest
man of thirty-five without any gifts, already bald and with a big belly.
He works from morning to night, reads tremendously and
remembers everything he has read. In this respect he is not merely
an excellent man, but a man of gold; but in all others he is a cart-
horse, or if you like a learned blockhead. The characteristic traits of
a cart-horse which distinguish him from a creature of talent are
these. His outlook is narrow, absolutely bounded by his specialism.
Apart from his own subject he is as naive as a child. I remember
once entering the room and saying:
"Think what bad luck! They say, Skobielev is dead."
Nicolas crossed himself; but Peter Ignatievich turned to me:
"Which Skobielev do you mean?"
Another time,—some time earlier—I announced that Professor
Pierov was dead. That darling Peter Ignatievich asked:
"What was his subject?"
I imagine that if Patti sang into his ear, or Russia were attacked by
hordes of Chinamen, or there was an earthquake, he would not lift a
finger, but would go on in the quietest way with his eye screwed
over his microscope. In a word: "What's Hecuba to him?" I would
give anything to see how this dry old stick goes to bed with his wife.
Another trait: a fanatical belief in the infallibility of science, above
all in everything that the Germans write. He is sure of himself and
his preparations, knows the purpose of life, is absolutely ignorant of
the doubts and disillusionments that turn talents grey,—a slavish
worship of the authorities, and not a shadow of need to think for
himself. It is hard to persuade him and quite impossible to discuss
with him. Just try a discussion with a man who is profoundly
convinced that the best science is medicine, the best men doctors,
the best traditions—the medical! From the ugly past of medicine only
one tradition has survived,—the white necktie that doctors wear still.
For a learned, and more generally for an educated person there can
exist only a general university tradition, without any division into
traditions of medicine, of law, and so on. But it's quite impossible for
Peter Ignatievich to agree with that; and he is ready to argue it with
you till doomsday.
His future is quite plain to me. During the whole of his life he will
make several hundred preparations of extraordinary purity, will write
any number of dry, quite competent, essays, will make about ten
scrupulously accurate translations; but he won't invent gunpowder.
For gunpowder, imagination is wanted, inventiveness, and a gift for
divination, and Peter Ignatievich has nothing of the kind. In short,
he is not a master of science but a labourer.
Peter Ignatievich, Nicolas, and I whisper together. We are rather
strange to ourselves. One feels something quite particular, when the
audience booms like the sea behind the door. In thirty years I have
not grown used to this feeling, and I have it every morning. I button
up my frock-coat nervously, ask Nicolas unnecessary questions, get
angry.... It is as though I were afraid; but it is not fear, but
something else which I cannot name nor describe.
Unnecessarily, I look at my watch and say:
"Well, it's time to go."
And we march in, in this order: Nicolas with the preparations or
the atlases in front, myself next, and after me, the cart-horse,
modestly hanging his head; or, if necessary, a corpse on a stretcher
in front and behind the corpse Nicolas and so on. The students rise
when I appear, then sit down and the noise of the sea is suddenly
still. Calm begins.
I know what I will lecture about, but I know nothing of how I will
lecture, where I will begin and where I will end. There is not a single
sentence ready in my brain. But as soon as I glance at the audience,
sitting around me in an amphitheatre, and utter the stereotyped "In
our last lecture we ended with...." and the sentences fly out of my
soul in a long line—then it is full steam ahead. I speak with
irresistible speed, and with passion, and it seems as though no
earthly power could check the current of my speech. In order to
lecture well, that is without being wearisome and to the listener's
profit, besides talent you must have the knack of it and experience;
you must have a clear idea both of your own powers, of the people
to whom you are lecturing, and of the subject of your remarks.
Moreover, you must be quick in the uptake, keep a sharp eye open,
and never for a moment lose your field of vision.
When he presents the composer's thought, a good conductor does
twenty things at once. He reads the score, waves his baton, watches
the singer makes a gesture now towards the drum, now to the
double-bass, and so on. It is the same with me when lecturing. I
have some hundred and fifty faces before me, quite unlike each
other, and three hundred eyes staring me straight in the face. My
purpose is to conquer this many-headed hydra. If I have a clear idea
how far they are attending and how much they are comprehending
every minute while I am lecturing, then the hydra is in my power. My
other opponent is within me. This is the endless variety of forms,
phenomena and laws, and the vast number of ideas, whether my
own or others', which depend upon them. Every moment I must be
skilful enough to choose what is most important and necessary from
this enormous material, and just as swiftly as my speech flows to
clothe my thought in a form which will penetrate the hydra's
understanding and excite its attention. Besides I must watch
carefully to see that my thoughts shall not be presented as they
have been accumulated, but in a certain order, necessary for the
correct composition of the picture which I wish to paint. Further, I
endeavour to make my speech literary, my definitions brief and
exact, my sentences as simple and elegant as possible. Every
moment I must hold myself in and remember that I have only an
hour and forty minutes to spend. In other words, it is a heavy
labour. At one and the same time you have to be a savant, a
schoolmaster, and an orator, and it is a failure if the orator triumphs
over the schoolmaster in you or the schoolmaster over the orator.
After lecturing for a quarter, for half an hour, I notice suddenly
that the students have begun to stare at the ceiling or Peter
Ignatievich. One will feel for his handkerchief, another settle himself
comfortably, another smile at his own thoughts. This means their
attention is tried. I must take steps. I seize the first opening and
make a pun. All the hundred and fifty faces have a broad smile, their
eyes flash merrily, and for a while you can hear the boom of the sea.
I laugh too. Their attention is refreshed and I can go on.
No sport, no recreation, no game ever gave me such delight as
reading a lecture. Only in a lecture could I surrender myself wholly
to passion and understand that inspiration is not a poet's fiction, but
exists indeed. And I do not believe that Hercules, even after the
most delightful of his exploits, felt such a pleasant weariness as I
experienced every time after a lecture.
This was in the past. Now at lectures I experience only torture.
Not half an hour passes before I begin to feel an invincible weakness
in my legs and shoulders. I sit down in my chair, but I am not used
to lecture sitting. In a moment I am up again, and lecture standing.
Then I sit down again. Inside my mouth is dry, my voice is hoarse,
my head feels dizzy. To hide my state from my audience I drink
some water now and then, cough, wipe my nose continually, as
though I was troubled by a cold, make inopportune puns, and finally
announce the interval earlier than I should. But chiefly I feel
ashamed.
Conscience and reason tell me that the best thing I could do now
is to read my farewell lecture to the boys, give them my last word,
bless them and give up my place to someone younger and stronger
than I. But, heaven be my judge, I have not the courage to act up to
my conscience.
Unfortunately, I am neither philosopher nor theologian. I know
quite well I have no more than six months to live; and it would seem
that now I ought to be mainly occupied with questions of the
darkness beyond the grave, and the visions which will visit my sleep
in the earth. But somehow my soul is not curious of these questions,
though my mind grants every atom of their importance. Now before
my death it is just as it was twenty or thirty years ago. Only science
interests me.—When I take my last breath I shall still believe that
Science is the most important, the most beautiful, the most
necessary thing in the life of man; that she has always been and
always will be the highest manifestation of love, and that by her
alone will man triumph over nature and himself. This faith is,
perhaps, at bottom naive and unfair, but I am not to blame if this
and not another is my faith. To conquer this faith within me is for me
impossible.
But this is beside the point. I only ask that you should incline to
my weakness and understand that to tear a man who is more deeply
concerned with the destiny of a brain tissue than the final goal of
creation away from his rostrum and his students is like taking him
and nailing him up in a coffin without waiting until he is dead.
Because of my insomnia and the intense struggle with my
increasing weakness a strange thing happens inside me. In the
middle of my lecture tears rise to my throat, my eyes begin to ache,
and I have a passionate and hysterical desire to stretch out my
hands and moan aloud. I want to cry out that fate has doomed me,
a famous man, to death; that in some six months here in the
auditorium another will be master. I want to cry out that I am
poisoned; that new ideas that I did not know before have poisoned
the last days of my life, and sting my brain incessantly like
mosquitoes. At that moment my position seems so terrible to me
that I want all my students to be terrified, to jump from their seats
and rush panic-stricken to the door, shrieking in despair.
It is not easy to live through such moments.

II

After the lecture I sit at home and work. I read reviews,


dissertations, or prepare for the next lecture, and sometimes I write
something. I work with interruptions, since I have to receive visitors.
The bell rings. It is a friend who has come to talk over some
business. He enters with hat and stick. He holds them both in front
of him and says:
"Just a minute, a minute. Sit down, cher confrère. Only a word or
two."
First we try to show each other that we are both extraordinarily
polite and very glad to see each other. I make him sit down in the
chair, and he makes me sit down; and then we touch each other's
waists, and put our hands on each other's buttons, as though we
were feeling each other and afraid to bum ourselves. We both laugh,
though we say nothing funny. Sitting down, we bend our heads
together and begin to whisper to each other. We must gild our
conversation with such Chinese formalities as: "You remarked most
justly" or "I have already had the occasion to say." We must giggle if
either of us makes a pun, though it's a bad one. When we have
finished with the business, my friend gets up with a rush, waves his
hat towards my work, and begins to take his leave. We feel each
other once more and laugh. I accompany him down to the hall.
There I help my friend on with his coat, but he emphatically declines
so great an honour. Then, when Yegor opens the door my friend
assures me that I will catch cold, and I pretend to be ready to follow
him into the street. And when I finally return to my study my face
keeps smiling still, it must be from inertia.
A little later another ring. Someone enters the hall, spends a long
time taking off his coat and coughs. Yegor brings me word that a
student has come. I tell him to show him up. In a minute a pleasant-
faced young man appears. For a year we have been on these forced
terms together. He sends in abominable answers at examinations,
and I mark him gamma. Every year I have about seven of these
people to whom, to use the students' slang, "I give a plough" or
"haul them through." Those of them who fail because of stupidity or
illness, usually bear their cross in patience and do not bargain with
me; only sanguine temperaments, "open natures," bargain with me
and come to my house, people whose appetite is spoiled or who are
prevented from going regularly to the opera by a delay in their
examinations. With the first I am over-indulgent; the second kind I
keep on the run for a year.
"Sit down," I say to my guest. "What was it you wished to say?"
"Forgive me for troubling you, Professor...." he begins, stammering
and never looking me in the face. "I would not venture to trouble
you unless.... I was up for my examination before you for the fifth
time ... and I failed. I implore you to be kind, and give me a 'satis,'
because...."
The defence which all idlers make of themselves is always the
same. They have passed in every other subject with distinction, and
failed only in mine, which is all the more strange because they had
always studied my subject most diligently and know it thoroughly.
They failed through some inconceivable misunderstanding.
"Forgive me, my friend," I say to my guest. "But I can't give you a
'satis'—impossible. Go and read your lectures again, and then come.
Then we'll see."
Pause. I get a desire to torment the student a little, because he
prefers beer and the opera to science; and I say with a sigh:
"In my opinion, the best thing for you now is to give up the
Faculty of Medicine altogether. With your abilities, if you find it
impossible to pass the examination, then it seems you have neither
the desire nor the vocation to be a doctor."
My sanguine friend's face grows grave.
"Excuse me, Professor," he smiles, "but it would be strange, to say
the least, on my part. Studying medicine for five years and suddenly
—to throw it over."
"Yes, but it's better to waste five years than to spend your whole
life afterwards in an occupation which you dislike."
Immediately I begin to feel sorry for him and hasten to say:
"Well, do as you please. Read a little and come again."
"When?" the idler asks, dully.
"Whenever you like. To-morrow, even."
And I read in his pleasant eyes. "I can come again; but you'll send
me away again, you beast."
"Of course," I say, "you won't become more learned because you
have to come up to me fifteen times for examination; but this will
form your character. You must be thankful for that."
Silence. I rise and wait for my guest to leave. But he stands there,
looking at the window, pulling at his little beard and thinking. It
becomes tedious.
My sanguine friend has a pleasant, succulent voice, clever,
amusing eyes, a good-natured face, rather puffed by assiduity to
beer and much resting on the sofa. Evidently he could tell me many
interesting things about the opera, about his love affairs, about the
friends he adores; but, unfortunately, it is not the thing. And I would
so eagerly listen!
"On my word of honour, Professor, if you give me a 'satis' I'll...."
As soon as it gets to "my word of honour," I wave my hands and
sit down to the table. The student thinks for a while and says,
dejectedly:
"In that case, good-bye.... Forgive me!"
"Good-bye, my friend.... Good-bye!"
He walks irresolutely into the hall, slowly puts on his coat, and,
when he goes into the street, probably thinks again for a long while;
having excogitated nothing better than "old devil" for me, he goes to
a cheap restaurant to drink beer and dine, and then home to sleep.
Peace be to your ashes, honest labourer!
A third ring. Enters a young doctor in a new black suit, gold-
rimmed spectacles and the inevitable white necktie. He introduces
himself. I ask him to take a seat and inquire his business. The young
priest of science begins to tell me, not without agitation, that he
passed his doctor's examination this year, and now has only to write
his dissertation. He would like to work with me, under my guidance;
and I would do him a great kindness if I would suggest a subject for
his dissertation.
"I should be delighted to be of use to you, mon cher confrère," I
say. "But first of all, let us come to an agreement as to what is a
dissertation. Generally we understand by this, work produced as the
result of an independent creative power. Isn't that so? But a work
written on another's subject, under another's guidance, has a
different name."
The aspirant is silent. I fire up and jump out of my seat. "Why do
you all come to me? I can't understand," I cry out angrily. "Do I
keep a shop? I don't sell theses across the counter. For the one
thousandth time I ask you all to leave me alone. Forgive my
rudeness, but I've got tired of it at last!"
The aspirant is silent. Only, a tinge of colour shows on his cheek.
His face expresses his profound respect for my famous name and my
erudition, but I see in his eyes that he despises my voice, my pitiable
figure, my nervous gestures. When I am angry I seem to him a very
queer fellow.
"I do not keep a shop," I storm. "It's an amazing business! Why
don't you want to be independent? Why do you find freedom so
objectionable?"
I say a great deal, but he is silent. At last by degrees I grow calm,
and, of course, surrender. The aspirant will receive a valueless
subject from me, will write under my observation a needless thesis,
will pass his tedious disputation cum laude and will get a useless and
learned degree.
The rings follow in endless succession, but here I confine myself
to four. The fourth ring sounds, and I hear the familiar steps, the
rustling dress, the dear voice.
Eighteen years ago my dear friend, the oculist, died and left
behind him a seven year old daughter, Katy, and sixty thousand
roubles. By his will he made me guardian. Katy lived in my family till
she was ten. Afterwards she was sent to College and lived with me
only in her holidays in the summer months. I had no time to attend
to her education. I watched only by fits and starts; so that I can say
very little about her childhood.
The chief thing I remember, the one I love to dwell upon in
memory, is the extraordinary confidence which she had when she
entered my house, when she had to have the doctor,—a confidence
which was always shining in her darling face. She would sit in a
corner somewhere with her face tied up, and would be sure to be
absorbed in watching something. Whether she was watching me
write and read books, or my wife bustling about, or the cook peeling
the potatoes in the kitchen or the dog playing about—her eyes
invariably expressed the same thing: "Everything that goes on in this
world,—everything is beautiful and clever." She was inquisitive and
adored to talk to me. She would sit at the table opposite me,
watching my movements and asking questions. She is interested to
know what I read, what I do at the University, if I'm not afraid of
corpses, what I do with my money.
"Do the students fight at the University?" she would ask.
"They do, my dear."
"You make them go down on their knees?"
"I do."
And it seemed funny to her that the students fought and that I
made them go down on their knees, and she laughed. She was a
gentle, good, patient child.
Pretty often I happened to see how something was taken away
from her, or she was unjustly punished, or her curiosity was not
satisfied. At such moments sadness would be added to her
permanent expression of confidence—nothing more. I didn't know
how to take her part, but when I saw her sadness, I always had the
desire to draw her close to me and comfort her in an old nurse's
voice: "My darling little orphan!"
I remember too she loved to be well dressed and to sprinkle
herself with scents. In this she was like me. I also love good clothes
and fine scents.
I regret that I had neither the time nor the inclination to watch the
beginnings and the growth of the passion which had completely
taken hold of Katy when she was no more than fourteen or fifteen. I
mean her passionate love for the theatre. When she used to come
from the College for her holidays and live with us, nothing gave her
such pleasure and enthusiasm to talk about as plays and actors. She
used to tire us with her incessant conversation about the theatre. I
alone hadn't the courage to deny her my attention. My wife and
children did not listen to her. When she felt the desire to share her
raptures she would come to my study and coax: "Nicolai Stiepanich,
do let me speak to you about the theatre."
I used to show her the time and say:
"I'll give you half an hour. Fire away!"
Later on she used to bring in pictures of the actors and actresses
she worshipped—whole dozens of them. Then several times she
tried to take part in amateur theatricals, and finally when she left
College she declared to me she was born to be an actress.
I never shared Katy's enthusiasms for the theatre. My opinion is
that if a play is good then there's no need to trouble the actors for it
to make the proper impression; you can be satisfied merely by
reading it. If the play is bad, no acting will make it good.
When I was young I often went to the theatre, and nowadays my
family takes a box twice a year and carries me off for an airing
there. Of course this is not enough to give me the right to pass
verdicts on the theatre; but I will say a few words about it. In my
opinion the theatre hasn't improved in the last thirty or forty years. I
can't find any more than I did then, a glass of dean water, either in
the corridors or the foyer. Just as they did then, the attendants fine
me sixpence for my coat, though there's nothing illegal in wearing a
warm coat in winter. Just as it did then, the orchestra plays quite
unnecessarily in the intervals, and adds a new, gratuitous impression
to the one received from the play. Just as they did then, men go to
the bar in the intervals and drink spirits. If there is no perceptible
improvement in little things, it will be useless to look for it in the
bigger things. When an actor, hide-bound in theatrical traditions and
prejudices, tries to read simple straightforward monologue: "To be or
not to be," not at all simply, but with an incomprehensible and
inevitable hiss and convulsions over his whole body, or when he tries
to convince me that Chazky, who is always talking to fools and is in
love with a fool, is a very clever man and that "The Sorrows of
Knowledge" is not a boring play,—then I get from the stage a breath
of the same old routine that exasperated me forty years ago when I
was regaled with classical lamentation and beating on the breast.
Every time I come out of the theatre a more thorough conservative
than I went in.
It's quite possible to convince the sentimental, self-confident
crowd that the theatre in its present state is an education. But not a
man who knows what true education is would swallow this. I don't
know what it may be in fifty or a hundred years, but under present
conditions the theatre can only be a recreation. But the recreation is
too expensive for continual use, and robs the country of thousands
of young, healthy, gifted men and women, who if they had not
devoted themselves to the theatre would be excellent doctors,
farmers, schoolmistresses, or officers. It robs the public of its
evenings, the best time for intellectual work and friendly
conversation. I pass over the waste of money and the moral injuries
to the spectator when he sees murder, adultery, or slander wrongly
treated on the stage.
But Katy's opinion was quite the opposite. She assured me that
even in its present state the theatre is above lecture-rooms and
books, above everything else in the world. The theatre is a power
that unites in itself all the arts, and the actors are men with a
mission. No separate art or science can act on the human soul so
strongly and truly as the stage; and therefore it is reasonable that a
medium actor should enjoy much greater popularity than the finest
scholar or painter. No public activity can give such delight and
satisfaction as the theatrical.
So one fine day Katy joined a theatrical company and went away, I
believe, to Ufa, taking with her a lot of money, a bagful of rainbow
hopes, and some very high-class views on the business.
Her first letters on the journey were wonderful. When I read them
I was simply amazed that little sheets of paper could contain so
much youth, such transparent purity, such divine innocence, and at
the same time so many subtle, sensible judgments, that would do
honour to a sound masculine intelligence. The Volga, nature, the
towns she visited, her friends, her successes and failures—she did
not write about them, she sang. Every line breathed the confidence
which I used to see in her face; and with all this a mass of
grammatical mistakes and hardly a single stop.
Scarce six months passed before I received a highly poetical
enthusiastic letter, beginning, "I have fallen in love." She enclosed a
photograph of a young man with a clean-shaven face, in a broad-
brimmed hat, with a plaid thrown over his shoulders. The next
letters were just as splendid, but stops already began to appear and
the grammatical mistakes to vanish. They had a strong masculine
scent. Katy began to write about what a good thing it would be to
build a big theatre somewhere in the Volga, but on a cooperative
basis, and to attract the rich business-men and shipowners to the
undertaking. There would be plenty of money, huge receipts, and
the actors would work in partnership.... Perhaps all this is really a
good thing, but I can't help thinking such schemes could only come
from a man's head.
Anyhow for eighteen months or a couple of years everything
seemed to be all right. Katy was in love, had her heart in her
business and was happy. But later on I began to notice dear
symptoms of a decline in her letters. It began with Katy complaining
about her friends. This is the first and most ominous sign. If a young
scholar or litterateur begins his career by complaining bitterly about
other scholars or littérateurs, it means that he is tired already and
not fit for his business. Katy wrote to me that her friends would not
come to rehearsals and never knew their parts; that they showed an
utter contempt for the public in the absurd plays they staged and
the manner they behaved. To swell the box-office receipts—the only
topic of conversation—serious actresses degrade themselves by
singing sentimentalities, and tragic actors sing music-hall songs,
laughing at husbands who are deceived and unfaithful wives who
are pregnant. In short, it was amazing that the profession, in the
provinces, was not absolutely dead. The marvel was that it could
exist at all with such thin, rotten blood in its veins.
In reply I sent Katy a long and, I confess, a very tedious letter.
Among other things I wrote: "I used to talk fairly often to actors in
the past, men of the noblest character, who honoured me with their
friendship. From my conversations with them I understood that their
activities were guided rather by the whim and fashion of society than
by the free working of their own minds. The best of them in their
lifetime had to play in tragedy, in musical comedy, in French farce,
and in pantomime; yet all through they considered that they were
treading the right path and being useful. You see that this means
that you must look for the cause of the evil, not in the actors, but
deeper down, in the art itself and the attitude of society towards it."
This letter of mine only made Katy cross. "You and I are playing in
different operas. I didn't write to you about men of the noblest
character, but about a lot of sharks who haven't a spark of nobility in
them. They are a horde of savages who came on the stage only
because they wouldn't be allowed anywhere else. The only ground
they have for calling themselves artists is their impudence. Not a
single talent among them, but any number of incapables, drunkards,
intriguers, and slanderers. I can't tell you how bitterly I feel it that
the art I love so much is fallen into the hands of people I despise. It
hurts me that the best men should be content to look at evil from a
distance and not want to come nearer. Instead of taking an active
part, they write ponderous platitudes and useless sermons...." and
more in the same strain.
A little while after I received the following: "I have been
inhumanly deceived. I can't go on living any more. Do as you think
fit with my money. I loved you as a father and as my only friend.
Forgive me."
So it appeared that he too belonged to the horde of savages.
Later on, I gathered from various hints, that there was an attempt at
suicide. Apparently, Katy tried to poison herself. I think she must
have been seriously ill afterwards, for I got the following letter from
Yalta, where most probably the doctors had sent her. Her last letter
to me contained a request that I should send her at Yalta a
thousand roubles, and it ended with the words: "Forgive me for
writing such a sad letter. I buried my baby yesterday." After she had
spent about a year in the Crimea she returned home.
She had been travelling for about four years, and during these
four years I confess that I occupied a strange and unenviable
position in regard to her. When she announced to me that she was
going on to the stage and afterwards wrote to me about her love;
when the desire to spend took hold of her, as it did periodically, and
I had to send her every now and then one or two thousand roubles
at her request; when she wrote that she intended to die, and
afterwards that her baby was dead,—-I was at a loss every time. All
my sympathy with her fate consisted in thinking hard and writing
long tedious letters which might as well never have been written.
But then I was in loco parentis and I loved her as a daughter.
Katy lives half a mile away from me now. She took a five-roomed
house and furnished it comfortably, with the taste that was born in
her. If anyone were to undertake to depict her surroundings, then
the dominating mood of the picture would be indolence. Soft
cushions, soft chairs for her indolent body; carpets for her indolent
feet; faded, dim, dull colours for her indolent eyes; for her indolent
soul, a heap of cheap fans and tiny pictures on the walls, pictures in
which novelty of execution was more noticeable than content; plenty
of little tables and stands, set out with perfectly useless and
worthless things, shapeless scraps instead of curtains.... All this,
combined with a horror of bright colours, of symmetry, and space,
betokened a perversion of the natural taste as well as indolence of
the soul. For whole days Katy lies on the sofa and reads books,
mostly novels and stories. She goes outside her house but once in
the day, to come and see me.
I work. Katy sits on the sofa at my side. She is silent, and wraps
herself up in her shawl as though she were cold. Either because she
is sympathetic to me, or I because I had got used to her continual
visits while she was still a little girl, her presence does not prevent
me from concentrating on my work. At long intervals I ask her some
question or other, mechanically, and she answers very curtly; or, for
a moment's rest, I turn towards her and watch how she is absorbed
in looking through some medical review or newspaper. And then I
see that the old expression of confidence in her face is there no
more. Her expression now is cold, indifferent, distracted, like that of
a passenger who has to wait a long while for his train. She dresses
as she used—well and simply, but carelessly. Evidently her clothes
and her hair suffer not a little from the sofas and hammocks on
which she lies for days together. And she is not curious any more.
She doesn't ask me questions any more, as if she had experienced
everything in life and did not expect to hear anything new.
About four o'clock there is a sound of movement in the hall and
the drawing-room. It's Liza come back from the Conservatoire,
bringing her friends with her. You can hear them playing the piano,
trying their voices and giggling. Yegor is laying the table in the
dining-room and making a noise with the plates.
"Good-bye," says Katy. "I shan't go in to see your people. They
must excuse me. I haven't time. Come and see me."
When I escort her into the hall, she looks me over sternly from
head to foot, and says in vexation:
"You get thinner and thinner. Why don't you take a cure? I'll go to
Sergius Fiodorovich and ask him to come. You must let him see
you."
"It's not necessary, Katy."
"I can't understand why your family does nothing. They're a nice
lot."
She puts on her jacket with her rush. Inevitably, two or three hair-
pins fall out of her careless hair on to the floor. It's too much bother
to tidy her hair now; besides she is in a hurry. She pushes the
straggling strands of hair untidily under her hat and goes away.
As soon as I come into the dining-room, my wife asks:
"Was that Katy with you just now? Why didn't she come to see us.
It really is extraordinary...."
"Mamma!" says Liza reproachfully, "If she doesn't want to come,
that's her affair. There's no need for us to go on our knees."
"Very well; but it's insulting. To sit in the study for three hours,
without thinking of us. But she can do as she likes."
Varya and Liza both hate Katy. This hatred is unintelligible to me;
probably you have to be a woman to understand it. I'll bet my life on
it that you'll hardly find a single one among the hundred and fifty
young men I see almost every day in my audience, or the hundred
old ones I happen to meet every week, who would be able to
understand why women hate and abhor Katy's past, her being
pregnant and unmarried and her illegitimate child. Yet at the same
time I cannot bring to mind a single woman or girl of my
acquaintance who would not cherish such feelings, either
consciously or instinctively. And it's not because women are purer
and more virtuous than men. If virtue and purity are not free from
evil feeling, there's precious little difference between them and vice.
I explain it simply by the backward state of women's development.
The sorrowful sense of compassion and the torment of conscience,
which the modern man experiences when he sees distress have
much more to tell me about culture and moral development than
have hatred and repulsion. The modern woman is as lachrymose and
as coarse in heart as she was in the middle ages. And in my opinion
those who advise her to be educated like a man have wisdom on
their side.
But still my wife does not like Katy, because she was an actress,
and for her ingratitude, her pride, her extravagances, and all the
innumerable vices one woman can always discover in another.
Besides myself and my family we have two or three of my
daughter's girl friends to dinner and Alexander Adolphovich Gnekker,
Liza's admirer and suitor. He is a fair young man, not more than
thirty years old, of middle height, very fat, broad shouldered, with
reddish hair round his ears and a little stained moustache, which
give his smooth chubby face the look of a doll's. He wears a very
short jacket, a fancy waistcoat, large-striped trousers, very full on
the hip and very narrow in the leg, and brown boots without heels.
His eyes stick out like a lobster's, his tie is like a lobster's tail, and I
can't help thinking even that the smell of lobster soup clings about
the whole of this young man. He visits us every day; but no one in
the family knows where he comes from, where he was educated, or
how he lives. He cannot play or sing, but he has a certain connection
with music as well as singing, for he is agent for somebody's pianos,
and is often at the Academy. He knows all the celebrities, and he
manages concerts. He gives his opinion on music with great
authority and I have noticed that everybody hastens to agree with
him.
Rich men always have parasites about them. So do the sciences
and the arts. It seems that there is no science or art in existence,
which is free from such "foreign bodies" as this Mr. Gnekker. I am
not a musician and perhaps I am mistaken about Gnekker, besides I
don't know him very well. But I can't help suspecting the authority
and dignity with which he stands beside the piano and listens when
anyone is singing or playing.
You may be a gentleman and a privy councillor a hundred times
over; but if you have a daughter you can't be guaranteed against the
pettinesses that are so often brought into your house and into your
own humour, by courtings, engagements, and weddings. For
instance, I cannot reconcile myself to my wife's solemn expression
every time Gnekker comes to our house, nor to those bottles of
Château Lafitte, port, and sherry which are put on the table only for
him, to convince him beyond doubt of the generous luxury in which
we live. Nor can I stomach the staccato laughter which Liza learned
at the Academy, and her way of screwing up her eyes, when men
are about the house. Above all, I can't understand why it is that
such a creature should come to me every day and have dinner with
me—a creature perfectly foreign to my habits, my science, and the
whole tenour of my life, a creature absolutely unlike the men I love.
My wife and the servants whisper mysteriously that that is "the
bridegroom," but still I can't understand why he's there. It disturbs
my mind just as much as if a Zulu were put next to me at table.
Besides, it seems strange to me that my daughter whom I used to
think of as a baby should be in love with that necktie, those eyes,
those chubby cheeks.
Formerly, I either enjoyed my dinner or was indifferent about it.
Now it does nothing but bore and exasperate me. Since I was made
an Excellency and Dean of the Faculty, for some reason or other my
family found it necessary to make a thorough change in our menu
and the dinner arrangements. Instead of the simple food I was used
to as a student and a doctor, I am now fed on potage-puree, with
some sossoulki swimming about in it, and kidneys in Madeira. The
title of General and my renown have robbed me for ever of schi and
savoury pies, and roast goose with apple sauce, and bream with
kasha. They robbed me as well of my maid servant Agasha, a funny,
talkative old woman, instead of whom I am now waited on by Yegor,
a stupid, conceited fellow who always has a white glove in his right
hand. The intervals between the courses are short, but they seem
terribly long. There is nothing to fill them. We don't have any more
of the old good-humour, the familiar conversations, the jokes and
the laughter; no more mutual endearments, or the gaiety that used
to animate my children, my wife, and myself when we met at the
dinner table. For a busy man like me dinner was a time to rest and
meet my friends, and a feast for my wife and children, not a very
long feast, to be sure, but a gay and happy one, for they knew that
for half an hour I did not belong to science and my students, but
solely to them and to no one else. No more chance of getting tipsy
on a single glass of wine, no more Agasha, no more bream with
kasha, no more the old uproar to welcome our little contretemps at
dinner, when the cat fought the dog under the table, or Katy's head-
band fell down her cheek into her soup.
Our dinner nowadays is as nasty to describe as to eat. On my
wife's face there is pompousness, an assumed gravity, and the usual
anxiety. She eyes our plates nervously: "I see you don't like the
meat?... Honestly, don't you like it?" And I must answer, "Don't
worry, my dear. The meat is very good." She: "You're always taking
my part, Nicolai Stiepanich. You never tell the truth. Why has
Alexander Adolphovich eaten so little?" and the same sort of
conversation for the whole of dinner. Liza laughs staccato and screws
up her eyes. I look at both of them, and at this moment at dinner
here I can see quite clearly that their inner lives have slipped out of
my observation long ago. I feel as though once upon a time I lived
at home with a real family, but now I am dining as a guest with an
unreal wife and looking at an unreal Liza. There has been an utter
change in both of them, while I have lost sight of the long process
that led up to the change. No wonder I don't understand anything.
What was the reason of the change? I don't know. Perhaps the only
trouble is that God did not give my wife and daughter the strength
He gave me. From my childhood I have been accustomed to resist
outside influences and have been hardened enough. Such earthly
catastrophes as fame, being made General, the change from comfort
to living above my means, acquaintance with high society, have
scarcely touched me. I have survived safe and sound. But it all fell
down like an avalanche on my weak, unhardened wife and Liza, and
crushed them.
Gnekker and the girls talk of fugues and counter-fugues; singers
and pianists, Bach and Brahms, and my wife, frightened of being
suspected of musical ignorance, smiles sympathetically and
murmurs: "Wonderful.... Is it possible?... Why?..." Gnekker eats
steadily, jokes gravely, and listens condescendingly to the ladies'
remarks. Now and then he has the desire to talk bad French, and
then he finds it necessary for some unknown reason to address me
magnificently, "Votre Excellence."
And I am morose. Apparently I embarrass them all and they
embarrass me. I never had any intimate acquaintance with class
antagonism before, but now something of the kind torments me
indeed. I try to find only bad traits in Gnekker. It does not take long
and then I am tormented because one of my friends has not taken
his place as bridegroom. In another way too his presence has a bad
effect upon me. Usually, when I am left alone with myself or when I
am in the company of people I love, I never think of my merits; and
if I begin to think about them they seem as trivial as though I had
become a scholar only yesterday. But in the presence of a man like
Gnekker my merits appear to me like an extremely high mountain,
whose summit is lost in the clouds, while Gnekkers move about the
foot, so small as hardly to be seen.
After dinner I go up to my study and light my little pipe, the only
one during the whole day, the sole survivor of my old habit of
smoking from morning to night. My wife comes into me while I am
smoking and sits down to speak to me. Just as in the morning, I
know beforehand what the conversation will be.
"We ought to talk seriously, Nicolai Stiepanovich," she begins. "I
mean about Liza. Why won't you attend?"
"Attend to what?"
"You pretend you don't notice anything. It's not right: It's not right
to be unconcerned. Gnekker has intentions about Liza. What do you
say to that?"
"I can't say he's a bad man, because I don't know him; but I've
told you a thousand times already that I don't like him."
"But that's impossible ... impossible...." She rises and walks about
in agitation.
"It's impossible to have such an attitude to a serious matter," she
says. "When our daughter's happiness is concerned, we must put
everything personal aside. I know you don't like him.... Very well....
But if we refuse him now and upset everything, how can you
guarantee that Liza won't have a grievance against us for the rest of
her life? Heaven knows there aren't many young men nowadays. It's
quite likely there won't be another chance. He loves Liza very much
and she likes him, evidently. Of course he hasn't a settled position.
But what is there to do? Please God, he'll get a position in time. He
comes of a good family, and he's rich."
"How did you find that out?"
"He said so himself. His father has a big house in Kharkov and an
estate outside. You must certainly go to Kharkov."
"Why?"
"You'll find out there. You have acquaintances among the
professors there. I'd go myself. But I'm a woman. I can't."
"I will not go to Kharkov," I say morosely.
My wife gets frightened; a tormented expression comes over her
face.
"For God's sake, Nicolai Stiepanich," she implores, sobbing, "For
God's sake help me with this burden! It hurts me."
It is painful to look at her.
"Very well, Varya," I say kindly, "If you like—very well I'll go to
Kharkov, and do everything you want."
She puts her handkerchief to her eyes and goes to cry in her
room. I am left alone.
A little later they bring in the lamp. The familiar shadows that
have wearied me for years fall from the chairs and the lamp-shade
on to the walls and the floor. When I look at them it seems that it's
night already, and the cursed insomnia has begun. I lie down on the
bed; then I get up and walk about the room then lie down again. My
nervous excitement generally reaches its highest after dinner, before
the evening. For no reason I begin to cry and hide my head in the
pillow. All the while I am afraid somebody may come in; I am afraid
I shall die suddenly; I am ashamed of my tears; altogether,
something intolerable is happening in my soul. I feel I cannot look at
the lamp or the books or the shadows on the floor, or listen to the
voices in the drawing-room any more. Some invisible, mysterious
force pushes me rudely out of my house. I jump up, dress hurriedly,
and go cautiously out into the street so that the household shall not
notice me. Where shall I go?
The answer to this question has long been there in my brain: "To
Katy."

III

As usual she is lying on the Turkish divan or the couch and reading
something. Seeing me she lifts her head languidly, sits down, and
gives me her hand.
"You are always lying down like that," I say after a reposeful
silence. "It's unhealthy. You'd far better be doing something."
"Ah?"
"You'd far better be doing something, I say."
"What?... A woman can be either a simple worker or an actress."
"Well, then—if you can't become a worker, be an actress."
She is silent.
"You had better marry," I say, half-joking.
"There's no one to marry: and no use if I did."
"You can't go on living like this."
"Without a husband? As if that mattered. There are as many men
as you like, if you only had the will."
"This isn't right, Katy."
"What isn't right?"
"What you said just now."
Katy sees that I am chagrined, and desires to soften the bad
impression.
"Come. Let's come here. Here."
She leads me into a small room, very cosy, and points to the
writing table.
"There. I made it for you. You'll work here. Come every day and
bring your work with you. They only disturb you there at home....
Will you work here? Would you like to?"
In order not to hurt her by refusing, I answer that I shall work
with her and that I like the room immensely. Then we both sit down
in the cosy room and begin to talk.
The warmth, the cosy surroundings, the presence of a
sympathetic being, rouses in me now not a feeling of pleasure as it
used but a strong desire to complain and grumble. Anyhow it seems
to me that if I moan and complain I shall feel better.
"It's a bad business, my dear," I begin with a sigh. "Very bad."
"What is the matter?"
"I'll tell you what is the matter. The best and most sacred right of
kings is the right to pardon. And I have always felt myself a king so
long as I used this right prodigally. I never judged, I was
compassionate, I pardoned everyone right and left. Where others
protested and revolted I only advised and persuaded. All my life I've
tried to make my society tolerable to the family of students, friends
and servants. And this attitude of mine towards people, I know,
educated every one who came into contact with me. But now I am
king no more. There's something going on in me which belongs only
to slaves. Day and night evil thoughts roam about in my head, and
feelings which I never knew before have made their home in my
soul. I hate and despise; I'm exasperated, disturbed, and afraid. I've
become strict beyond measure, exacting, unkind, and suspicious.
Even the things which in the past gave me the chance of making an
extra pun, now bring me a feeling of oppression. My logic has
changed too. I used to despise money alone; now I cherish evil
feelings, not to money, but to the rich, as if they were guilty. I used
to hate violence and arbitrariness; now I hate the people who
employ violence, as if they alone are to blame and not all of us, who
cannot educate one another. What does it all mean? If my new
thoughts and feelings come from a change of my convictions, where
could the change have come from? Has the world grown worse and
I better, or was I blind and indifferent before? But if the change is
due to the general decline of my physical and mental powers—I am
sick and losing weight every day—then I'm in a pitiable position. It
means that my new thoughts are abnormal and unhealthy, that I
must be ashamed of them and consider them valueless...."
"Sickness hasn't anything to do with it," Katy interrupts. "Your
eyes are opened—that's all. You've begun to notice things you didn't
want to notice before for some reason. My opinion is that you must
break with your family finally first of all and then go away."
"You're talking nonsense."
"You don't love them any more. Then, why do you behave
unfairly? And is it a family! Mere nobodies. If they died to-day, no
one would notice their absence to-morrow."
Katy despises my wife and daughter as much as they hate her. It's
scarcely possible nowadays to speak of the right of people to despise
one another. But if you accept Katy's point of view and own that
such a right exists, you will notice that she has the same right to
despise my wife and Liza as they have to hate her.
"Mere nobodies!" she repeats. "Did you have any dinner to-day?
It's a wonder they didn't forget to tell you dinner was ready. I don't
know how they still remember that you exist."
"Katy!" I say sternly. "Please be quiet."
"You don't think it's fun for me to talk about them, do you? I wish
I didn't know them at all. You listen to me, dear. Leave everything
and go away: go abroad—the quicker, the better."
"What nonsense! What about the University?"
"And the University, too. What is it to you? There's no sense in it
all. You've been lecturing for thirty years, and where are your pupils?
Have you many famous scholars? Count them up. But to increase
the number of doctors who exploit the general ignorance and make
hundreds of thousands,—there's no need to be a good and gifted
man. You aren't wanted."
"My God, how bitter you are!" I get terrified. "How bitter you are.
Be quiet, or I'll go away. I can't reply to the bitter things you say."
The maid enters and calls us to tea. Thank God, our conversation
changes round the samovar. I have made my moan, and now I want
to indulge another senile weakness—reminiscences. I tell Katy about
my past, to my great surprise with details that I never suspected I
had kept safe in my memory. And she listens to me with emotion,
with pride, holding her breath. I like particularly to tell how I once
was a student at a seminary and how I dreamed of entering the
University.
"I used to walk in the seminary garden," I tell her, "and the wind
would bring the sound of a song and the thrumming of an accordion
from a distant tavern, or a troika with bells would pass quickly by
the seminary fence. That would be quite enough to fill not only my
breast with a sense of happiness, but my stomach, legs, and hands.
As I heard the sound of the accordion or the bells fading away, I
would see myself a doctor and paint pictures, one more glorious
than another. And, you see, my dreams came true. There were more
things I dared to dream of. I have been a favourite professor thirty
years, I have had excellent friends and an honourable reputation. I
loved and married when I was passionately in love. I had children.
Altogether, when I look back the whole of my life seems like a nice,
clever composition. The only thing I have to do now is not to spoil
the finale. For this, I must die like a man. If death is really a danger
then I must meet it as becomes a teacher, a scholar, and a citizen of
a Christian State. But I am spoiling the finale. I am drowning, and I
run to you and beg for help, and you say: 'Drown. It's your duty.'"
At this point a ring at the bell sounds in the hall. Katy and I both
recognise it and say:
"That must be Mikhail Fiodorovich."
And indeed in a minute Mikhail Fiodorovich, my colleague, the
philologist, enters. He is a tall, well-built man about fifty years old,
clean shaven, with thick grey hair and black eyebrows. He is a good
man and an admirable friend. He belongs to an old aristocratic
family, a prosperous and gifted house which has played a notable
rôle in the history of our literature and education. He himself is
clever, gifted, and highly educated, but not without his eccentricities.
To a certain extent we are all eccentric, queer fellows, but his
eccentricities have an element of the exceptional, not quite safe for
his friends. Among the latter I know not a few who cannot see his
many merits clearly because of his eccentricities.
As he walks in he slowly removes his gloves and says in his
velvety bass:
"How do you do? Drinking tea. Just in time. It's hellishly cold."
Then he sits down at the table, takes a glass of tea and
immediately begins to talk. What chiefly marks his way of talking is
his invariably ironical tone, a mixture of philosophy and jest, like
Shakespeare's grave-diggers. He always talks of serious matters; but
never seriously. His opinions are always acid and provocative, but
thanks to his tender, easy, jesting tone, it somehow happens that his
acidity and provocativeness don't tire one's ears, and one very soon
gets used to it. Every evening he brings along some half-dozen
stories of the university life and generally begins with them when he
sits down at the table.
"O Lord," he sighs with an amusing movement of his black
eyebrows, "there are some funny people in the world."
"Who?" asks Katy.
"I was coming down after my lecture to-day and I met that old
idiot N—— on the stairs. He walks along, as usual pushing out that
horse jowl of his, looking for some one to bewail his headaches, his
wife, and his students, who won't come to his lectures. 'Well,' I think
to myself, 'he's seen me. It's all up—no hope for And so on in the
same strain. Or he begins like this,
"Yesterday I was at Z's public lecture. Tell it not in Gath, but I do
wonder how our alma mater dares to show the public such an ass,
such a double-dyed blockhead as Z. Why he's a European fool. Good
Lord, you won't find one like him in all Europe—not even if you
looked in daytime, and with a lantern. Imagine it: he lectures as
though he were sucking a stick of barley-sugar—su—su—su. He gets
a fright because he can't make out his manuscript. His little thoughts
will only just keep moving, hardly moving, like a bishop riding a
bicycle. Above all you can't make out a word he says. The flies die of
boredom, it's so terrific. It can only be compared with the boredom
in the great Hall at the Commemoration, when the traditional speech
is made. To hell with it!"
Immediately an abrupt change of subject.
"I had to make the speech; three years ago. Nicolai Stiepanovich
will remember. It was hot, close. My full uniform was tight under my
arms, tight as death. I read for half an hour, an hour, an hour and a
half, two hours. 'Well,' I thought, 'thank God I've only ten pages left.'
And I had four pages of peroration that I needn't read at all. 'Only
six pages then,' I thought. Imagine it. I just gave a glance in front of
me and saw sitting next to each other in the front row a general
with a broad ribbon and a bishop. The poor devils were bored stiff.
They were staring about madly to stop themselves from going to
sleep. For all that they are still trying to look attentive, to make
some appearance of understanding what I'm reading, and look as
though they like it. 'Well,' I thought, 'if you like it, then you shall
have it. I'll spite you.' So I set to and read the four pages, every
word."
When he speaks only his eyes and eyebrows smile as it is
generally with the ironical. At such moments there is no hatred or
malice in his eyes but a great deal of acuteness and that peculiar
fox-cunning which you can catch only in very observant people.
Further, about his eyes I have noticed one more peculiarity. When he
takes his glass from Katy, or listens to her remarks, or follows her
with a glance as she goes out of the room for a little while, then I
catch in his look something humble, prayerful, pure....
The maid takes the samovar away and puts on the table a big
piece of cheese, some fruit, and a bottle of Crimean champagne, a
thoroughly bad wine which Katy got to like when she lived in the
Crimea. Mikhail Fiodorovich takes two packs of cards from the
shelves and sets them out for patience. If one may believe his
assurances, some games of patience demand a great power of
combination and concentration. Nevertheless while he sets out the
cards he amuses himself by talking continually. Katy follows his cards
carefully, helping him more by mimicry than words. In the whole
evening she drinks no more than two small glasses of wine, I drink
only a quarter of a glass, the remainder of the bottle falls to Mikhail
Fiodorovich, who can drink any amount without ever getting drunk.
During patience we solve all kinds of questions, mostly of the lofty
order, and our dearest love, science, comes off second best.
"Science, thank God, has had her day," says Mikhail Fiodorovich
very slowly. "She has had her swan-song. Ye-es. Mankind has begun
to feel the desire to replace her by something else. She was grown
from the soil of prejudice, fed by prejudices, and is now the same
quintessence of prejudices as were her bygone grandmothers:
alchemy, metaphysics and philosophy. As between European
scholars and the Chinese who have no sciences at all the difference
is merely trifling, a matter only of externals. The Chinese had no
scientific knowledge, but what have they lost by that?"
"Flies haven't any scientific knowledge either," I say; "but what
does that prove?"
"It's no use getting angry, Nicolai Stiepanich. I say this only
between ourselves. I'm more cautious than you think. I shan't
proclaim it from the housetops, God forbid! The masses still keep
alive a prejudice that science and art are superior to agriculture and
commerce, superior to crafts. Our persuasion makes a living from
this prejudice. It's not for you and me to destroy it. God forbid!"
During patience the younger generation also comes in for it.
"Our public is degenerate nowadays," Mikhail Fiodorovich sighs. "I
don't speak of ideals and such things, I only ask that they should be
able to work and think decently. 'Sadly I look at the men of our
time'—it's quite true in this connection."
"Yes, they're frightfully degenerate," Katy agrees. "Tell me, had
you one single eminent person under you during the last five or ten
years?"
"I don't know how it is with the other professors,—but somehow I
don't recollect that it ever happened to me."
"In my lifetime I've seen a great many of your students and young
scholars, a great many actors.... What happened? I never once had
the luck to meet, not a hero or a man of talent, but an ordinarily
interesting person. Everything's dull and incapable, swollen and
pretentious...."
All these conversations about degeneracy give me always the
impression that I have unwittingly overheard an unpleasant
conversation about my daughter. I feel offended because the
indictments are made wholesale and are based upon such ancient
hackneyed commonplaces and such penny-dreadful notions as
degeneracy, lack of ideals, or comparisons with the glorious past.
Any indictment, even if it's made in a company of ladies, should be
formulated with all possible precision; otherwise it isn't an
indictment, but an empty calumny, unworthy of decent people.
I am an old man, and have served for the last thirty years; but I
don't see any sign either of degeneracy or the lack of ideals. I don't
find it any worse now than before. My porter, Nicolas, whose
experience in this case has its value, says that students nowadays
are neither better nor worse than their predecessors.
If I were asked what was the thing I did not like about my present
pupils, I wouldn't say offhand or answer at length, but with a certain
precision. I know their defects and there's no need for me to take
refuge in a mist of commonplaces. I don't like the way they smoke,
and drink spirits, and marry late; or the way they are careless and
indifferent to the point of allowing students to go hungry in their
midst, and not paying their debts into "The Students' Aid Society."
They are ignorant of modern languages and express themselves
incorrectly in Russian. Only yesterday my colleague, the hygienist,
complained to me that he had to lecture twice as often because of
their incompetent knowledge of physics and their complete
ignorance of meteorology. They are readily influenced by the most
modern writers, and some of those not the best, but they are
absolutely indifferent to classics like Shakespeare, Marcus Aurelius,
Epictetus and Pascal; and their worldly unpracticality shows itself
mostly in their inability to distinguish between great and small. They
solve all difficult questions which have a more or less social
character (emigration, for instance) by getting up subscriptions, but
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