Go for Java Programmers: Learn the Google Go Programming Language 1st Edition Barry Feigenbaum all chapter instant download
Go for Java Programmers: Learn the Google Go Programming Language 1st Edition Barry Feigenbaum all chapter instant download
com
https://ebookmeta.com/product/go-for-java-programmers-learn-
the-google-go-programming-language-1st-edition-barry-
feigenbaum/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/learn-concurrent-programming-with-go-
meap-v02-james-cutajar/
ebookmeta.com
https://ebookmeta.com/product/wild-women-do-female-killers-tricksters-
and-crooks-in-singapore-1st-edition-yeo-suan-futt/
ebookmeta.com
Engineering Disease Resistance in Plants using CRISPR-Cas
1st Edition Zulqurnain Khan
https://ebookmeta.com/product/engineering-disease-resistance-in-
plants-using-crispr-cas-1st-edition-zulqurnain-khan/
ebookmeta.com
https://ebookmeta.com/product/sports-cardiology-care-of-the-athletic-
heart-from-the-clinic-to-the-sidelines-david-j-engel/
ebookmeta.com
https://ebookmeta.com/product/mathematics-in-the-21st-
century-2022-edition-scientific-american-editors/
ebookmeta.com
https://ebookmeta.com/product/wireless-interface-technologies-
for-3d-ic-and-module-integration-1st-edition-tadahiro-kuroda/
ebookmeta.com
Go for Java
Programmers
Learn the Google Go Programming
Language
—
Barry Feigenbaum, Ph.D.
Go for Java Programmers
Learn the Google
Go Programming Language
Introduction������������������������������������������������������������������������������������������������������������xix
Assessments�������������������������������������������������������������������������������������������������������xxxv
v
Table of Contents
vi
Table of Contents
Go Command-Line Tools������������������������������������������������������������������������������������������������������������� 61
Tools Bundled in the Go Command���������������������������������������������������������������������������������������� 62
Other Tools����������������������������������������������������������������������������������������������������������������������������� 64
Go Runs Programs Instead of Classes���������������������������������������������������������������������������������������� 64
Go Memory Management������������������������������������������������������������������������������������������������������������ 66
Go Identifiers������������������������������������������������������������������������������������������������������������������������������� 71
Go Scopes����������������������������������������������������������������������������������������������������������������������������������� 73
Go Scopes vs. Go Source Files���������������������������������������������������������������������������������������������� 76
Initializing Go Variables��������������������������������������������������������������������������������������������������������������� 78
Lifetimes of Go Identifiers����������������������������������������������������������������������������������������������������������� 80
Go Module Summary������������������������������������������������������������������������������������������������������������������� 81
Go Assignments and Expressions����������������������������������������������������������������������������������������������� 87
Text Formatting in Go������������������������������������������������������������������������������������������������������������������ 89
Goroutines����������������������������������������������������������������������������������������������������������������������������������� 94
Issues with Concurrency������������������������������������������������������������������������������������������������������� 94
Go Concurrency��������������������������������������������������������������������������������������������������������������������� 97
Goroutines by Example�������������������������������������������������������������������������������������������������������� 100
vii
Table of Contents
viii
Table of Contents
ix
Table of Contents
x
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 575
xi
About the Author
Barry Feigenbaum, Ph.D., has decades of software engineering experience. During his
career, he has worked for major industry-leading companies, such as IBM and Amazon,
and is currently at Dell where he is a Senior Principal Software Engineer. He has worked
on mainframe and midrange servers and many applications for personal computers.
He has developed software products, such as assemblers for multiple hardware
architectures, in many key industry languages such as C/C++/C#, Python, JavaScript,
Java, and now Go. He has extensive experience in the full software development life
cycle. Most recently, he has committed himself to leading teams developing mission-
critical microservices, most often written in Go, that operate in large clustered
environments.
He led the early development of the LAN support inside Microsoft Windows
(he defined the SMB protocol that is the basis for both the CIFS and the SAMBA
technologies). He has served as a software tester, developer, and designer as well as a
development team lead, architect, and manager on multiple occasions. He was a key
contributor as a developer, architect, and manager to several releases of PC-DOS and
OS/2. In these roles, he worked extensively with Microsoft on joint requirements, design,
and implementation.
Dr. Feigenbaum has a Ph.D. in Computer Engineering with a concentration in
object-oriented (OO) software design and other degrees in Electrical Engineering. He
has published multiple articles in technical magazines and juried journals. He has
coauthored several books on IBM PC-DOS. He has spoken at numerous technical
conferences, such as JavaOne. He has served on industry standard bodies. He has taught
multiple college-level courses on data structures, software engineering, and distributed
software as an adjunct professor at several universities. He has over 20 issued US patents.
He is married, has one son, and lives in Austin, TX.
xiii
About the Technical Reviewer
Ronald Petty, M.B.A., M.S., is founder of Minimum
Distance LLC, a management consulting firm based in
San Francisco. He spends his time helping technology-
based startups do the right thing. He is also an instructor
at UC Berkeley Extension.
xv
Acknowledgments
To my son Barry, Jr., for his careful review of the drafts of this book. He provided a
perfect example of the book’s target audience: a professional Java programmer wanting
to learn Go.
A hearty thanks to all the other reviewers that made helpful comments, suggested
additional content, and/or made errata corrections: Charles Stein, Divya Khatnar, Rosish
Shakya, and Sharath Hegde.
I especially want to thank Ronald Petty for his thorough technical review of this text.
Also, for his numerous suggested content improvements and code samples, several of
which were included.
I wish to thank Jason Isaacs at Dell who supported me during the creation of this text
and allowed me to go forward with this effort.
To the developers of Go and to the Go community in general, many thanks for
building such a powerful tool. I learned much from the extensive Go documentation and
the many articles, blogs, wikis, tutorials, and books provided by the community.
xvii
Introduction
Since its debut in the mid-1990s, Java has enjoyed huge success. Arguably more so
than other languages, Java is a major player in the web application space and key data
processing areas such as Big Data tools, among others. Among other aspects, Java’s high
level of portability across operating systems and hardware architectures, its rich and
improving over time language and library of functions, as well as its good performance
contributed to this success.
But Java comes with some drawbacks. Java was created at a time when Object-
Oriented Programming1 was the norm and network delivery of code was advantageous.
The resulting Java runtime footprint is quite large, and it is resource intensive. The Java
developers are trying to address this to some degree with the use of Java Modules along
with standard library subsetting and the Graal2 Virtual Machine, but typical Java code,
for the same functionality, often uses more resources than typical Go code does.
As time is passing, the Java language and runtime is no longer an optimal fit for many
modern, especially cloud-based, applications. Also, the Java language is continuously
growing and can be a challenge to fully master. Go is deliberately a simple, thus easy to
master, language.
The Go language and runtime is relatively new and designed to meet the needs
of modern cloud computing systems and other system3 programming tasks. It is
considered by many to be a “better C than C” and thus a potential replacement for the C4
programming language, the language it most closely resembles. Go is also likely to take
over a large fraction of the Java server and application space. Thus, it is the raison d'etre
for this book.
Many new applications and reengineering of existing applications are now being
developed in Go. For applications previously written in Java, Kotlin5 or Scala6 JVM
1
https://en.wikipedia.org/wiki/Object-oriented_programming
2
www.graalvm.org/java/
3
Oriented to operating the computer system rather than achieving business tasks.
4
https://en.wikipedia.org/wiki/C_(programming_language)
5
https://kotlinlang.org/
6
www.scala-lang.org/
xix
Introduction
(both available as Java Virtual Machine–based languages) might be the more expected
language to use, but often Go is winning out over them. As an example of a redo into
Go, Khan Academy7 is using Go to reengineer8 its previous Python site implementation.
This often happens because Go exhibits many of the ease-of-use features common to
scripting languages with the efficiency of compiled languages.
The original Go lead designers, Robert Griesemer, Rob Pike, and Ken Thompson, all
at Google, wanted to define a language and associated runtime with these key features
(some also provided by Java):
• High developer productivity – Go offers a consumable and
reasonably complete runtime. It also offers a one-stop shopping
toolchain. It has widespread high community support.
7
www.khanacademy.org/
8
https://blog.khanacademy.org/half-a-million-lines-of-go/
9
https://en.wikipedia.org/wiki/C%2B%2B
xx
Introduction
10
www.red-gate.com/simple-talk/opinion/geek-of-the-week/rob-pike-geek-of-the-week/
11
https://storage.googleapis.com/golang-assets/Go-brand-book-v1.9.5.pdf
xxi
Introduction
12
https://en.wikipedia.org/wiki/Node.js, https://nodejs.org/en/
13
https://en.wikipedia.org/wiki/JavaScript
14
https://golang.org/doc/go1compat
15
https://hackernoon.com/go-is-on-a-trajectory-to-become-the-next-enterprise-
programming-language-3b75d70544e
xxii
Introduction
• Easy to learn
• Ease of maintenance
16
www.infoworld.com/article/3442978/10-open-source-projects-proving-the-power-of-
google-go.html
17
https://brainhub.eu/library/companies-using-golang/
xxiii
Introduction
• Similar to C
• Quick compilation
18
https://awesomeopensource.com/projects/go
19
www.quora.com/profile/Sandra-Parker-34
20
https://medium.com/@Sandra_Parker/why-golang-is-the-future-part-1-ed7dd4f419d and
https://medium.com/@Sandra_Parker/why-golang-is-the-future-part-2-1f984ae8f1a4
xxiv
Introduction
In 2020, Ziff Davis21 showed that Go is the most desired new language to learn, as
shown in Figure 1.
32%
30%
25%
24%
21%
20%
20%
18%
16%
15%
15% 14%
10%
5%
0%
Other sources extol the virtues of Go and indicate it has a growing future. For
example, Towards Data Science22 states these as key features for Go’s success:
1. Go has language-level support for Concurrency. It offers a CSP23
based message-passing concurrency via Goroutine (lightweight
Green thread) and Channel.
21
https://en.wikipedia.org/wiki/Ziff_Davis, www.zdnet.com/article/developers-
say-googles-go-is-most-sought-after-programming-language-of-2020/, and www.
hackerearth.com/recruit/developer-survey/
22
https://towardsdatascience.com/top-10-in-demand-programming-languages-to-learn-
in-2020-4462eb7d8d3e
23
Communicating sequential processes – https://en.wikipedia.org/wiki/
Communicating_sequential_processes
xxv
Introduction
Go is ranked as one of the top five most loved languages by GeeksforGeeks,25 which
describes Go as follows:
Go is a statically typed, open-source programming language designed at
Google that makes programmers more productive and helps to build simple,
reliable, and efficient software very easily. This language … is syntactically
similar to C, but with memory safety, garbage collection, structural typing,
and CSP-style concurrency. Go is well known for its high-performance in
networking and multiprocessing.
They cite these key virtues:
24
Unique selling proposition – https://en.wikipedia.org/wiki/Unique_selling_proposition
25
www.geeksforgeeks.org/top-5-most-loved-programming-languages-in-2020/
xxvi
Introduction
Note that this author disagrees with point 3. In his opinion, Go is object-based,26 not
object-oriented.
The popular TIOBE27 index shows that Go use is growing at a fast rate. A late 2020
survey shows this:
Few languages have seen such high year-over-year growth. TIOBE twice named
Go as the “language of the year.” The future need for Go programmers is expected to
continue to grow rapidly.
A look at Go Users28 shows hundreds of organizations, including some of the world’s
largest companies, using Go around the world. This list is likely to omit many actual
users.
Go is used, and in many ways proven effective, in many complex programs. The
Docker29 container system and the Kubernetes30 container orchestrator are prime
examples of industry-leading programs written in Go. Also, the Go compiler, builder,
and most of the standard libraries are written in Go.31 They are an important test case in
themselves.
In 2020, StackOverflow has ranked (https://insights.stackoverflow.com/
survey/2020) the most loved languages. Go is among the top of the top 25 listed well-known
languages, and it ranks higher in that list on the desired (“loved”) scale than Java. Note how
well it compares to Python; this is remarkable for a compiled language.
26
https://en.wikipedia.org/wiki/Object-based_language
27
The Importance of Being Earnest – https://en.wikipedia.org/wiki/TIOBE_index
28
https://github.com/golang/go/wiki/GoUsers
29
www.docker.com/
30
https://kubernetes.io/
31
Originally bootstrapped from a C version of these tools.
xxvii
Introduction
Rust 86.1%
TypeScript 67.1%
Python 66.7%
Kotlin 62.9%
Go 62.3%
Julia 62.2%
Dart 62.1%
C# 59.7%
Swift 59.5%
JavaScript 58.3%
SQL 56.6%
Bash/Shell/PowerShell 53.7%
HTML/CSS 53.5%
Scala 53.2%
Haskell 51.7%
R 44.5%
Java 44.1%
C++ 43.4%
Ruby 42.9%
PHP 37.3%
C 33.1%
Assembly 29.4%
Perl 28.6%
Objective-C 23.4%
VBA 19.6%
xxviii
Introduction
All this should make learning to program in Go highly interesting to experienced Java
developers looking to broaden their skills and marketability. In the author’s opinion, Go
will emerge as the go-to language for multi-core computing over networks, especially for
servers.
Of course, for a complete analysis, we need to contrast the mascots of Go and Java.
In the author’s opinion, Go’s mascot is both simpler and cuddlier, as, arguably, is the
language itself.
Figure 2 shows the Go logo and Gopher mascot. 32
32
The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/) and is
licensed under the Creative Commons 3.0 Attributions license.
33
https://wiki.openjdk.java.net/display/duke/Main
xxix
Introduction
Gophers, welcome aboard! In this book, we will briefly explore the concepts behind
Go and why it was created. This overview will be followed by an introduction to Go’s
various features and a look at if/how they differ from Java. Then comes a presentation
of most of the Go language statements and data types. This is followed by a brief look
at some potential future Go enhancements. A capstone example Go program is then
presented to unify the Go experience. Next comes a review of the Go standard libraries
as they compare to similar Java libraries. Finally comes a survey of a subset of the various
Go standard libraries as an introduction to their usage. Deeper and more comprehensive
descriptions are available at the Go site.
More precisely, this book’s content is broken down into three parts with several
chapters within each part.
Some background on Go:
A description of the Go language and its key features with a look at using Go in
practice:
xxx
Introduction
In addition, there are five appendixes with supplementary information such as how
to install Go, as well as some summary and reference information.
Note In some of the code examples in this book, long source lines are wrapped
into multiple lines. This wrapping may not be allowed in actual Go source.
The source for the capstone programs, as well as for some of the other listing
samples in this book, is available at the book website: www.github.com/apress/
go-for-java-programmers.
Before we dive into Go, let us consider why Go exists. Rob Pike summarized34 the
language and why it was created this way:
The Go programming language was conceived in late 2007 as an answer
to some of the problems we were seeing developing software infrastruc-
ture at Google. The computing landscape today is almost unrelated to
the environment in which the languages being used, mostly C++, Java,
and Python, had been created. The problems introduced by multicore
34
https://talks.golang.org/2012/splash.article
xxxi
Introduction
35
https://en.wikipedia.org/wiki/Go_(programming_language)
36
https://en.wikipedia.org/wiki/Java_(programming_language)
xxxii
Introduction
These descriptions cover some of the key similarities and differences. In the
author’s opinion, the relative brevity of the Go description reflects the relative
simplicity of Go vs. Java.
Go addresses the needs of modern system and application software development in
cloud environments on modern multi-core machines. In the author’s opinion, it meets
these goals very well. As you explore Go more within these pages, you will see its features
and functions and how they match and support the goals stated earlier. By the time you
finish this book, perhaps you will also agree.
Go was not designed to replace (cover all use cases of ) Java. It is more targeted
toward the use cases of the C (and to some extent C++) language. It is primarily a system
programming language well suited toward implementing servers and tools such as
compilers. Java also supports these types of programs.
One of the reasons Go is popular is it is lightweight relative to many other languages.
Go is arguably more lightweight than Java in many areas. This is one of its most attractive
attributes.
Go’s threading model, provided by goroutines and channels, certainly is lighter
weight. Because it lacks Object-Oriented Programming (OOP) features, its data model
and error processing are also more lightweight. Even more lightweight is the set of
standard libraries. Perhaps most critically, Go’s single executable (vs. a JRE and many
JARs) deployments and resulting fast program launching are most attractive.
Go is also arguably easier to master than Java. The language is simpler and has fewer
constructs to learn. The runtime libraries are, while functional, generally more basic and
approachable.
This is not to say that Go is necessarily better than Java (or the reverse), but that
it is often more approachable and easier to master and use. Both languages and their
runtimes will extend over time; Go is more likely to continue its more approachable style.
xxxiii
Assessments
Divya Khatnar: If one knows Java, they will surely enjoy learning Go using this book. The
author makes sure that each topic uses Java as a baseline to explain Go. Not only does this
book teach you Go, but it also sharpens your understanding about Java.
Charles Stein: As Go becomes a staple language, Java users need a clear guide to help
them make the transition. This book thoroughly covers the basics and exciting applications
of Go from a Java-analogous perspective.
Sharath Hedge: This book covers all the comparisons of Java and Go exhaustively.
Also, it covers important packages provided by Go. As a developer if I want to start a
project in Go, this book will offer ready reckoner for the many questions I have. This book
offers examples for the majority of the cases, which helps a lot.
xxxv
Discovering Diverse Content Through
Random Scribd Documents
other two captains. And now, because I did not take their advice, I have lost
the Dupleix, my ship. Mon Dieu, what an ass I was! Now they will report it
to my owners, and I will never get a ship again."
"The Antonin——"
"Come in."
One Sunday morning, we sighted a large British barque and started after
her. She thought we were playfully challenging her to a race, and tried to
run away. I don't know whether we could have caught her in a straight
sailing ship against sailing ship contest; at any rate, our motor gave us the
edge.
"Pinmore"
Ah, my old Pinmore, on which I had made the longest and most
harrowing voyage of my life. Memories swept over me of those endless
storms and of the disease on board, beri-beri, scurvy. My whole being
seemed to leap back to the days of my youth. Homesickness seized me. I
could not say a word to Leudemann, who stood beside me.
"No use, the ship must be sunk," a harsh inner voice told me.
It was hard for me to sink any sailing vessel, but doubly cruel to have to
sink my old ship. I felt as though she were a kind of mother. No sailor with
any kind of sailor's soul in him will raise a hand against his own ship.
We took her as we had taken the others. When her crew came aboard, I
looked for familiar faces. There were none. The skipper, Captain Mullen,
came up to me with a humorous, seamanly air.
When everyone had left the Pinmore, I had a boat take me over to her. I
clambered aboard and sent the boat and its crew back, telling them I would
give them a hail when I wanted them again.
"Why does the Count want to remain alone aboard her?" I heard one of
them say.
I went to the fo'c'sle. There was my bunk, the same old bunk where I
had slept night after night for months and had tumbled out countless times
at the command "all hands on deck" while those endless storms bore down
upon us. I paced the planks on deck where I had stood watch so often. It
seemed as though I had never seen that deck save in a storm. Those gales
had left so deep an imprint on my memory that it gave me a sense of
strangeness to see the sun shining on the Pinmore's planks and a slowly
heaving sea around.
I remembered a cunning little cat I had once owned on board her. The
captain's wife wanted it. The steward got it for her. I told the steward that if
he did not bring it back to me I would go to the captain. The steward
laughed at me. I determined to complain to the captain about the steward
and his wife and demand my cat back. I could see myself as I had
wrathfully strode along the deck to the cabin. The sight of the door made
me stop. I mustered up my courage and advanced again. I ventured just far
enough to peep in at the door, which was ajar. The skipper was sitting there
reading a paper. One glimpse of the master, and all of Phelax Luedige's
bravery oozed away. He turned and tiptoed away. I never did get my cat
back, and forever after held a grudge against the steward.
I could still feel the old enmity. If I could have found that steward, I
would have let him know how the end of a rope felt. I went to the cabin and
half opened the door. It was much as when I had seen it last. The bright
rainbow glow of the coloured skylight gave me an old familiar feeling.
Something restrained me from entering. I did not dare go in then. I would
not now.
At the stern I looked for my name which I had once carved on the rail. I
found it, half effaced by time and weather. I read it slowly, spelling it out as
a child spells its first lessons: P-H-E-L-A-X L-U-E-D-I-G-E. I looked at the
compass, beside which I had watched for hours. The compass is a sacred
place to a sailor.
"This ship," I thought, "carried me safely. The storms were wild all the
way from 'Frisco around the Horn to Liverpool. They wanted to take us,
every man aboard, but the good old Pinmore fought against wind and wave
over leagues and leagues of dreary waste and brought us safely to port. Yes,
she was our mother, our kindly protecting mother."
The deserted ship with an unguided helm rolled back and forth. The
rigging creaked and groaned. It seemed to be a voice, a voice that hurt me.
Every spar seemed to say:
"So here you are, Phelax, back again. Where have you been all these
years? Where is all the crew? What do you want here, alone? What are you
going to do with me?"
Little had I dreamed when I was a sailor on this fine barque that one day
I would walk her decks again, not as a seaman, but as the commander of a
raider.
Ever taken a trip at sea where the company aboard was dull and dead,
the passengers uncongenial to one another, and everybody sitting around
day after day and bored to death? You have? Well, then, you know what it's
like, eh?
Although our old jolly-boat was a raiding auxiliary cruiser, she also
degenerated into a breed of passenger ship, too. Our passengers were our
prisoners. That made the situation somewhat unusual and added a bit of
spice. I've served as an officer aboard a dozen or more liners, and have seen
all kinds and strata of society aboard, including dull, delightful, ill-natured,
jovial—both the quick and the dead. Yes, I have had some splendid
passenger lists on voyages where every hour was gay and bubbling with
fun. But no group of passengers on a liner ever enjoyed such happy
comradeship as did we aboard our buccaneering craft. The fact that we were
captors and captives only seemed to make it all the jollier. We took the
greatest pleasure in making the time agreeable for our prisoners, with
games, concerts, cards, and story-telling. We tried to feed them well, and I
think we did, which helps a lot, as you'll agree. We didn't throw it at them
either. In fact, we served special meals for all the nations whose ships we
captured. One day our own German chef cooked, and that boy was some
cook, as you say. The next day an English cookie, then the French chef,
then the Italian to make us some polenta. The English food was the worst. It
usually is. On the other hand, the Americans fed their sailors best of all. It's
long been a tradition on Yankee clippers. In the old days, the American
sailing ships were famous for frightful work and much brutality, but the
food was good. To-day the work is not bad and there is no brutality, but the
food is still good.
There was only one of our prisoners who behaved himself in any way
that could be considered improper. That was Captain Lecoq of the La
Rochefoucauld, that same Captain Lecoq who had cherished hopes that we
would run afoul of the British cruiser. You see, the skippers aboard were
quite free to go where they liked on the ship, except that I asked each one,
as he came aboard, not to go into the fore part of the ship, and I explained
why.
"My magazines," I said, "are in the forward half of the boat. I do not
want you to know exactly where they are placed. After you are released,
you might reveal the secret. Then, one of these merry days, if some cruiser
takes a shot at me, and if the location of my magazines is known, they'll aim
right at that spot. A shell there and up in the air we go. I must ask you to
give me your word of honour that you will not go into the foreship, else I
will have to keep you confined."
Captain Lecoq broke his promise. He not only went secretly into the
foreship, but he made sketches of the layout there. Captain Mullen of the
Pinmore saw the sketches, knocked Lecoq down, and reported him to me. I
berated Lecoq soundly.
He turned a bit green around the gills at that, but there was nothing he
could say in reply.
Our only woman aboard, the skipper's little bride, grew melancholy. We
did everything we could to make the time pleasant for her, but she pined for
the society of other women. It was rather a trial for her to be so long the
only woman among several hundred men.
"Count, I do so wish there were a woman aboard that I could talk to,"
she said to me a bit coaxingly one day. "Why don't you catch me one?"
The captain looked curiously at the crowded figures standing at our rail,
of every colour and race. They waved gaily. Our gramophone blared out,
"It's a Long Way to Tipperary."
Officers and sailors and the woman on his deck craned their necks for a
reply.
I could see the captain rapidly thumbing the pages of his book. His head
jerked up suddenly. His binoculars focussed themselves on our masthead
where the German flag now waved. Our gun mask dropped, and the cannon
peered forth. By Joe, but it raised a commotion on the deck. When she saw
it, the woman darted into her cabin. The sailors ran to the boats. Even the
helmsman deserted the wheel. The captain was the only one who kept his
head. He seized the helm with a firm hand, and the ship hove to.
Our little woman put on her best clothes and asked me for a nosegay
from a supply of artificial flowers we had captured. The newly arriving
woman, who scarcely knew what to expect aboard our dreadful pirate craft,
was surprised when she was greeted not only by our Captains' Club with all
of its stately courtesies, but also by a brightly smiling young woman who
presented her with a bouquet of flowers that made up in brightness of
colour what it lacked in sweetness of perfume, since they were imitation
ones.
The two women immediately became the best of friends, and the
convivial spirit aboard made our happiness complete.
We did catch them. We caught a match box full of them, and put them in
his bunk.
XIX
Our floating hotel was about full. If we wanted to take any more guests
aboard, we would have to get rid of our present company. The old pirates
would have had a plank-walking ceremony. That was a sure way to prevent
inconvenient information from getting around. Undoubtedly, it would have
enabled us to keep our existence still secret. We were buccaneers in a sense,
but not quite that bad. We would have to take other measures. When our
prisoners got to port and our freebooting career became known, cruisers, of
course, would set out after us. They would make the narrow Atlantic much
too hot for us. We would have to seek other waters. The broad Pacific
remained. We did not want to hold our prisoners for the always rough
passage of Cape Horn, where, in addition, there were likely to be cruisers
on watch, keeping a guard for suspicious ships that might be trying to take
the shortest route from European waters to the Pacific. We might be shelled
and sunk, but it would have been scarcely humane to take a chance of going
down with all our prisoners on board. So we arranged it in a way that would
enable us to get a good start on our trip around Cape Horn before the
cruisers could get word of us.
The French barque, the Cambronne, came along. You should have seen
her heave to and her yards come banging down when our German flag went
up and we signalled the inevitable: "Stop or I shall fire."
Her captain exhibited all of the usual Gallic despair at the prospect of
losing his ship. We looked the craft over. She was large and roomy and had
aboard a large stock of provisions.
"No," I said to her skipper, "we are not going to sink your ship. She will
go right on to port."
"They won't be your guests, Captain. You will be the guest of the new
captain of the Cambronne."
"Not at all. I have a Captains' Club aboard. You, as a prisoner, are now a
charter member. Your ship is my prize. I will select a member of the
Captains' Club as her skipper."
He was very angry. It hurt him nearly as much to be removed from the
command of his ship as to have her sunk.
I was rather glad that it was not I who would command the Cambronne.
With all those captains aboard, especially the disgruntled French captains,
the skipper of the Cambronne was certain to have an uncomfortable time.
One skipper always knows more than any other skipper. Nor is any skipper
ever reticent about the mistakes of another. The skipper of the Cambronne
had better navigate with a perfect correctness, or there would be plenty of
talk aboard.
We lopped off the Cambronne's upper masts, so that she could set only
her lower sails. She could not make any speed now, and it would take her
from ten to fourteen days to get to Rio de Janeiro, which was the nearest
port. Then I exacted a pledge from Captain Mullen:
"Captain," said I, "we are releasing our prisoners, and they are under
your command. I understand perfectly well that when you get to port our
existence will be known. We will be a sailing ship in a world of armoured
cruisers. We will be chased like a wild deer. We need a start. We have taken
care that you do not get to port too soon. One thing remains, though. You
may meet a ship within a week or within a day—it may be a steamer with a
wireless plant. I ask for your word that you will not communicate with any
ship until you reach port. We have, I hope, treated our prisoners fairly, and I
ask this of you in return. I must have your solemn word on it."
"Count," he replied, "I give you my word that the Cambronne will not
communicate with any ship until she is in port at Rio."
We shook hands on it, and my mind was at rest. It was no risk to take
the word of the Pinmore's old skipper.
He played his part nobly. He passed several steamers on his way to Rio,
but steered clear of them. One comical thing happened. A big steamer came
toward the Cambronne one morning, and then her captain noticed the crowd
of prisoners on the ship's deck. He was a cautious soul. It looked suspicious.
The steamer turned and fled at full speed.
"Gentlemen," I replied, "I have just now rested the safety of my ship on
Captain Mullen's word. You are all ship masters. You know a captain's duty
to the vessel he commands. Very well, I know that Captain Mullen's word is
good. I have taken the others of you at your word, and you have not failed
me. But Captain Lecoq broke his word. Can I trust him not to break it
again?"
They argued so hard for their unfortunate fellow skipper that I finally
gave in. After all, even if he did break his word again and tell of the
position of my magazines, it did not necessarily mean disaster. I made him
sign a promise and made the other captains sign as witnesses to his promise.
Then I gave orders that he should go with the rest.
We paid our prisoners off, just as if they had been working for us. Each
received wages for the time he had spent aboard, and each was paid the
wage he ordinarily received from his shipowner. By Joe, that made them
happy. We had a final banquet. The sailors feasted in their quarters. I
entertained the officers and ladies in my cabin. Toasts of champagne were
drunk, and at the end there were cordial handshakes. We transferred the
crowd to the Cambronne in boatloads, and each boat, as it pushed off, gave
three cheers for the Seeadler.
Evening was coming on. The Seeadler lay watching while the
Cambronne raised sail. Now the stately barque was sliding through the
water. Hands waved and farewells were shouted. The two ships saluted each
other. With her snow-white canvas bellied out by the brisk wind, the
Cambronne sailed toward the horizon. Aboard the buccaneer, we watched
till the last tip of her mast disappeared below the skyline.
We had been away from port for eight weeks and had sunk eleven
vessels, representing a total of more than forty thousand tons of Allied
shipping. The Atlantic had given us its share. Now to the Pacific. And God
save us from the cruisers.
XX
Through an oily sea we sailed south and west toward the Falkland
Islands. Many a time had I passed this way in the old days when bound for
Cape Horn. These islands of the South Atlantic have long been the base for
whaling schooners. But to every German the Falklands will be forever
memorable as the scene of a one-sided naval engagement in which one of
our best beloved admirals was overwhelmed by a British fleet.
Had you seen our deck as we sailed south during these days, you might
have wondered what we were about. Along with other plunder, we had
looted captured ships of several great sheets of iron. We had ripped them
from iron walls and roofs of forecastles and stowed them on our deck. Now
the mechanics of the Seeadler's motor crew got busy with acetylene
torches, and from those sheets of metal they welded a great iron cross, ten
feet high.
We drew near a spot on that lonely ocean just a bit to the east of the
Falkland Islands. My navigation officer and I figured out the point carefully
on our chart, and when our instruments told us we were there, I called all
hands on deck. Somewhere far below on the floor of the ocean were the
bodies of hundreds of our comrades and the battered hulks of a once proud
German fleet. It was in these very waters that our gallant Pacific Squadron
under Count von Spee sank in three thousand fathoms. For here it was that
our light cruisers, the Scharnhorst, Gneisenau, Nuremburg, and Leipsic,
with odds against them, fought it out with a more powerful British
squadron.
With flag at half mast, we stood at solemn attention. The sky was gray
and melancholy. The sea rolled with a gentle swell. In our mind's eye we
could picture that disastrous day when, outranged by the guns of the great
British warships, our cruisers, two large and three small, had fought a losing
and hopeless fight. One, a scout cruiser, escaped. The others went down.
Pounded from the distance, they trembled under the blows of the shells that
rained down upon them. Exploding projectiles raked the decks and pierced
the hulls of the ill-fated vessels. As if in a last struggle, trying to keep afloat
for one more shot at the enemy, they staggered, lurched, and then, one after
the other, plunged into the depths, entering port on their final voyage far
below on the ocean floor, eighteen thousand feet beneath the surface. Every
man aboard three of the ships was lost. A high sea happened to be running
at the time, so the victors had little chance to rescue the men from the
doomed ships. Two hundred and fifty members of the crew of the
Gneisenau were picked up and got to the Falklands alive.
The sailors all give three cheers. They think the Admiral and his men
are merely going for a pleasant vacation to the Orient. It is in 1913. No war
is in sight. Yet a darker note intrudes: Even then military and naval men
were unable to escape the thought of war:
"We are leaving home and country for two years. We who part from you
to-morrow will do our duty, knowing that every man at home will do his. If
war should come, we will be across the world and you will be here. We will
be too far away to lend a hand to you, and there is little that you will be able
to do for us.
"Ours is a young navy, but we have had a great teacher. When England
built her mighty fleet, she taught us how to build ours. The English have
great naval traditions, and both their fleet and traditions have been our
model. If war should come before we meet again, we along the far-off
China coast may be but a few ships against many enemies, but from you of
the High Sea Fleet we expect great deeds."
The day after he said auf wiedersehen to us at Kiel, he and his officers
and men left by transport for the Orient, there to relieve the officers and
men aboard the cruisers of our small Pacific Squadron at Tsing Tao. What
was to have been their two-year term overseas began as commonplace,
quiet routine. It ended under the salvos of British guns off the Falkland
Islands.
Von Spee's plan, when the war caught him 15,000 miles from German
waters, was to harass the Allies in the Pacific and then try to slip back
through the North Sea to Kiel. Lady Luck smiled on him for a little while
and then deserted him. After crossing the Pacific, he caught Craddock, the
British admiral, off the coast of Chile. Von Spee's star was in its ascendancy
at this time and Craddock's on the wane. A German secret agent in Chile
flashed a wireless to Von Spee giving him the information that Craddock
was waiting for the arrival of the big but old battleship Canopus that was
rounding the Horn. Without the Canopus, Craddock's forces were weaker
than Von Spee's, and Von Spee instantly dashed to the attack so as to engage
Craddock before the Canopus came up. Craddock and his men met their
fate like true British sailors. Outgunned, the British cruisers continued to
fire until they sank. Only one, a small boat, got away. But their conqueror's
days were numbered.
Von Spee now began his long race toward Kiel. Only two routes were
possible, one by Cape Horn and the other by the Cape of Good Hope. Of
course, he knew the British would be laying for him at both places. He
knew also that they would be after him with swifter and more powerful
ships than his own. His one chance was to beat them to Cape Horn, lose
himself in the broad Atlantic, make a run for it, and probably fight his way
through the blockade.
As he rounded the Horn, Dame Fortune tempted him, and he made what
proved to be a fatal error. He stopped a British collier and took all her coal.
This delayed him for three days. Meanwhile, a fleet of Britain's mightiest
battle cruisers had arrived at the Falklands. He still might have run by them
unnoticed had he not determined to shell and destroy the wireless station on
the Falklands. Thus he stumbled into that nest of battle cruisers. He tried to
run, but they caught and sank him. That day the British had their sea giants,
the Indefatigable, the Invincible, the Indomitable, and along with them a
number of other battle cruisers, that later were to fight gallantly at Jutland,
and then find their way to rest on the floor of the North Sea.
Only one of Von Spee's ships, the light but fleet cruiser Dresden,
showed her heels to the British leviathans and slipped back around Cape
Horn, But the Fates were merely playing with the poor Dresden, and a few
days later she was sunk by the more powerful British cruiser Kent off San
Juan Fernandez, Robinson Crusoe's island, in the Pacific. She was lying in
neutral waters and should have been sheltered by the laws of war. Her
captain signalled to the commander of the Kent:
"My orders are to sink you on sight," replied the Kent, "and no matter
where you are."
The captain of the Dresden blew up his ship, and with his officers and
crew swam ashore. The island was not quite so deserted after this shipwreck
as it was in Robinson Crusoe's day!
That in brief was the story of the plucky Von Spee and his gallant men.
Hence this dreary waste of waters off the Falklands was sacred to us. We
hove to, and from my quarter-deck I presided over a brief memorial service
above the watery graves of our comrades and their ships. First I told my
boys the story of my friend Count von Spee and his men, and every one of
us knew that we, too, might soon be on our way to join them. But with the
difference that we might not even have a chance to fight it out.
On German ships, the captain is also the chaplain. Every Sunday aboard
the Seeadler we had our hour of prayer and song. When we had "guests"
aboard from enemy ships, we invited them to join with us in the worship of
the Great Ruler of the Waves. Our service followed the ritual of no
particular creed. It was as simple as we simple seamen could make it. The
table which bore the ship's Bible was draped not only with our German flag
but also with the flags of all the Allied nations whose ships we had captured
and under whose colours our prisoners had sailed. I wanted to make our
prisoners feel that the service was as much theirs as it was ours, and that we
did not feel ourselves any more a chosen people before the Altar of God
than any other people.
My life has not been altogether a pious one. On the contrary, it had been
decidedly blasphemous. My character was then, and still is, far from saintly.
However, I may not have been wholly unfit for the office of ship's chaplain.
I am religious at heart, easily swayed by sentimental appeal. Had I not been
a member of the Salvation Army in Australia? Those testimonial meetings
in Fremantle were still vivid memories to me. So I was not exactly a
greenhorn at conducting a prayer meeting.
I then led the sailors in a prayer that we repeated aloud, and while the
chorused invocation travelled southward on the winds that blew toward the
Antarctic, four men came forward bearing the great iron cross.
At this signal from me the massive emblem slid into the water with
scarcely a splash and flashed swiftly down, down, three thousand fathoms,
to carry our message to Admiral Count von Spee and his men.
XXI
We knew that, as soon as our former prisoners made port, the news of
our presence in the South Atlantic would be flashed abroad. Then the
British would send their cruisers on the double-quick down the coast of
South America to keep us from doubling the Cape. To be sure, we had taken
care to give ourselves a mighty good start. But in a race of windjammer
against swift cruisers, what is a start of a thousand miles or so? With decent
weather, we had hopes of making it. So far we had had fair winds and had
made good time. But the most difficult stretch of sea in all the world now
lay before us. The storms for which the Horn is famous often delay sailing
ships for weeks.
A feeling of homesickness for the old Moewe came over me, as it does
over any sailor at the mention of a ship on which he has sailed. My service
aboard the Moewe had been neither long nor eventful, but already she had
made for herself a heroic reputation. I have always regretted that I was not
with her on her raids. She made several, slipping out through the blockade,
sinking quantities of Allied shipping, and stealing back into German waters.
She was built just before the war, and originally designed to carry the
exotic banana from Southwest Africa and "German East" to Hamburg.
Plans had just been made to flood Germany with them. Her sister ship in the
banana trade was the Wolf, and she, too, became a famous raider.
All manner of ingenious devices were invented in fitting out the Moewe
for her career as a raider. She was altered so that she could disguise herself
and change disguises while steaming at full speed just like a quick-change
actor. One day she would be a three or two funnelled steamer, the next she
would look like a slow tramp with one funnel. The line of her deck could be
changed in a few minutes also. She also had fake superstructures that could
be raised or lowered at will. She could even be made longer or shorter in a
few moments by means of a fake section that slipped out from her stern.
One day she would be a tramp, the next, with fake bulls'-eyes, a liner. These
startling metamorphoses were a great success and enabled her to dodge
many an Allied cruiser.
The two ships steamed with straining boilers, and the Glasgow was fast
creeping up on the Moewe. When almost within range, the hunted raider ran
into one of those sudden rain squalls that sweep over the ocean. Like the
Biblical cloud, it hid her from the pursuing cruiser. Of course, the Glasgow
followed her into the squall. But as the Moewe ran through the swirling
storm, she passed another steamer, this one steaming north. The cruiser saw
emerging from the squall this new ship. She had three masts. The Moewe
had had but two. The captain of the Glasgow thought only of the Moewe's
ability to disguise herself. He presumed that the Moewe had taken
advantage of the squall to run up a third mast and then double back on her
trail in the hope that the Englishman would not recognize her and that she
might pass safely and even have an opportunity to torpedo the Glasgow.
The cruiser instantly opened fire, and blew the poor, inoffensive cargo
steamer out of the water. It was only when they examined the wreckage that
they discovered that they had made a mistake and sunk a British freighter!
Meanwhile, the Moewe had escaped once more.
Nor was that the only ship the British sank by mistake. They shelled two
harmless sailing vessels to pieces, mistaking them for our Seeadler. It all
came about because of one of those familiar war rumours, a rumour to the
effect that we were already somewhere off the Australian coast. An
Australian cruiser encountered a Scandinavian three-master, and they
seemed to think she was behaving queerly. Word had been passed around
that the Seeadler carried torpedoes. So the cruiser thought she had better not
run any chance of being blown up. She opened fire at long range. Only ten
men aboard the Scandinavian ship were saved. Later on, the armoured
cruiser Kent[1] sank another sailing vessel under similar circumstances in
the Pacific.
Sailors since Magellan, by Joe, have talked about the storms around
Cape Horn. Sea stories usually have something about the tough times
rounding the Cape. I had seen those storms myself when I had sailed in the
forecastle, and as a naval officer I had many a time told tales to my brother
officers of gales and tempests I had witnessed in an old windjammer
rounding Horn. But our trip this voyage was to be the most unusual of all. If
the storms held us back, the cruisers would be almost certain to catch us.
We had sailed south in fine time, and if we made a quick passage round that
boisterous tip of South America, we might slip into the wide Pacific and
continue our raids.
Well, we ran into the dirtiest weather off the Horn, gales and hurricanes.
Why, there were days when even with our motor running we could make no
headway at all. It took us three weeks to beat our way through the gales and
around the point. By that time, the cruisers lay there in wait for us, not just
one or two, but a whole half dozen of them.
On our way through the blockade, we had steered into the Arctic. Now
here we were heading into the Antarctic.
To make it pleasant, by Joe, the weather, which had been quite decent to
us on the way south, changed in order to give us a regular Cape Horn
welcome. It turned into a veritable hurricane. Nevertheless, we were
determined to carry as much sail as possible. Risky, but we had to take
chances in the hope of getting through. As the tempest increased, not even
the Seeadler dared carry more than a rag or two of lower sail. With this we
tried to hold our way. Through the mist we saw a great wall. It came
moving toward us. A vast wall of white, an iceberg. The wind was driving
this white spectre through the water, and we had to veer off in order to
avoid collision.
To the north were the cruisers, and here, but a few hundred yards away,
an equally relentless enemy bearing down upon us, as though determined to
turn us into the arms of our pursuers. A shout to the helmsman. Determined
as we were to go no farther north, we knew we could do no more than hug
the Antarctic ice field.
The ship shook as the helm was forced over, and the wind nearly turned
us bottom side up. Storm or no storm, we were all dead men if that cruiser
ever caught us.
We must risk it and run with all our canvas before the hurricane, and
perhaps, somehow, we knew not how, in the shelter of the storm, we might
be lucky enough to evade the cruiser.
Only men who have been to sea in windjammers can imagine what it is
to set sail in a hurricane. The canvas whipped as though a devil had taken
hold of it. The masts bent under the force of the wind as it blasted against
the sails. The ship and its rigging creaked and groaned as though crying out
against the sudden strain.
Never mind the hurricane. To the south we go. We'll bury ourselves in
the Antarctic ice before we let them catch us, if the wind doesn't snap off
our masts.
So, with the combined force of the gale and our 1,000-horsepower
motor, we scudded southward. Suddenly, a flooding rain broke over us, a
providential squall if there ever was one. It was like a gift of heaven. It
blotted us out from the cruiser, just like the squall that rescued the raider
Moewe.
"It is the hand of God," I shouted. "Our hour hasn't struck yet."
Under cover of the squall, we got away from there as fast as we could
go, and after a few hours we felt certain we had given our pursuer the slip.
In reality, we had not been pursued at all. The cruiser hadn't even seen us,
and our lookout had been sharper than hers. We learned this from later
reports. The ironical thing now would have been for us to have impaled the
Seeadler on an iceberg in that mad sprint southward. But luck was with us
again. The storm blew itself out.
Still, we were not out of the danger zone. Days went by before we were
safely out of that boisterous region and spreading our wings on the broad
expanse of the Pacific. Cruisers were still watching for us, and we had to
keep a constant lookout. Our problem now was how to put them off the
scent.
This left the way clear for us, and now we sailed out to continue our
adventure on the greatest of all the seven seas.
Now, when old John Bull tells a fib, you can bet, by Joe, that he has
good reason for it. We tried to figure it out, and came to the conclusion that
it had something to do with the scare we had created. The news that our
prisoners had given out at Rio had sent Lloyd's rates skyward and caused
many ships to lie in harbour until the danger from the German raider had
blown over. The British, in order to bring Lloyd's rates down and to liberate
all the shipping that had been tied up, took pains to spread a highly coloured
report of our disaster dressed up with suitable imaginative trimmings to
make it more convincing.
Our wireless operator, a very capable fellow, worked out a scheme with
me. "Sparks" sent out the following message purporting to come from a
British ship:
SOS—SOS—German sub....
After a suitable interval he sent out another call, this one merely
reporting German submarines off the coast of Chile.
Did Lloyd's rates go up again? And did those ships that were getting
ready to put to sea put back to their berths? Well, you can bet your boots
they did. And we sent out other submarine warnings every so often just to
keep our little joke alive.
These were all small injuries, but we had been sent out to harass the
enemy, and this was one way of doing it. What more could you expect of a
lone windjammer? And then, it's these injuries all added together that more
often than not win the day. It was good sport for us, anyhow.
XXII
Our wireless antennæ kept us in touch with the latest phase of the
international situation. Nor was it particularly pleasant on those long idle
days at sea to sit and meditate on the fact that the United States was going
into the war against us. We sailors knew better than some of our people at
home the tremendous power of the great republic of the West. There were
closeted statesmen and generals who might talk as they pleased about the
American lack of military preparedness and the impossibility of American
troops being mustered and sufficiently trained in time to be of any service
in the critical hour of the war. We sailors had travelled. Many of us had