Python Debugging for AI, Machine Learning, and Cloud Computing: A Pattern-Oriented Approach 1st Edition Dmitry Vostokov instant download
Python Debugging for AI, Machine Learning, and Cloud Computing: A Pattern-Oriented Approach 1st Edition Dmitry Vostokov instant download
or textbooks at https://ebookmass.com
_____ Follow the link below to get your download now _____
https://ebookmass.com/product/python-debugging-for-ai-
machine-learning-and-cloud-computing-a-pattern-oriented-
approach-1st-edition-dmitry-vostokov/
https://ebookmass.com/product/foundations-of-arm64-linux-debugging-
disassembling-and-reversing-dmitry-vostokov/
Artificial Intelligence and Machine Learning for EDGE
Computing 1st Edition Rajiv Pandey
https://ebookmass.com/product/artificial-intelligence-and-machine-
learning-for-edge-computing-1st-edition-rajiv-pandey/
https://ebookmass.com/product/productionizing-ai-how-to-deliver-
ai-b2b-solutions-with-cloud-and-python-1st-edition-barry-walsh/
https://ebookmass.com/product/productionizing-ai-how-to-deliver-
ai-b2b-solutions-with-cloud-and-python-1st-edition-barry-walsh-2/
Machine Learning Guide for Oil and Gas Using Python Hoss
Belyadi
https://ebookmass.com/product/machine-learning-guide-for-oil-and-gas-
using-python-hoss-belyadi/
Python Debugging
for AI, Machine
Learning, and
Cloud Computing
A Pattern-Oriented Approach
—
Dmitry Vostokov
Python Debugging for AI,
Machine Learning, and
Cloud Computing
A Pattern-Oriented Approach
Dmitry Vostokov
Python Debugging for AI, Machine Learning, and Cloud Computing:
A Pattern-Oriented Approach
Dmitry Vostokov
Dalkey, Dublin, Ireland
Introduction������������������������������������������������������������������������������������������������������������xxi
v
Table of Contents
vi
Table of Contents
Module Patterns�������������������������������������������������������������������������������������������������������������������������� 43
Module Collection������������������������������������������������������������������������������������������������������������������ 44
Not My Version���������������������������������������������������������������������������������������������������������������������� 47
Exception Module������������������������������������������������������������������������������������������������������������������ 47
Origin Module������������������������������������������������������������������������������������������������������������������������ 47
Thread Patterns�������������������������������������������������������������������������������������������������������������������������� 47
Spiking Thread����������������������������������������������������������������������������������������������������������������������� 48
Active Thread������������������������������������������������������������������������������������������������������������������������� 48
Blocked Thread���������������������������������������������������������������������������������������������������������������������� 48
Blocking Module�������������������������������������������������������������������������������������������������������������������� 48
Synchronization Patterns������������������������������������������������������������������������������������������������������������ 48
Wait Chain����������������������������������������������������������������������������������������������������������������������������� 49
Deadlock�������������������������������������������������������������������������������������������������������������������������������� 49
Livelock��������������������������������������������������������������������������������������������������������������������������������� 49
Memory Consumption Patterns�������������������������������������������������������������������������������������������������� 49
Memory Leak������������������������������������������������������������������������������������������������������������������������� 49
Handle Leak��������������������������������������������������������������������������������������������������������������������������� 49
Case Study���������������������������������������������������������������������������������������������������������������������������������� 50
Summary������������������������������������������������������������������������������������������������������������������������������������ 64
vii
Table of Contents
Case Study���������������������������������������������������������������������������������������������������������������������������������� 81
Elementary Diagnostics Patterns������������������������������������������������������������������������������������������ 81
Debugging Analysis Patterns������������������������������������������������������������������������������������������������� 81
Debugging Implementation Patterns������������������������������������������������������������������������������������� 82
Summary������������������������������������������������������������������������������������������������������������������������������������ 89
viii
Table of Contents
Data������������������������������������������������������������������������������������������������������������������������������������� 132
Interaction��������������������������������������������������������������������������������������������������������������������������� 132
The How? Category������������������������������������������������������������������������������������������������������������������� 132
Software Narrative�������������������������������������������������������������������������������������������������������������� 132
Software State��������������������������������������������������������������������������������������������������������������������� 132
Summary���������������������������������������������������������������������������������������������������������������������������������� 133
ix
Table of Contents
x
Table of Contents
xi
Table of Contents
xii
Table of Contents
xiii
Table of Contents
Chapter 15: What AI and Machine Learning Can Do for Python Debugging��������� 213
Automated Error Detection������������������������������������������������������������������������������������������������������� 213
Intelligent Code Fix Suggestions����������������������������������������������������������������������������������������������� 213
Interaction Through Natural Language Queries������������������������������������������������������������������������ 214
Visual Debugging Insights��������������������������������������������������������������������������������������������������������� 214
Diagnostics and Anomaly Detection������������������������������������������������������������������������������������������ 214
Augmenting Code Reviews������������������������������������������������������������������������������������������������������� 215
Historical Information Analysis and Prognostics����������������������������������������������������������������������� 215
Adaptive Learning and Personalized Debugging Experience���������������������������������������������������� 216
Test Suite Integration and Optimization������������������������������������������������������������������������������������ 216
Enhanced Documentation and Resource Suggestions������������������������������������������������������������� 216
Problem Modeling��������������������������������������������������������������������������������������������������������������������� 217
Generative Debugging Strategy������������������������������������������������������������������������������������������������ 217
Help with In Papyro Debugging������������������������������������������������������������������������������������������������� 217
Summary���������������������������������������������������������������������������������������������������������������������������������� 218
xiv
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 225
xv
About the Author
Dmitry Vostokov is an internationally recognized expert,
speaker, educator, scientist, inventor, and author. He founded
the pattern-oriented software diagnostics, forensics, and
prognostics discipline (Systematic Software Diagnostics)
and Software Diagnostics Institute (DA+TA: DumpAnalysis.
org + TraceAnalysis.org). Vostokov has also authored
multiple books on software diagnostics, anomaly detection
and analysis, software, and memory forensics, root cause
analysis and problem-solving, memory dump analysis,
debugging, software trace and log analysis, reverse engineering, and malware analysis.
He has over thirty years of experience in software architecture, design, development,
and maintenance in various industries, including leadership, technical, and people
management roles. In his spare time, he presents multiple topics on Debugging.TV and
explores software narratology and its further development as narratology of things and
diagnostics of things (DoT), software pathology, and quantum software diagnostics.
His current interest areas are theoretical software diagnostics and its mathematical
and computer science foundations, application of formal logic, artificial intelligence,
machine learning, and data mining to diagnostics and anomaly detection, software
diagnostics engineering and diagnostics-driven development, diagnostics workflow,
and interaction. Recent interest areas also include cloud native computing, security,
automation, functional programming, applications of category theory to software
development and big data, and artificial intelligence diagnostics.
xvii
About the Technical Reviewer
Krishnendu Dasgupta is currently the Head of Machine
Learning at Mondosano GmbH, leading data science
initiatives focused on clinical trial recommendations and
advanced patient health profiling through disease and drug
data. Prior to this role, he co-founded DOCONVID AI, a
startup that leveraged applied AI and medical imaging to
detect lung abnormalities and neurological disorders.
With a strong background in computer science
engineering, Krishnendu has more than a decade of
experience in developing solutions and platforms using applied machine learning. His
professional trajectory includes key positions at prestigious organizations such as NTT
DATA, PwC, and Thoucentric.
Krishnendu’s primary research interests include applied AI for graph machine
learning, medical imaging, and decentralized privacy-preserving machine learning in
healthcare. He also had the opportunity to participate in the esteemed Entrepreneurship
and Innovation Bootcamp at the Massachusetts Institute of Technology, cohort of
2018 batch.
Beyond his professional endeavors, Krishnendu actively dedicates his time to
research, collaborating with various research NGOs and universities worldwide. His
focus is on applied AI and ML.
xix
Introduction
Python is the dominant language used in AI and machine learning with data and
pipelines in cloud environments. Besides debugging Python code in popular IDEs,
notebooks, and command-line debuggers, this book also includes coverage of native
OS interfacing (Windows and Linux) necessary to understand, diagnose, and debug
complex software issues.
The book begins with an introduction to pattern-oriented software diagnostics and
debugging processes that, before doing Python debugging, diagnose problems in various
software artifacts such as memory dumps, traces, and logs. Next, it teaches various
debugging patterns using Python case studies that model abnormal software behavior.
Further, it covers Python debugging specifics in cloud native and machine learning
environments. It concludes with how recent advances in AI/ML can help in Python
debugging. The book also goes deep for case studies when there are environmental
problems, crashes, hangs, resource spikes, leaks, and performance degradation. It
includes tracing and logging besides memory dumps and their analysis using native
WinDbg and GDB debuggers.
This book is for those who wish to understand how Python debugging is and can
be used to develop robust and reliable AI, machine learning, and cloud computing
software. It uses a novel pattern-oriented approach to diagnosing and debugging
abnormal software structure and behavior. Software developers, AI/ML engineers,
researchers, data engineers, MLOps, DevOps, and anyone who uses Python will benefit
from this book.
Source Code: All source code used in this book can be downloaded from g ithub.
com/Apress/Python-Debugging-for-AI-Machine-Learning-and-Cloud-Computing.
xxi
CHAPTER 1
Fundamental Vocabulary
Debugging complex software issues in machine learning and cloud computing
environments requires not only the knowledge of the Python language and its interpreter
(or compiler), plus standard and external libraries, but also necessary and relevant
execution environment and operating system internals. In this chapter, you will review
some necessary fundamentals from software diagnostics and debugging languages to
have the same base level of understanding for the following chapters. In this book, I
assume that you are familiar with the Python language and its runtime environment.
Process
A Python script is interpreted by compiling it into bytecode and then executing it, or it
can even be precompiled into an application program. In both cases, this interpreter file
or the compiled application is an executable program (in Windows, it may have a .exe
extension) that references some operating system libraries (.dll in Windows and .so in
Linux). This application can be loaded into computer memory several times; each time,
a separate process is created with its own resources and unique process ID (PID, also
TGID), as shown in Figure 1-1. The process may also have a parent process that created
it, with a parent process ID (PPID).
1
© Dmitry Vostokov 2024
D. Vostokov, Python Debugging for AI, Machine Learning, and Cloud Computing,
https://doi.org/10.1007/978-1-4842-9745-2_1
Chapter 1 Fundamental Vocabulary
To illustrate, I executed the code in Listing 1-1 on both Windows and Linux twice.
import time
def main():
foo()
def foo():
bar()
def bar():
while True:
time.sleep(1)
if __name__ == "__main__":
main()
2
Chapter 1 Fundamental Vocabulary
On Linux, you can also see two processes when you execute the same script in two
separate terminals:
~/Chapter1$ ps -a
PID TTY TIME CMD
17 pts/0 00:00:00 mc
60 pts/2 00:00:00 python3
61 pts/1 00:00:00 python3
80 pts/3 00:00:00 ps
3
Chapter 1 Fundamental Vocabulary
Thread
From an operating system perspective, a process is just a memory container for a
Python interpreter, its code, and data. But the interpreter code needs to be executed,
for example, to interpret the Python bytecode. This unit of execution is called a thread.
A process may have several such units of execution (several threads, the so-called
multithreaded application). Each thread has its own unique thread ID (TID, also LWP
or SPID), as shown in Figure 1-3. For example, one thread may process user interface
events and others may do complex calculations in response to UI requests, thus making
the UI responsive. On Windows, thread IDs are usually different from process IDs, but
in Linux, the thread ID of the main thread is the same as the process ID for a single-
threaded process.
4
Chapter 1 Fundamental Vocabulary
import time
import threading
def thread_func():
foo()
def main():
t1 = threading.Thread(target=thread_func)
t1.start()
t2 = threading.Thread(target=thread_func)
t2.start()
t1.join()
t2.join()
def foo():
bar()
def bar():
while True:
time.sleep(1)
if __name__ == "__main__":
main()
Figure 1-4 shows that in Windows, you can see 11 threads at the beginning (this
number later changes to 7 and then to 5). You see that the number of threads may be
greater than expected.
5
Chapter 1 Fundamental Vocabulary
~/Chapter1$ ps -aT
PID SPID TTY TIME CMD
17 17 pts/0 00:00:00 mc
45 45 pts/2 00:00:00 python3
45 46 pts/2 00:00:00 python3
45 47 pts/2 00:00:00 python3
54 54 pts/1 00:00:00 ps
6
Chapter 1 Fundamental Vocabulary
Listing 1-3 shows managed stack trace. Listing 1-4 shows the corresponding unmanaged
Linux stack trace with debugging symbols (the most recent call first). Listing 1-5 shows
the corresponding unmanaged Windows stack trace without debugging symbols (the
most recent call first).
Listing 1-3. Managed Stack Trace from the Execution of the Python Script from
Listing 1-1
Listing 1-4. Unmanaged Linux Backtrace from the Execution of the Python
Script from Listing 1-1 with Debugging Symbols
7
Chapter 1 Fundamental Vocabulary
8
Chapter 1 Fundamental Vocabulary
9
Chapter 1 Fundamental Vocabulary
10
Chapter 1 Fundamental Vocabulary
Listing 1-5. Unmanaged Windows Stack Trace from the Execution of the Python
Script from Listing 1-1 Without Debugging Symbols
00 00000090`7e1ef0a8 00007ff9`8c44fcf9 ntdll!NtWaitForMultipleObjects+
0x14
01 00000090`7e1ef0b0 00007ff9`8c44fbfe KERNELBASE!WaitForMultipleObject
sEx+0xe9
02 00000090`7e1ef390 00007ff8`ef943986 KERNELBASE!WaitForMultipleObject
s+0xe
03 00000090`7e1ef3d0 00007ff8`ef94383d python311!PyTraceBack_Print_
Indented+0x35a
04 00000090`7e1ef430 00007ff8`ef81a6b2 python311!PyTraceBack_Print_
Indented+0x211
05 00000090`7e1ef460 00007ff8`ef82fa77 python311!PyEval_
EvalFrameDefault+0x8f2
06 00000090`7e1ef670 00007ff8`ef82f137 python311!PyMapping_Check+0x1eb
07 00000090`7e1ef6b0 00007ff8`ef82d80a python311!PyEval_EvalCode+0x97
11
Chapter 1 Fundamental Vocabulary
08 00000090`7e1ef730 00007ff8`ef82d786 python311!PyMapping_Items+0x11e
09 00000090`7e1ef760 00007ff8`ef97a17e python311!PyMapping_Items+0x9a
0a 00000090`7e1ef7a0 00007ff8`ef7e33a5 python311!PyThread_tss_is_
created+0x53ce
0b 00000090`7e1ef810 00007ff8`ef8da620 python311!PyRun_
SimpleFileObject+0x11d
0c 00000090`7e1ef880 00007ff8`ef8daaef python311!PyRun_
AnyFileObject+0x54
0d 00000090`7e1ef8b0 00007ff8`ef8dab5f python311!Py_
MakePendingCalls+0x38f
0e 00000090`7e1ef980 00007ff8`ef8db964 python311!Py_
MakePendingCalls+0x3ff
0f 00000090`7e1ef9b0 00007ff8`ef8db7f5 python311!Py_RunMain+0x184
10 00000090`7e1efa20 00007ff8`ef8260d9 python311!Py_RunMain+0x15
11 00000090`7e1efa50 00007ff6`aefe1230 python311!Py_Main+0x25
12 00000090`7e1efaa0 00007ff9`8e1c26ad python+0x1230
13 00000090`7e1efae0 00007ff9`8ef6a9f8 KERNEL32!BaseThreadInitThunk+0x
1d
14 00000090`7e1efb10 00000000`00000000 ntdll!RtlUserThreadStart+0x28
S
ymbol Files
Symbol files allow a debugger to map memory addresses to symbolic information such
as function and variable names. For example, if you download and apply symbol files to
the Windows example above, you get a much better and more accurate stack trace, as
shown in Listing 1-6.
12
Chapter 1 Fundamental Vocabulary
Listing 1-6. Unmanaged Windows Stack Trace from the Execution of the Python
Script from Listing 1-1 with Debugging Symbols
00 00000090`7e1ef0a8 00007ff9`8c44fcf9 ntdll!NtWaitForMultipleObjects+
0x14
01 00000090`7e1ef0b0 00007ff9`8c44fbfe KERNELBASE!WaitForMultipleObject
sEx+0xe9
02 00000090`7e1ef390 00007ff8`ef943986 KERNELBASE!WaitForMultipleObject
s+0xe
03 00000090`7e1ef3d0 00007ff8`ef94383d python311!pysleep+0x11a
04 00000090`7e1ef430 00007ff8`ef81a6b2 python311!time_sleep+0x2d
05 00000090`7e1ef460 00007ff8`ef82fa77 python311!_PyEval_
EvalFrameDefault+0x8f2
06 (Inline Function) --------`-------- python311!_PyEval_EvalFrame+0x1e
07 00000090`7e1ef670 00007ff8`ef82f137 python311!_PyEval_Vector+0x77
08 00000090`7e1ef6b0 00007ff8`ef82d80a python311!PyEval_EvalCode+0x97
09 00000090`7e1ef730 00007ff8`ef82d786 python311!run_eval_code_obj+0x52
0a 00000090`7e1ef760 00007ff8`ef97a17e python311!run_mod+0x72
0b 00000090`7e1ef7a0 00007ff8`ef7e33a5 python311!pyrun_file+0x196b66
0c 00000090`7e1ef810 00007ff8`ef8da620 python311!_PyRun_
SimpleFileObject+0x11d
0d 00000090`7e1ef880 00007ff8`ef8daaef python311!_PyRun_
AnyFileObject+0x54
0e 00000090`7e1ef8b0 00007ff8`ef8dab5f python311!pymain_run_file_
obj+0x10b
0f 00000090`7e1ef980 00007ff8`ef8db964 python311!pymain_run_file+0x63
10 00000090`7e1ef9b0 00007ff8`ef8db7f5 python311!pymain_run_
python+0x140
11 00000090`7e1efa20 00007ff8`ef8260d9 python311!Py_RunMain+0x15
12 00000090`7e1efa50 00007ff6`aefe1230 python311!Py_Main+0x25
13 (Inline Function) --------`-------- python!invoke_main+0x22
14 00000090`7e1efaa0 00007ff9`8e1c26ad python!__scrt_common_main_
seh+0x10c
15 00000090`7e1efae0
00007ff9`8ef6a9f8 KERNEL32!BaseThreadInitThunk+0x1d
16 00000090`7e1efb10 00000000`00000000 ntdll!RtlUserThreadStart+0x28
13
Chapter 1 Fundamental Vocabulary
M
odule
Like the distinction between managed and unmanaged stack traces, there is a difference
between Python modules (which may correspond to files in traceback) and native
modules such as DLLs in Windows and .so files in Linux, which are loaded into memory
when you execute the Python compiler/interpreter. For example, the following shared
libraries are loaded in Linux for the simple multithreaded example from Listing 1-2:
~/Chapter1$ pmap 60
60: python3 process.py
0000000000400000 132K r---- python3.7
0000000000421000 2256K r-x-- python3.7
0000000000655000 1712K r---- python3.7
0000000000801000 4K r---- python3.7
0000000000802000 664K rw--- python3.7
00000000008a8000 140K rw--- [ anon ]
0000000001fff000 660K rw--- [ anon ]
00007f6bc7f69000 1684K rw--- [ anon ]
00007f6bc810e000 2964K r---- locale-archive
00007f6bc83f3000 12K rw--- [ anon ]
00007f6bc83f6000 136K r---- libc-2.28.so
00007f6bc8418000 1308K r-x-- libc-2.28.so
00007f6bc855f000 304K r---- libc-2.28.so
00007f6bc85ab000 4K ----- libc-2.28.so
00007f6bc85ac000 16K r---- libc-2.28.so
00007f6bc85b0000 8K rw--- libc-2.28.so
00007f6bc85b2000 16K rw--- [ anon ]
00007f6bc85b6000 52K r---- libm-2.28.so
00007f6bc85c3000 636K r-x-- libm-2.28.so
00007f6bc8662000 852K r---- libm-2.28.so
00007f6bc8737000 4K r---- libm-2.28.so
00007f6bc8738000 4K rw--- libm-2.28.so
00007f6bc8739000 8K rw--- [ anon ]
00007f6bc873b000 12K r---- libz.so.1.2.11
00007f6bc873e000 72K r-x-- libz.so.1.2.11
00007f6bc8750000 24K r---- libz.so.1.2.11
14
Chapter 1 Fundamental Vocabulary
15
Chapter 1 Fundamental Vocabulary
00007ff6`aefe0000 00007ff6`aeffa000 python python.exe
00007ff8`ef7e0000 00007ff8`efdad000 python311 python311.dll
00007ff9`62950000 00007ff9`6296b000 VCRUNTIME140 VCRUNTIME140.dll
00007ff9`7f1e0000 00007ff9`7f1ea000 VERSION VERSION.dll
00007ff9`8bce0000 00007ff9`8bd08000 bcrypt bcrypt.dll
00007ff9`8c3f0000 00007ff9`8c793000 KERNELBASE KERNELBASE.dll
00007ff9`8c840000 00007ff9`8c951000 ucrtbase ucrtbase.dll
00007ff9`8c960000 00007ff9`8c9db000 bcryptprimitives bcryptprimitives.dll
00007ff9`8d150000 00007ff9`8d1c1000 WS2_32 WS2_32.dll
00007ff9`8d1d0000 00007ff9`8d2e7000 RPCRT4 RPCRT4.dll
00007ff9`8dd50000 00007ff9`8ddf7000 msvcrt msvcrt.dll
00007ff9`8ded0000 00007ff9`8df7e000 ADVAPI32 ADVAPI32.dll
00007ff9`8e1b0000 00007ff9`8e272000 KERNEL32 KERNEL32.DLL
00007ff9`8e280000 00007ff9`8e324000 sechost sechost.dll
00007ff9`8ef10000 00007ff9`8f124000 ntdll ntdll.dll
M
emory Dump
A process memory can be saved in a memory dump file.
16
Chapter 1 Fundamental Vocabulary
These memory dumps are also called core dumps in Linux. It is also possible to get a
kernel memory dump and a dump of physical memory (also called a complete memory
dump in Windows). Figure 1-5 shows different memory dump types.
Crash
To fail suddenly. “Has the system just crashed?” “Something crashed the
OS!” Also used transitively to indicate the cause of the crash (usually a
person or a program, or both). “Those idiots playing SPACEWAR crashed
the system.”
Eric S. Raymond, The New Hacker’s Dictionary, Third Edition.
17
Chapter 1 Fundamental Vocabulary
When something illegal happens inside a process thread, such as when memory
outside its available range is accessed or you write to read-only memory, the operating
system reports the error and terminates the process. It may also save the process
memory into a memory dump file. The process then disappears from the list of available
processes.
Hang
1. To wait for an event that will never occur. “The system is hanging because
it can’t read from the crashed drive.”
2. To wait for an event to occur. “The program displays a menu and then
hangs until you type a character.”
Threads interact with other threads, including other processes’ threads. These
interactions can be viewed as sending messages and waiting for the responses. Some
processes may be critical because their threads process messages from many other
threads from other processes. If threads from such a critical process stop sending
responses, all other waiting threads are blocked. A deadlock is when two threads are
waiting for each other. When hanging, the process continues to be present in the list
of available processes. There are also processes (critical components) that, when their
threads hang, block threads from many other processes (noncritical components).
Figure 1-6 depicts such components and their interaction abstracted via messages in
the normal scenario, and Figure 1-7 shows the abnormal scenario when noncritical
components are blocked and waiting for responses because the critical components are
deadlocked.
18
Chapter 1 Fundamental Vocabulary
Figure 1-6. Request and response interaction between critical and noncritical
system components
19
Chapter 1 Fundamental Vocabulary
Summary
In this chapter, you learned the fundamental vocabulary you will use in subsequent
chapters. The next chapter introduces a pattern-oriented debugging approach.
20
CHAPTER 2
Pattern-Oriented
Debugging
This chapter introduces the pattern-oriented debugging process approach and the
pattern languages you will use in subsequent chapters.
1
Mehdi Amoui et al., “A Pattern Language for Software Debugging,” International Journal
of Computer Science, vol. 1, no. 3, pp. 218-224, 2006. https://stargroup.uwaterloo.
ca/~mamouika/papers/pdf/IJCS.2006.pdf
2
Eric Allen, Bug Patterns in Java, 2002 (ISBN-13: 978-1590590614)
3
https://en.wikipedia.org/wiki/Debugging_pattern
4
Linda Rising, The Pattern Almanac 2000, p. 154 (ISBN-13: 978-0201615678)
5
Robert Charles Metzger, Debugging by Thinking: A Multidisciplinary Approach, 2003 (ISBN-13:
978-1555583071)
21
© Dmitry Vostokov 2024
D. Vostokov, Python Debugging for AI, Machine Learning, and Cloud Computing,
https://doi.org/10.1007/978-1-4842-9745-2_2
Chapter 2 Pattern-Oriented Debugging
Development Process
Let’s first look at the traditional software development process stages. Figure 2-1
abstracts them from several development processes, including waterfall and
iterative ones.
6
Alfred A. Hough and Janice E. Cuny, “Initial experiences with a pattern-oriented parallel
debugger.” PADD ‘88: Proceedings of the 1988 ACM SIGPLAN and SIGOPS workshop on
Parallel and distributed debugging November 1988 Pages 195–205
https://doi.org/10.1145/68210.69234
7
Dmitry Vostokov, Pattern-Oriented Debugging Process, in Theoretical Software Diagnostics:
Collected Articles, Third Edition, 2020 (ISBN-13: 978-1912636334), pp. 197-199
8
Ibid., “Analysis, Architectural, Design, Implementation and Usage Debugging Patterns,” p. 129
9
Accelerated Windows Debugging 4D, Third Edition, 2022 (ISBN-13: 978-1912636532)
10
Dmitry Vostokov, Introduction to Pattern-Driven Software Problem Solving, 2011 (ISBN-13:
978-1908043177)
22
Chapter 2 Pattern-Oriented Debugging
Development Patterns
For each stage, there exists some pattern language such as a vocabulary of solutions to
common recurrent identifiable problems with grammar, semantics, and pragmatics.
Figure 2-2 also includes software usage and presentation patterns for human-computer
interaction. In this book, I assume you have familiarity with such pattern languages
(some references are provided below).
23
Chapter 2 Pattern-Oriented Debugging
24
Chapter 2 Pattern-Oriented Debugging
11
Jason McC. Smith, Elemental Design Patterns, 2012 (ISBN-13: 978-0321711922)
25
Chapter 2 Pattern-Oriented Debugging
12
Dmitry Vostokov, Encyclopedia of Crash Dump Analysis Patterns: Detecting Abnormal Software
Structure and Behavior in Computer Memory, Third Edition, 2020 (ISBN-13: 978-1912636303)
13
Dmitry Vostokov, Fundamentals of Trace and Log Analysis: A Pattern-Oriented Approach to
Monitoring, Diagnostics, and Debugging, Apress, 2023 (ISBN-13: 978-1484298954) and Dmitry
Vostokov, Trace, Log, Text, Narrative, Data: An Analysis Pattern Reference for Information Mining,
Diagnostics, Anomaly Detection, Fifth Edition, 2023 (ISBN-13: 978-1912636587)
14
Frank Buschmann et al., Pattern-Oriented Software Architecture: A System of Patterns, 1996
(ISBN-13: 978-0471958697)
15
Erich Gamma et al., Design Patterns: Elements of Reusable Object-Oriented Software, 1995
(ISBN-13: 978-0201633610)
26
Chapter 2 Pattern-Oriented Debugging
16
Jan Borchers, A Pattern Approach to Interaction Design, 2001 (ISBN-13: 978-0471498285)
17
Kristian Rother, Pro Python Best Practices: Debugging, Testing and Maintenance, 2017
(ISBN-13: 978-1484222409) and R. L. Zimmerman, Python Debugging Handbook, 2020 (ISBN-13:
979-8610761725)
18
Andreas Zeller, The Debugging Book: Tools and Techniques for Automated Software Debugging,
www.debuggingbook.org/ (uses Python for examples)
27
Other documents randomly have
different content
lectured for three years on the Practice of Physic, and then he and
Cullen agreed to give alternate lectures on the Theory and Practice
of Medicine. The university possessing three such able teachers as
Gregory, Cullen and Black, grew more and more prosperous. It is
impossible to go over the records of these years without admiration
for John Gregory, who, amidst all the strife that waged around him
and around Cullen, has not left a record of any bitterness. That he
must have felt these annoyances is obvious, but his worries were
only Edinburgh worries, and outside he knew that both he and
Cullen were appreciated and valued for their individual work. On his
appointment to the Edinburgh chair he had resigned his King’s
College professorship.
When Dr Gregory came to Edinburgh, he came with his six children.
Elizabeth, his youngest little girl, died in 1771. His eldest son James
was studying medicine, the other boys were at work, and Dorothea
and Anna Margaretta, his elder daughters, were growing into more
charming companions for him with every day that passed. They
were tall, willowy girls, promising great beauty, and full of
sweetness. Dorothea, or Dolly as she was called, was a god-
daughter of Mrs Montague’s, and when that lady came to stay with
Dr Gregory, she was absolutely fascinated by her godchild. Her visit
was a great pleasure to the Gregorys, to whom she was ever her
most charming self.
Edinburgh society did not take kindly to her, if we are to believe Dr
Carlyle, and in fact he is rather bitter upon the subject, calls her ‘a
faded beauty,’ ‘a candidate for glory,’ and says she might have been
admired by the first order of minds had she not been ‘greedy of
more praise than she was entitled to.’ Even he, however,
acknowledged her a wit, a critic, an author of some fame,
possessing some parts and knowledge, which is praise to a certain
point, though not to the point which Mrs Montague would have
desired! ‘Old Edinburgh was not a climate for the success of
impostures,’ writes the minister of Inveresk, and then to support his
judgment with a little legal weight, he added, ‘Lord Kames, who was
at first catched with her Parnassian coquetry, said at last that he
thought she had as much learning as a well-educated college lad
here of sixteen.’ Alas, poor Mrs Montague! and then, too, Dr Carlyle
has unwittingly pointed out the rock on which she struck—‘she
despised the women’—and by such obvious silliness did she not
evoke her fate? Gray the poet was also a visitor at the Gregorys’ and
Gregory was asked to meet anyone of interest who came to the
town. With Smollett, indeed, who lived in St John Street for a winter,
he could have little real friendship, for the novelist had put Lord
Lyttleton into Roderick Random in anything but a kindly spirit, and
the Gregories were notoriously ‘Love me, love my dog’ people. He
lived on terms of close intimacy with Dr Robertson, Dr Blair, David
Hume, John Home, Lord Kames, Lord Monboddo, and Lord
Woodhouselee. He was a member of the Poker Club, though he went
there very seldom, because of the way he was laughed at when he
uttered his favourite doctrine of the superiority of women over men.
This at least was the gossip of the time, but there is just a possibility
that he thought his own company more entertaining than the
constant attendance at the Poker from three in the afternoon till
eight at night, and though no one knew it, he was busy drawing up
a book of advices for his daughters against the time, which he felt
could not be very far off, when he would no longer be with them.
‘My Dear Girls—You had the misfortune to be deprived of your
Mother at a time of life when you were insensible of your loss, and
could receive little benefit either from her instruction or her example.
Before this comes to your hands, you will likewise have lost your
Father. I have had many melancholy reflections on the forlorn and
helpless situation you must be in if it should please God to remove
me from you before you arrive at that period of life, when you will
be able to think and act for yourselves.... I have been supported
under the gloom ... by a reliance on the Goodness of that Providence
which has hitherto preserved you, and given me the most pleasing
prospect of the goodness of your dispositions, and by the secret
hope that your Mother’s virtues will entail a blessing on her children.’
This was the spirit in which the book was written, and though it is a
type of book which has entirely passed out of fashion, it is
interesting to read it and remember that in the days of our great-
grandmothers it had its place on every girl’s table.
Dr Gregory had a very observant way of watching girls, he knew life,
and his advice was shrewd and tender. In the chapter on Conduct
and Behaviour there are many quaint observations as to what gifts
are attractive in a girl.
‘Wit,’ he says, ‘is the most dangerous talent you can possess, it must
be guarded with great discretion and good nature, otherwise it will
create you many enemies’.... ‘Be even cautious in displaying your
good sense. It will be thought you assume a superiority over the rest
of the company—But if you happen to have any learning, keep it a
profound secret, especially from the men’.... ‘Beware of detraction,
especially when your own sex are concerned. You are generally
accused of being particularly addicted to this vice—I think unjustly—
Men are fully as guilty of it when their interests interfere. As your
interests more frequently clash, and as your feelings are quicker
than ours, your temptations to it are more frequent. For this reason,
be particularly tender of the reputation of your own sex, especially
when they happen to rival you in our regards.’ Later on, there is a
pathetic feeling of how little he can foretell his daughters’ tastes. ‘I
do not want to make you anything, I want to know what Nature has
made you, and to perfect you on her plan.’
A Father’s Legacy to his Daughter was intended only for his own
girls, and was not published till after Dr Gregory’s death. During his
time in Edinburgh he brought out besides his Comparative View,
Lectures on the Duties and Qualifications of a Physician, which were
his introductory lectures, and Elements of the Practice of Physic, a
first volume of a text-book for his students which he did not live to
complete. He thought medicine required a more comprehensive
mind than any other profession, and often brought much besides
mere technical knowledge into his lectures. As a speaker he was
simple, natural and vigorous. He lectured only from notes, ‘in a style
happily attempered,’ said one of his contemporaries, ‘between the
formality of studied composition, and the ease of conversation.’ On
one thing he insisted, that every student should appreciate the
limitations of medicine, for only so could they learn to extend its
borders.
During these years, too, he carried on a constant correspondence
with James Beattie, Professor of Moral Philosophy in Aberdeen, and
a poet. Both Beattie and Thomas Reid, who held the corresponding
chair in Glasgow, were engaged in combating the teaching of David
Hume, which had become very fashionable, and Gregory, though
much attached to David Hume as a man, feared him as a teacher,
and dreaded the growth of that scepticism which marked the time—
a tendency quite as bitterly lamented in England by Samuel Johnson.
‘I am well convinced,’ Gregory wrote to Beattie in a letter dated
Edinburgh, 16th June 1767, ‘that the great deference paid to our
modern heathens has been productive of the worst effects. Young
people are impressed with an idea of their being men of superior
abilities, whose genius has raised them above the vulgar prejudices,
and who have spirit enough to avow openly their contempt of them.
Atheism and Materialism are the present fashion. If one speak with
warmth of an infinitely wise and good Being, who sustains and
directs the frame of nature, or expresses his steady belief of a future
state of existence, he gets hints of his having either a very weak
understanding, or of his being a very great hypocrite.... You are the
best man I know to chastise these people as they deserve, you have
more Philosophy and more wit than will be necessary for the
purpose, though you can never employ any of them in so good a
cause.’
When Beattie’s answer to Hume was in manuscript, he sent it to Dr
Gregory, who read it, and cordially approved of it, but one result of
this was that Gregory had to become a partaker in the acrimony of
Hume’s friends. His advices as to an attractive style were somewhat
curious, ‘You are well aware of the antipathy, which the present race
of readers have against all abstract reasoning, except what is
employed in defence of the fashionable principles; but though they
pretend to admire their metaphysical champions, yet they never
read them, nor if they did, could they understand them. Among Mr
Hume’s numerous disciples, I do not know one who ever read his
Treatise on Human Nature. In order, therefore, to be read, you must
not be satisfied with reasoning with justness and perspicuity; you
must write with pathos, with elegance, with spirit, and endeavour to
warm the imagination and touch the heart of those who are deaf to
the voice of reason. Whatever you write in the way of criticism will
be read, and, if my partiality to you does not deceive me, be
admired. Everything relating to the ‘Belles Lettres’ is read, or
pretended to be read. What has made Lord Kames’ Elements of
Criticism so popular in England, is his numerous illustrations and
quotations from Shakespeare.... This is a good political hint to you in
your capacity of an author.’
Gregory was also consulted about the sketch design of Beattie’s
Poem, The Minstrel, which he admired, and the closing stanza
written by his friend the poet, when he heard of Gregory’s death,
was supposed to be very beautiful poetry. Cowper wrote in one of
his letters to the Rev. William Unwin, ‘If you have not his poem
called The Minstrel, and cannot borrow it, I must beg you to buy it
for me, for though I cannot afford to deal largely in so expensive a
commodity as books, I must afford to purchase at least the poetical
works of Beattie.’
Gregory’s views of his friend’s high gifts then were shared by
Cowper. Gray also held him in high estimation, and Mrs Siddons
spent an afternoon with Beattie, crying because they were so happy
over poetry and music, and some of the poetry must have been his
own. As for Beattie’s lines on Gregory, they are as much calculated
to draw smiles as tears from our eyes.
‘Adieu, ye lays that fancy’s flowers adorn,
The soft amusement of the vacant mind!
He sleeps in dust and all the Muses mourn,
He whom each virtue fired, each grace refined,
Friend, teacher, pattern, darling of mankind!
He sleeps in dust: and how should I pursue
My theme? To heart-consuming grief resigned,
Here on his recent grave I fix my view,
And pour my bitter tears. Ye flowery lays, adieu!
—Old Play.
‘Dear Sir,—I take the first leisure hour I could command, to thank
you for your letter and the copy of verses enclosed in it. As there is
real poetic merit, I mean both fancy and tenderness, and some
happy expressions, in them, I think they well deserve that you
should revise them carefully and polish them to the utmost. This I
am sure you can do if you please, for you have great command both
of expression and of rhymes; and you may judge, from the two last
pieces of Mrs Hunter’s poetry that I gave you, how much correctness
and high polish enhance the value of such compositions. As you
desire it, I shall with great freedom give you my most rigorous
criticisms on your verses. I wish you would give me another edition
of them, much amended, and I will send it to Mrs Hunter, who, I am
sure, will have much pleasure in reading it. Pray give me likewise for
myself, and her too, a copy (as much amended as you please) of the
“Waterfowl on Loch Turit.”
‘The “Wounded Hare” is a pretty good subject, but the measure or
stanza you have chosen for it is not a good one: it does not flow
well; and the rhyme of the fourth line is almost lost by its distance
from the first, and the two interposed, close rhymes. If I were you I
would put it into a different stanza yet.
‘Stanza 1.—The execrations in the first two lines are too strong or
coarse, but they may pass. “Murder-aiming” is a bad compound
epithet and not very intelligible. “Blood-stained” in Stanza III. line 4
has the same fault: Bleeding bosom is infinitely better. You have
accustomed yourself to such epithets and have no notion how stiff
and quaint they appear to others and how incongruous with poetic
fancy and tender sentiments. Suppose Pope had written “Why that
bloodstained bosom gored” how would you have liked it? Form is
neither a poetic nor a dignified nor a plain common word: it is a
mere sportsman’s word: unsuitable to pathetic or serious poetry.
“Mangled” is a coarse word. “Innocent,” in this sense, is a nursery
word; but both may pass.
‘Stanza 4. “Who will now provide that life a mother only can bestow”
will not do at all: it is not grammar—it is not intelligible. Do you
mean “provide for that life which the mother had bestowed and used
to provide for?” There was a ridiculous slip of the pen, “Feeling” (I
suppose) for “Fellow,” in the title of your copy of the verses; but
even “fellow” would be wrong: it is but a colloquial and vulgar word,
unsuitable to your sentiments. “Shot” is improper too. On seeing a
person (or a sportsman) wound a hare: it is needless to add with
what weapon; but if you think otherwise, you should say with a
fowling-piece. Let me see you when you come to town, and I will
shew you some more of Mrs Hunter’s poems.’
Perhaps when Burns submitted his lines, ‘On seeing a wounded hare
limp by me, which a fellow had just shot at,’ he hoped for as kindly a
criticism as Dr Gregory had given to Clarinda’s verses, which the
poet had shown him in December 1787; but if so, he was much
disappointed. ‘Dr Gregory is a good man, but he crucifies me,’ wrote
Burns soon after; and again, ‘I believe in the iron justice of Dr
Gregory; but like the devils I believe and tremble.’ It was a curious
friendship, but friendship it was. There is an English translation of
Cicero, which the physician had given to Burns in Edinburgh in 1787,
and on the fly-leaf of this is written, ‘This book, a present from the
truly worthy and learned Dr Gregory, I shall preserve to my latest
hour as a mark of the gratitude, esteem and veneration I bear the
owner—so help me God.—Robert Burns.’ Clarinda’s desire to make
Gregory’s acquaintance which is surely an indication of how much
her Sylvander admired him, finds utterance in a letter of 1787, ‘Pray
is Dr Gregory pious? I have heard so, I wish I knew him.’
It was at Lord Monboddo’s that Gregory first met Burns. Besides the
queer old judge, who was made a laughing stock for saying that
men originally had tails, there was his charming daughter, the
beautiful Miss Burnet, to whom Gregory is said to have offered his
heart and hand.
One of the stories that Lord Cockburn tells of Gregory is in
connection with Miss Sophia Johnston (generally known in the
Edinburgh of that day as ‘Suphy’) one of the Hilton family; about
whom, because of her curious upbringing, there were many odd
stories. ‘When Suphy’s day was visibly approaching, Dr Gregory
prescribed abstinence from animal food, and recommended “spoon-
meat” unless she wished to die. “Dee, doctor, odd, I’m thinking
they’ve forgotten an auld wife like me up yonder!” However, when
he came back next day, the doctor found her at the spoon-meat,
supping a haggis—she was remembered.’
Gregory lived now, as we know, in St Andrew Square, having left the
old home in the Canongate, but besides this he bought a house
called Canaan Lodge, which was then at a sufficient distance from
Edinburgh to be in the real country. Walking towards this house he
might often be seen of an evening with his all too warlike stick over
his shoulder, possibly the very stick with which he smote his brother
physician Professor Hamilton within the sacred precincts of the
university. The story does not end here, nor even at the Law Courts,
where he was made to pay £100 damages to the infuriated object of
his attack, but with Gregory, who as usual had the last word, and
the last laugh in the matter, and said as he paid his fine, that he
would willingly pay double for another chance.
‘A’ the country, far and near,
Hae heard Macgregor’s fame, lady.
William Gregory was the last of this great academic family to hold a
chair in a Scottish University.
He was the fourth son of Professor James Gregory, and having been
brought up among the traditions of medicine, he turned to the study
of it instinctively, though the necessity laid upon him was by no
means the same as that which had made his forefathers physicians
in spite of themselves. He had not gone far in his medical course
when he decided to be a chemist rather than a doctor. The magic of
Professor Hope’s experiments made at least one convert and as he
sat in the class-room observing the strange effects of chemicals, he
made up his mind that if it were possible he would some day take
the teacher’s place. With rude implements he would spend hours at
home repeating the processes which he had watched in the class,
his mind all alive to the interest of his subject, and his poor body
much neglected. These happy hours in his laboratory were dearly
paid for by the delicacy, which began to show itself about this time.
The noxious fumes of the chemicals acted as a slow poison, and
from this stage of his life he had to struggle with ill health, all his
occupations being interrupted at times by unconquerable pain.
He graduated M.D. in 1828, and then went abroad to study
chemistry in the famous schools of the continent. At Giessen, the
most important of these, he had the good fortune to attract the
attention of the great teacher, whose work had made the university
famous, and from this time forward, Liebig was the friend and
correspondent of William Gregory.
During the years when Gregory was completing his studies abroad,
and teaching successively in Edinburgh, Glasgow, and Dublin, King’s
College, Aberdeen, was going through considerable difficulties in
connection with the post of mediciner. In the days of John Gregory’s
tenure of that office, he had as we already know, made efforts to
improve the medical curriculum there, but without success. A step in
advance was made in 1801, when it was determined that a
candidate for the degree of M.D. must ‘oblidge himself that he is
not, nor will be concerned in the sale of quack medicines of any
description!’ and a further step was taken in 1817 by the authorities
insisting on a satisfactory account of the ‘classical, literary and
scientifical education of the candidate.’
Between 1824 and 1826, an attempt was made by the Chancellor
and Senatus to insist that the mediciner should teach medicine, but
Dr Bannerman, who then held that office, would only consent to
consider the matter for a year, and after that time he let it rest. In
1836, he was advised that if he would neither teach nor appoint a
substitute, a lecturer would be chosen, and paid out of his salary.
This threat, however, was never carried out, and he died in 1838,
and it was to this post of mediciner, made vacant by his death, that
William Gregory was appointed on February 19th, 1839.
Dr William Pulteney Alison, to whom the electors of King’s College
applied for suggestions as to a suitable candidate, had curiously
enough never mentioned the name of his cousin, and it was only
owing to the intervention of Thomas Clark who held the Chair of
Chemistry in Marischal College that Gregory came to apply. After
giving him minute instructions as to the form which his application
must take, he added, ‘Don’t mention me no more than the Devil.’
The name of this friend was therefore kept out of sight, and Gregory
was in due course appointed to the vacant professorship. It was with
great joy that his advent was announced to the professors of King’s
College. Their difficulties in improving the medical course, when the
very mediciner would not teach a class, had been insuperable, but
now they felt a man of influence was coming amongst them, who
would be the means of promoting the interests of their university,
and who would give the benefit of a hereditary power of teaching to
the students, whom they felt sure his great name would attract to
their midst.
While in Aberdeen William Gregory became intensely interested in
the welfare of King’s College, and busied himself in trying to secure
revenue from the government to found new chairs, but in this he
was unsuccessful.
He taught Materia Medica in a house fitted up for a Medical School in
Kingsland Place, and he had a good class, but from the witticisms of
the students as to the effect of their professor’s preparation of
muriate of morphia it is evident that William Gregory’s physical
weakness was growing upon him, and that it was only with the most
strenuous effort that he could get to his class at ten o’clock.
As his power of walking failed him, the professor found much solace
in music, and sweet snatches of melody were carried across his old-
fashioned garden to the ears of passers-by. He played beautifully,
and his wife, who was a niece of Colonel Scott of Gala, added
greatly to the charms of their musical parties. It is said that they
were the first to shock the people of Aberdeen by playing secular
music on Sunday.
To the Aberdonians, however, he gave a more serious cause for
complaint—William Gregory was of a singularly childlike and trustful
disposition, and he was intensely interested in the occult science of
Spiritualism; the result was that he became the patron of a most
undesirable throng of quasi-scientific humbugs, whose presence in
their midst they resented with extreme frankness. There is a
continual atmosphere of table-turning, mesmerism and magnetic
flames in the tales extant about him, and though the narrators are
tender about his memory, they have perforce to take up the attitude
of counsel for the defence.
As a chemist, he undoubtedly came first in Scotland. He invented
processes for the more perfect preparation of hydrochloric acid,
muriate of morphia and oxyde of silver, besides making important
observations on many other chemicals. He had an accurate
command of practical chemistry, a power of condensation and clear
expression, and a just perception of the value of discoveries, which
made his writings unsurpassed for the use of students.
In 1844 Dr William Gregory realised the dream of his youth. After a
sharp contest with Dr Lyon Playfair, he was appointed to succeed
Professor Hope in his chair in the University of Edinburgh. ‘The chair
was given to him,’ says Sir Alexander Grant, ‘under a new title, for
the Town Council now judiciously omitted “Medicine” from its
province, and elected Dr Gregory to be Professor of Chemistry.’
His health was much impaired, so much so, that people even went
the length of saying that he was physically unfit for his new position,
and it is at any rate true that his finest teaching was given to his
students in Aberdeen. He was an able teacher, if at times erratic and
absent-minded. His class was always kept wide awake, for with what
alarms would not the professor bring back the straying imaginations
of his audience! ‘Gentlemen,’ he would say, while with his long
awkward fingers he lifted up the tube of some chemical before
them, ‘If this were to fall, not one of you could reach the door alive;’
and then, considering the matter over, he would place the tube
carelessly upon the edge of a plate, while the students near the
doorway filtered through it, and the others, hat in hand, awaited the
longed-for close of the lecture, feeling a fresh tremor with every
approach of Gregory’s loose fingers to the fatal vial.
Good as his teaching was, the books which he wrote while in
Edinburgh were his most valuable contribution to the Science of
Chemistry. In the preface to the Outlines of Chemistry, which was
published in 1845, he sketched the divisions which he intended to
make in his subject for the fuller elucidation of the facts, and, had
his health permitted him to carry out his plan, ‘the instruction from
his class would probably have been more complete than from any
other scientific chair in Europe.’ At the request of Liebig, he
translated several of his more important books into English, and in
the preface to the Familiar Letters on Chemistry, Liebig writes, ‘From
his intimate familiarity with chemical science, and especially with the
physiological subjects here treated, I am confident that the task
could not have been entrusted to better hands than those of my
friend Dr Gregory.’ Their friendship lasted throughout life, and only a
few days before Professor Gregory’s death, he was propped up in his
bed to write a pamphlet supporting some new theories of Liebig,
which the German had just communicated to him.
Gregory’s appearance was most noticeable. He was of great
proportions, obese, slouching and loosely hung together. In later
years his body was a great burden to him, but the mind kept the
mastery.
He was, like his father, a keen student of language, and would wile
away many of the weary hours of forced inaction by the study of
foreign tongues. French and German were to him as familiar as
English. With a microscope, too, he did beautiful work, and was in
his day, the greatest authority on the Diatomaceae. The slides which
he made of these microscopic water-plants with their sculptured
valves, were another resource of his declining years. He presented
valuable memoirs on this subject to the Royal Society of Edinburgh,
of which he was a member.
Professor William Gregory died in Edinburgh in April 1858, and was
honoured with a public funeral.
He was succeeded in the university by Dr Lyon Playfair (afterwards
Lord Playfair) who had contested the chair unsuccessfully at the time
of Gregory’s appointment.
William Gregory was survived by an only son, who was called after
his father’s far-famed friend, James Liebig Gregory.
Duncan Farquharson Gregory was considerably younger than his
brother the Professor of Chemistry, and was not at all like him in
personal appearance. His face was a beautiful one, fine, pale,
bearing on it already in this life some of the light and joyousness
that often mark out for especial love those who are to pass quickly
from this earth. His hair, which was thick and curling, fell more about
his brow than is usual, and his eyes like dark lamps illuminated his
features.
When he was hardly more than a baby, his father used fondly to
predict distinction for him. ‘He had pleasure in conversing with him
as with an equal on subjects of History and Geography,’ so Mr Ellis
wrote, and this when the boy was not more than six, for his father
died before he had left the nursery. He was a great inventor of
games for himself, and made an orrery with his busy little hands, on
which he would send the planets spinning round in their orbits.
Till he was nine years old he was taught entirely by his mother, who
was quite as attractive to her children as she had ever been in
society, and for whom Duncan had always a peculiar reverence and
affection. He passed out of her hands into the care of a tutor, and
then was sent to the Edinburgh Academy. From school he went
abroad to Geneva, where his mother and sisters were spending a
winter, and on his return he attended classes at the University of
Edinburgh. In mathematics he made astonishing strides, under
Professor Wallace, and those who saw the master and pupil together
in Cambridge in after days, said that the old man’s pride in his pupil’s
success never diminished.
In 1833 Mr Gregory’s name was entered at Trinity College,
Cambridge, and shortly afterwards he went to reside there. He took
with him a most unusual amount of knowledge on almost all
scientific subjects, in fact many men said that it was the diffuseness
of his learning that prevented him from taking the first place in the
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookmasss.com