PDF Building Applications with Scala 1st Edition Pacheco download
PDF Building Applications with Scala 1st Edition Pacheco download
https://ebookgate.com/product/building-high-integrity-applications-
with-spark-1st-edition-john-w-mccormick/
ebookgate.com
https://ebookgate.com/product/building-b2b-applications-with-xml-a-
resource-guide-1st-edition-michael-fitzgerald/
ebookgate.com
https://ebookgate.com/product/agile-data-science-building-data-
analytics-applications-with-hadoop-1st-edition-russell-jurney/
ebookgate.com
Getting Started with SBT for Scala 1st New edition Edition
Shiti Saxena
https://ebookgate.com/product/getting-started-with-sbt-for-scala-1st-
new-edition-edition-shiti-saxena/
ebookgate.com
Building Web Applications with ADO NET and XML Web
Services 1st Edition Richard Hundhausen
https://ebookgate.com/product/building-web-applications-with-ado-net-
and-xml-web-services-1st-edition-richard-hundhausen/
ebookgate.com
https://ebookgate.com/product/building-php-applications-with-symfony-
cakephp-and-zend-framework-1st-edition-bartosz-porebski/
ebookgate.com
https://ebookgate.com/product/javatm-programming-with-corbatm-
advanced-techniques-for-building-distributed-applications-3rd-edition-
gerald-brose/
ebookgate.com
https://ebookgate.com/product/professional-scala-1st-edition-janek-
bogucki/
ebookgate.com
Building Applications with Scala
Table of Contents
Building Applications with Scala
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Introduction to FP, Reactive, and Scala
Functional programming
Principles of functional programming
Immutability
Disciplined state
Pure functions and no side effects
First-class functions and higher-order functions
Type systems
Referential transparency
Installing Java 8 and Scala 2.11
Read Eval Print and Loop - REPL
Scala Hello World using the REPL
Scala REPL Hello World program
Scala object-oriented HelloWorld program
Scala HelloWorld App in the Scala REPL
Java HelloWorld application
Scala language - the basics
Scala variables - var and val
Scala REPL var usage
Scala val usage at the Scala REPL
Creating immutable variables
Scala variable type in the Scala REPL
Scala variables with explicit typing at the Scala REPL
Scala conditional and loops statements
If statements in Scala REPL
If statements in return statements in Scala REPL
Basic for loop in Scala REPL
For with List in Scala REPL
For with if statements for filtering - Scala REPL
Java code for filtering even numbers
For comprehensions
For comprehension in Scala REPL
Java code for performing filtering with collections
Scala collections
Creating, removing, and getting an item from a mutable list in Scala REPL
Scala tuples
Scala immutable Map in Scala REPL
Scala mutable Maps at Scala REPL
Monads
Scala Map function in Scala REPL
Option Monad in Scala
A list of all methods using the Scala REPL
Scala class, traits, and OO programming
A simple Scala class in Scala REPL
Scala plain old Java object in Scala REPL
Person class in Java
Traits and inheritance
Scala inheritance code in Scala REPL
Scala traits sample code in Scala REPL
Scala traits using variable mixing technique at Scala REPL
Scala type alias sample in Scala REPL
Case classes
Scala case classes feature in Scala REPL
Pattern Matcher
Simple Pattern Matcher in Scala
Advanced pattern matcher in Scala REPL
Advanced complex pattern matcher in Scala REPL
Partial functions
Simple Partial function in Scala REPL
Scala PartialFunction without OO using case statements in Scala REPL
PartialFunction composition in Scala REPL
Package objects
package.scala
MainApp.scala
Functions
Partial application
Partial function in Scala REPL
Curried functions
Curried functions - Scala REPL
Curried transformation in Scala REPL
Operator overloading
Scala operator overloading in Scala REPL
Implicits
Scala Implicits in SCALA REPL
Implicit Parameter at Scala REPL
Futures
Simple Future code in Scala REPL
A complete Future sample at Scala REPL
Reactive Programing and RxScala
Simple Observables Scala with RxScala
Simple Observables Scala with RxScala - Execution in the console
Complex Scala with RxScala Observables
Summary
2. Creating Your App Architecture and Bootstrapping with SBT
Introducing SBT
Installing SBT on Ubuntu Linux
Getting started with SBT
Adding dependencies
Generating Eclipse project files from SBT
Application distribution
Hello world SBT / Scala App
Bootstrapping our Play framework app with Activator
Activator shell
Activator - compiling, testing, and running
Summary
3. Developing the UI with Play Framework
Getting started
Creating our models
Creating routes
Creating our controllers
Working with services
Configuring the Guice module
Working with views(UI)
Summary
4. Developing Reactive Backing Services
Getting started with reactive programming
IPriceService - Scala trait
PriceService - RxScala PriceService implementation
Guice Injection - Module.scala
NGServiceEndpoint
Play framework and high CPU usage
RndDoubleGeneratorController
IRndService.scala - Scala trait
RndService.scala - RndService implementation
Module.scala - Guice Injections
main.scala.html
product_details.scala.html
Summary
5. Testing Your Application
Unit testing principles
Making code testable
Isolation and self-contained tests
Effective naming
Levels of testing
Testing with Junit
Behavior-Driven Development - BDD
MyFirstPlaySpec.scala - First BDD with ScalaTest and the Play framework
Testing with Play framework support
ProductService.scala - FIX the code issue
ImageServiceTestSpec.scala - ImageService Test
ReviewServiceTestSpec.scala - ReviewService test
Testing routes
RoutesTestingSpec.scala - Play framework route testing
Controller testing
RndDoubleGeneratorControllerTestSpec.scala - RndDoubleGeneratorController tests
IntegrationSpec.scala
ProductControllerTestSpec.scala
product_index.scala.html
ImageControllerTestSpec.scala
image_index.scala.html
ReviewControllerTestSpec.scala
review_index.scala.html
ApplicationSpec.scala
NGServiceImplTestSpec.scala
NGServiceEndpointControllerTest.scala
Summary
6. Persistence with Slick
Introducing the Slick framework
MySQL setup
Configuring Slick in our Play framework app
Configure the database connection
FPM Mapping
ProductDao
ReviewDAO
ImageDao
Slick evolutions
Refactoring services
Refactoring controllers
Configuring DAO packages in Guice
Refactoring tests
Generic mocks
Service tests
Controller tests
Running the application
Summary
7. Creating Reports
Introducing JasperReports
JasperReports workflow
Jasper sessions
Installing Jaspersoft Studio 6
Configuring MySQL Data Adapter in Jaspersoft Studio
Creating a product report
Creating a review report
Creating an image report
Integrating JasperReports with Play framework
build.sbt
Generic report builder
Adding the report to the product controller
Adding the report to the review controller
Adding the report to the image controller
Routes - adding new report routes
New centralized reports UI
Adding the report button for each view
Summary
8. Developing a Chat with Akka
Adding the new UI introduction to Akka
Introduction to the Actor model
What is an Actor?
Message exchange and mailboxes
Coding actors with Akka
Actor routing
Persistence
Creating our chat application
The chat protocol
The chat controller
Implementing the chat controller
Configuring the routes
Working on the UI
Adding Akka tests
Scala test for Akka Actor
Chat room Actor test
Chat Bot Admin Actor test
Summary
9. Design Your REST API
Introduction to REST
REST API design
HTTP verbs design
Uniform API
Response with HTTP status codes
REST API patterns
API versioning
Some anti-patterns to be avoided
Creating our API with REST and JSON
RestApiContoller
REST API Front Controller implementation
JSON mapping
Configuring new routes
Testing the API using the browser
Creating a Scala client
Configuring plugins.sbt
Configuring build.sbt
Scala client code
Creating our REST client proxies
Creating ScalaTest tests for the proxies
Adding back pressure
The leaky bucket algorithm
Scala leaky bucket implementation
Testing back pressure
Adding Swagger support
Swagger UI
Build and install Swagger Standalone
Summary
10. Scaling up
Standalone deploy
Reports folder
Changing report builder
Defining the secret
Running the standalone deploy
Architecture principles
Service orientation (SOA/microservices)
Performance
Scalability/Resiliency
Scalability principles
Vertical and horizontal scaling (up and out)
Caching
Load balancer
Throttling
Database cluster
Cloud computing/containers
Auto Scaling
A note about automation
Don't forget about telemetry
Reactive Drivers and discoverability
Mid-Tier load balancer, timeouts, Back pressure, and caching
Scaling up microservices with an Akka cluster
Scaling up the infrastructure with Docker and AWS cloud
Summary
Building Applications with Scala
Building Applications with Scala
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly or
indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals. However,
Packt Publishing cannot guarantee the accuracy of this information.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78646-148-3
www.packtpub.com
Credits
Author Copy Editor
Did you know that Packt offers eBook versions of every book published, with PDF and ePub
files available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and
eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt
books and video courses, as well as industry-leading tools to help you plan your personal
development and advance your career.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Preface
Functional programming started in academia and ended up in the IT industry. The Scala
language is a multi-paradigm language used by big players and large organizations that helps
you get the correct (in the sense of pure functional programming) software and, at the same
time, software that is practical and scalable.
Scala has a very rich ecosystem, including Play Framework, Akka, Slick, Gatling, Finable,
and more. In this book, we will start right from the basic principles and ideas on functional
and ReactiveX programming, and through practical examples, you will learn how to code
with the most important frameworks of the Scala ecosystem, such as Play, Akka, and Slick.
You will learn how to bootstrap a Scala application with SBT and Activator, how to build a
Play and Akka application step by step, and we cover the theory of how to scale massive Scala
applications with cloud and the NetflixOSS stack. This book will help you to go from the
basic subjects to the most advanced ones in order to make you a Scala expert.
What this book covers
Chapter 1, Introduction to FP, Reactive, and Scala, looks at how to set up a Scala development
environment, the difference between functional programming and object-oriented
programming, and the concepts of functional programming.
Chapter 2, Creating Your App Architecture and Bootstrapping with SBT, discusses the overall
architecture, SBT basics, and how to create your own application.
Chapter 3, Developing the UI with Play Framework, covers the principles of web development
in Scala, creating our models, creating our views, and adding validations.
Chapter 5, Testing Your Application, looks into testing principles with Scala and JUnit,
behavior-driven development principles, using ScalaTest specs and DSL in our tests, and
running our tests with SBT.
Chapter 6, Persistence with Slick, covers principles of database persistence with Slick,
working with Functional Relational Mapping in your application, creating the queries you
need with SQL support, and improving the code with async database operations.
Chapter 7, Creating Reports, helps you understand Jasper reports and add database reports to
your application.
Chapter 8, Developing a Chat with Akka, discusses the actor model, actor systems, actor
routing, and dispatchers.
Chapter 9, Design Your REST API, looks into REST and API design, creating our API with
REST and JSON, adding validations, adding backpressure, and creating a Scala client.
Chapter 10, Scaling Up, touches upon the architecture principles and scaling up the UI,
reactive drivers, and discoverability. It also covers middle-tier load balancers, timeouts, back
pressure, and caching, and guides you through scaling up microservices with an Akka cluster
and scaling up the infrastructure with Docker and AWS cloud.
What you need for this book
For this book, you will need the following:
Ubuntu Linux 14 or superior
Java 8 update 48 or superior
Scala 2.11.7
Typesafe Activator 1.3.9
Jasper Reports Designer
Windows fonts for Linux
Eclipse IDE
Who this book is for
This book is for professionals who want learn Scala, as well as functional and reactive
techniques. This book is mainly focused on software developers, engineers, and architects.
This is a practical book with practical code; however, we also have theory about functional
and reactive programming.
Conventions
In this book, you will find a number of text styles that distinguish between different kinds of
information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames,
dummy URLs, user input, and Twitter handles are shown as follows: "The next step is to
create the environment variable called SCALA_HOME, and to put the Scala binaries in the PATH
variable."
New terms and important words are shown in bold. Words that you see on the screen, for
example, in menus or dialog boxes, appear in the text like this: "The Actor behavior is the
code you will have inside your Actor."
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book--
what you liked or disliked. Reader feedback is important for us as it helps us develop titles
that you will really get the most out of.
To send us general feedback, simply e-mail [email protected], and mention the book's
title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to
get the most from your purchase.
Downloading the example code
You can download the example code files for this book from your account at
http://www.packtpub.com. If you purchased this book elsewhere, you can visit
http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
We appreciate your help in protecting our authors and our ability to bring you valuable
content.
Questions
If you have a problem with any aspect of this book, you can contact us at
[email protected], and we will do our best to address the problem.
Chapter 1. Introduction to FP, Reactive, and
Scala
In our first chapter, we will learn the basic concepts of Functional Programing (FP), reactive
programming, and the Scala language. These concepts are listed as follows:
Setting up a Scala development environment with Eclipse Scala IDE.
Basic constructs of the language like var, val, for, if, switch, and operator overload.
The difference between FP and object-oriented programming.
Principles of pure FP: immutability, no side effects, state discipline, composition, and
higher order functions.
Concepts of FP such as lambda, recursion, for comprehensions, partial functions,
Monads, currying, and functions.
Pattern Matcher, recursion, reflection, package objects, and concurrency.
Scala is a post-functional programming language built on top of the JVM. Being on top of the
JVM gives us a lot of benefits such as the following:
Reliability and performance: Java is used by 10 out of 10 top websites we have
currently, like Netflix, Apple, Uber, Twitter, Yahoo, eBay, Yelp, LinkedIn, Google,
Amazon, and many others. JVM is the best solution at scale and is battle-tested by these
web-scale companies.
Native JVM eco-system: Full access to all of the Java ecosystem including frameworks,
libraries, servers, and tools.
Operations leverage: Your operation team can run Scala in the same way they run Java.
Legacy code leverage: Scala allows you to easily integrate Scala code with Java code.
This feature is great because it enables Java legacy system integration inside the box.
Java interoperability: A code written in Scala can be accessed in Java.
Scala was created in 2001 at EPFL by Martin Odersky. Scala is a strong static-typed language,
and was inspired by another functional language called Haskell. Scala addresses several
criticisms of the Java language, and delivers a better developer experience through less code
and more concise programs, without losing performance.
Scala and Java share the same infrastructure as the JVM, but in terms of design, Scala is a
different language in comparison with Java. Java is an imperative object-oriented language
and Scala is a post-functional, multiparadigm programing language. FP works with different
principles than object-oriented programing (OOP). OOP got very popular and well
established in enterprise thanks to languages like Java, C#, Ruby, and Python. However,
languages like Scala, Clojure, F#, and Swift are gaining a huge momentum, and FP has grown
a lot in the last 10 years. Most of the new languages are pure functional, post-functional, or
hybrid (like Java 8). In this book, you will see Scala code compared with Java code so you
can see by yourself how Scala is way more compact, objective, and direct than Java and
imperative OOP languages.
FP started at academia and spread to the world; FP is everywhere. Big Data and Stream
processing solutions like Hadoop and Spark (built on top of Scala and Akka) are built on top
of FP ideas and principles. FP spread to UI with RxJavaScript - you can even find FP in a
database with Datomic (Clojure). Languages like Clojure and Scala made FP more practical
and attractive to enterprise and professional developers. In this book, we will be exploring
both principles and practical aspects of the Scala language.
Principles of functional programming
FP is a way of thinking, a specific style of constructing and building programs. Having an FP
language helps a lot in terms of syntax, but at the end of the day, it's all about ideas and
developer mindset. FP favors disciplined state management and immutability in a declarative
programming way rather than the imperative programming mostly used by OOP languages
such as Java, Python, and Ruby.
FP has roots in math back to Lambda calculus - a formal system developed in the 1930s.
Lambda calculus is a mathematical abstraction and not a programming language, but it is easy
to see its concepts in programming languages nowadays.
Imperative programming uses statements to change the program state. In other words, this
means you give commands to the program to perform actions. This way of thinking describes
a sequence of steps on how the program needs to operate. What you need to keep in mind is
the kind of style focus on how FP works in a different way, focusing on what the program
should accomplish without telling the program how to do it. When you are coding in FP, you
tend to use fewer variables, for loops, and IFS, and write more functions and make function
composition.
Higher-order functions are related to First-class functions, but they are not the same thing.
Higher-order functions often means language support for partial functional application and
Currying. Higher-order functions are a mathematical concept where functions operate with
other functions.
Partial functions are when you can fix a value (argument) to a particular function, which you
may or may not change later on. This is great for function composition.
Once you've downloaded Java, we need to add Java to the PATH variable; otherwise, you can
use the terminal. We do this as follows:
$ cd ~/
$ wget --no-cookies --no-check-certificate --header "Cookie:
gpw_e24=https%3A%2F%2Fptop.only.wip.la%3A443%2Fhttp%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-
cookie" "
http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jdk-8u77-linux-
i586.tar.gz"
$ tar -xzvf $ jdk-8u77-linux-x64.tar.gz
$ rm -f jdk-8u77-linux-x64.tar.gz
The next step is to create the environment variable called JAVA_HOME, and to put the Java 8
binaries in the PATH variable. In Linux, we need to edit the ~/.bashrc file, and export the
variables we need, like in the following:
export JAVA_HOME=~/jdk1.8.0_77
export PATH=$PATH:$JAVA_HOME/bin
Save the file, and then on the same terminal we need to source the file via $ source
~/.bashrc
Now we can test our Java 8 installation. Just type in $ java -version. You should see
something like the following:
$ java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) Server VM (build 25.77-b03, mixed mode)
Let's get started. We will be using the latest Scala version 2.11.8. However, the code inside this
book should work with any Scala 2.11.x version. First of all, let's download Scala from
http://www.scala-lang.org/.
Scala works on Windows, Mac, and Linux. For this book, I will show how to use Scala on
Ubuntu Linux(Debian-based). Open your browser and go to http://www.scala-
lang.org/download/.
Download scala 2.11.8: it will be a TGZ file. Extract it and add it to your path; otherwise,
you can use the terminal. Do this as follows:
$ cd ~/
$ wget http://downloads.lightbend.com/scala/2.11.8/scala-2.11.8.tgz
$ tar -xzvf scala-2.11.8.tgz
$ rm -rf scala-2.11.8.tgz
The next step is to create the environment variable called SCALA_HOME, and to put the Scala
binaries in the PATH variable. In Linux, we need to edit the ~/.bashrc file and export the
variables we need, like in the following:
export SCALA_HOME=~/scala-2.11.8/
export PATH=$PATH:$SCALA_HOME/bin
Save the file, and then, on the same terminal, we need to source the file via $ source
~/.bashrc.
Now we can test our Scala installation. Just type in $ scala -version. You should see
something like the following:
$ scala -version
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL
You have successfully installed Java 8 and Scala 2.11. Now we are ready to start learning the
FP principles in Scala. For this, we will be using the Scala REPL in the beginning. Scala REPL
is bundled with the default Scala installation, and you just need to type $ scala in your
terminal as follows:
$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help.
scala>
Scala REPL
Scala is a hybrid language, which means it is object-oriented and functional as well. You can
create classes and objects in Scala. Next we will create a complete Hello World application
using classes.
Scala object-oriented HelloWorld program
We will see how to create object-oriented HelloWorld program in Scala REPL as follows:
$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help.
scala> object HelloWorld {
| def main(args:Array[String]) = println("Hello World")
| }
defined object HelloWorld
scala> HelloWorld.main(null)
Hello World
scala>
The first thing you need to realize is that we use the word object instead of class. The Scala
language has different constructs compared to Java. Object is a singleton in Scala. It's the
same as coding the singleton pattern in Java.
Next we see the word def that is used in Scala to create functions. In the preceding program,
we create the main function similar to the way we do it in Java, and we call the built-in
function println in order to print the String Hello World. Scala imports some Java objects
and packages by default. Coding in Scala does not require you to type, for instance,
System.out.println("Hello World"), but you can if you want. Let's take a look at it in the
following code:
$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help.
scala> System.out.println("Hello World")
Hello World
scala>
We can and we will do better. Scala has some abstractions for a console application, so we can
write this code with a lesser number of lines of code. To accomplish this goal, we need to
extend the Scala class App. When we extend from App, we perform inheritance and we don't
need to define the main function. We can just put all the code in the body of the class, which is
very convenient and makes the code clean and simple to read.
Random documents with unrelated
content Scribd suggests to you:
pertinent to record two things that have come to my notice since.
One is that in rereading Faye’s “Origine du Monde,” I came upon a
passage in which it appears that M. Blandet had actually consulted
Faye about his hypothesis, and that Faye had shown him its
impossibility on much the same grounds as those above referred to;
which, however, did not deter M. Blandet from giving it to the world
nor De Lapparent from god-fathering the conception.
Faye, meanwhile, developed his theory of the origin of the world,
and by it explained the greater heat and lesser light of paleologic
times compared with our own, thus: The Earth evolved before the
Sun. In paleologic times the Sun was still of great extent,—an
ungathered-up residue of nebula that had not yet fallen together
enough to concentrate, not a contracting mass from which the
planets had been detached,—and was in consequence but feebly
luminous and of little heating effect; so that there were no seasons
on Earth and no climatic zones. The Earth itself supplied the heat
felt uniformly over its whole surface.
This differs from my conception, as the reader will see presently,
in one vital point—as to why the Earth was not heated by the Sun.
In the first place Faye’s sun has no raison d’être; and in the second
no visible means of existence. If its matter were not already within
the orbit of the Earth at the time, there seems no reason why it
should ever get there; and if there, why it should have been so loath
to condense. We cannot admit, I think, any such juvenility in the Sun
at the time the Earth was already so far advanced as geology shows
it to have been in paleologic times. For the Earth had already cooled
below the boiling-point of water.
Tree fern.
Mars.
NORTH POLAR CAP. SOUTH POLAR CAP.
At maximum full extent of white At maximum white
At minimum inner circle At minimum nothing
Now it so happens that these astronomic conditions affecting the
Earth several thousand years ago, are in process of action on one of
our nearest planetary neighbors at the present time. The orbit of
Mars is such that its present eccentricity is greater than what the
Earth ever can have had, and the winter solstice of the planet’s
southern hemisphere falls within 23° of its aphelion point. We have
then the conditions for glaciation if these are the astronomic ones
supposed, and we should expect a southern polar cap, larger at its
maximum and still more so, relatively, at its minimum, than in the
opposite hemisphere. Let us now look at the facts, for we have now
a knowledge of the Martian polar caps exceeding in some respects
what we know of our own. The accompanying diagrams exhibit the
state of things at a glance, the maximum and minimum of each cap
being represented in a single picture and the two being placed side
by side. It will be observed that the southern cap outdoes its
antipodal counterpart at its maximum, showing that the longer,
colder winter has its effect in snow or hoar-frost deposition. But, on
the other hand, instead of excelling it at its minimum, which it
should do to produce permanent glaciation, it so far falls short of its
fellow that during the last opposition at which it could be well
observed, it disappeared entirely. The short, hot summer, then, far
exceeded in melting capacity that of the longer but colder one.
Let us now suppose the precipitation to be increased, the winters
and summers remaining both in length and temperature what they
were before. The amount of snow which a summer of given length
and warmth can dispose of is, roughly speaking, a definite quantity.
For it depends to a great extent only on its amount of heat. The
summer precipitation may be taken as offsetting itself in the two
hemispheres alike. If, then, the snowfall in the winter be for any
reason increased daily in both, a time will come when the deposition
due the longer winter of the one will exceed what its summer can
melt relatively to the other, and a permanent glaciation result in the
hemisphere so circumstanced. Increased precipitation, then, not
eccentricity of orbit, is the real cause of an Ice Age. And this
astronomic deduction we owe not to theoretic conclusions, for which
we lack the necessary quantitative data, but wholly to study of our
neighbor in space. Had any one informed our geologic colleagues
that they must look to the sky for definite information about the
cause of an Ice Age, they would probably have been surprised.
With this Martian information, received some years ago, it is
pleasing now to see that Earthly knowledge is gradually catching up.
For that increased precipitation could account for it, the evidence of
pluvial eras in the equatorial regions, contemporaneous with glacial
periods, indicates. But another and probably the chief factor involved
was not a generally increased precipitation, potent as that would be,
but an increased snow deposit due to temporary elevation of the
ground.
E
VERYTHING around us on this Earth we see is subject to one
inevitable cycle of birth, growth, decay. Nothing that begins but
comes at last to end. Not less is this true of the Earth as a
whole and of each of its sister planets. Though our own lives are too
brief even to mark the slow nearing to that eventual goal, the past
history of the Earth written in its rocks and the present aspects of
the several planets that circle similarly round the Sun alike assure us
of the course of aging as certainly as if time, with all it brings about,
passed in one long procession before our very eyes.
Death is a distressing thing to contemplate under any
circumstances, and not less so to a philosopher when that of a
whole world is concerned. To think that this fair globe with all it has
brought forth must lapse in time to nothingness; that the
generations of men shall cease to be, their very records obliterated,
is something to strike a chill into the heart of the most callous and
numb endeavor at its core. That æons must roll away before that
final day is to the mind of the far-seeing no consolation for the end.
Not only that we shall pass, but that everything to show we ever
were shall perish too, seems an extinction too overpowering for
words.
But vain regret avails not to change the universe’s course. What
is concerns us and what will be too. From facing it we cannot turn
away. We may alleviate its poignancy by the thought that our
interest is after all remote, affecting chiefly descendants we shall
never know, and commend to ourselves the altruistic example so
nobly set us by doctors of medicine who, on the demise of others at
which—and possibly to which—they have themselves assisted, show
a fortitude not easily surpassed, a fortitude extending even to their
bills. If they can act thus unshaken at sight of their contemporaries,
we should not fall behind them in heroism toward posterity.
Having in our last chapter run the gantlet of the geologists, we
are in some sort fortified to face death—in a world—in this. The
more so that we have some millenniums of respite before the
execution of the decree. By the death of a planet we may designate
that stage when all change on its surface, save disintegration,
ceases. For then all we know as life in its manifold manifestations is
at an end. To this it may come by many paths. For a planet, like a
man, is exposed to death from a variety of untoward events.
Of these the one least likely to occur is death by accident. This,
celestially speaking, is anything which may happen to the solar
system from without, and is of the nature of an unforeseen
catastrophe. Our Sun might, as we remarked, be run into. For so far
as we know at present the stars are moving among themselves
without any too careful regard for one another. The swarm may be
circling a central Sun as André states, but the individual stars behave
more like the random particles of a gas with licensed freedom to
collide; whereas we may liken the members of the solar system to
molecules in the solid state held to a centre from which they can
never greatly depart. Their motions thus afford a sense of security
lacking in the universe at large.
Such an accident, a collision actual or virtual with another sun,
would probably occur with some dark star; of which we sketched the
ultimate results in our first chapter. The immediate ones would be of
a most disastrous kind. For prefatory to the new birth would be the
dissolution to make such resurrection possible. Destruction might
come direct, or indirectly through the Sun. For though the Sun would
be the tramp’s objective point, we might inadvertently find ourselves
in the way. The choice would be purely academic; between being
powdered, or deorbited and burnt up.
So remote is this contingency that it need cause us no immediate
alarm, as I carefully pointed out. But so strong is the instinct of self-
preservation and so pleasurable the sensation of spreading appalling
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookgate.com