Get How JavaScript Works: Master the Basics of JavaScript and Modern Web App Development 1st Edition Jonathon Simpson free all chapters
Get How JavaScript Works: Master the Basics of JavaScript and Modern Web App Development 1st Edition Jonathon Simpson free all chapters
com
https://ebookmeta.com/product/how-javascript-works-master-
the-basics-of-javascript-and-modern-web-app-development-1st-
edition-jonathon-simpson-2/
OR CLICK BUTTON
DOWLOAD NOW
https://ebookmeta.com/product/how-javascript-works-master-the-
basics-of-javascript-and-modern-web-app-development-1st-edition-
jonathon-simpson/
https://ebookmeta.com/product/the-modern-web-multi-device-web-
development-with-html5-css3-and-javascript-1st-edition-gasston-
peter/
https://ebookmeta.com/product/javascript-for-modern-web-
development-building-a-web-application-using-html-css-and-
javascript-1st-edition-alok-ranjan-abhilasha-sinha-ranjit-
battewad/
https://ebookmeta.com/product/javascript-frameworks-for-modern-
web-development-2nd-edition-sufyan-bin-uzayr/
JavaScript for Web Developers: Understanding the Basics
1st Edition Mark Simon
https://ebookmeta.com/product/javascript-for-web-developers-
understanding-the-basics-1st-edition-mark-simon/
https://ebookmeta.com/product/building-web-applications-with-net-
core-2-1-and-javascript-leveraging-modern-javascript-frameworks-
second-edition-philip-japikse/
https://ebookmeta.com/product/modern-web-development-with-deno-
develop-modern-javascript-and-typescript-code-with-svelte-react-
and-graphql-1st-edition-mayur-borse/
https://ebookmeta.com/product/connecting-arduino-to-the-web-
front-end-development-using-javascript-indira-knight/
https://ebookmeta.com/product/javascript-frameworks-for-modern-
web-dev-1st-edition-tim-ambler-nicholas-cloud/
Jonathon Simpson
This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.
The publisher, the authors, and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
1. Introduction to JavaScript
Jonathon Simpson1
(1) Belfast, Antrim, UK
JavaScript Fundamentals
JavaScript is based on a language standard called ECMAScript. How
JavaScript should exactly work is documented in a specific standard
called ECMA-262. Since ECMAScript does not provide any tools to
compile JavaScript, every implementation of JavaScript creates its own
version of JavaScript. That includes your browser and back-end
compilers like Node.js.
For the most part, these implementations follow ECMA-262, but
since each implementation is done by different teams, there can be
some minor discrepancies or different feature sets depending on the
browser or implementation.
In this chapter, we will be covering how you can set yourself up to
start using JavaScript, including how to set up JavaScript projects when
using Node.js. In future chapters, we will explore how to write
JavaScript code.
You’ll see that no types are defined here. For example, we did not
have to mention that "Some String" was a String. JavaScript
determines types based on context – so it will take x to be a String
simply because we put its value in quotation marks. Similarly, it will
dynamically interpret y as being of type Number since it lacks
quotation marks and z as being of type Boolean since it has no
quotation marks and uses the keyword false.
This makes JavaScript quite easy to pick up, but quite hard to
master. The lack of strong typing can mean that you unknowingly create
bugs in your software since JavaScript will not always throw errors if
unexpected types show up, and even worse, JavaScript may dynamically
interpret types incorrectly in some cases.
For more complex applications with lots of test cases, developers
often reach for TypeScript instead of JavaScript for this reason.
TypeScript is JavaScript, but extended. It’s strongly typed, meaning
types must be mentioned in your code.
Writing JavaScript
JavaScript on the front end is found inside HTML on web pages. As such,
familiarity with HTML is quite important when we work with
JavaScript. To create your first file containing JavaScript, you can start
by making a .html file. We usually call the home page of a website
index.html when building websites, so for this example, I created a
new HTML file called index.html.
.html files can be opened by any web browser, such as Google
Chrome. You can edit your HTML file by opening it up in a text or code
editor (Notepad included), and puting in this standard “boilerplate”
HTML:
<!DOCTYPE html>
<html>
<head>
<title>My First JavaScript</title>
</head>
<body>
<p>Hello World</p>
<script type=”text/javascript”>
// This is JavaScript!
</script>
</body>
</html>
Note You can use any text editor (like Notepad) to create HTML
and even JavaScript. While that works fine, it’s better to use a
professional code editor instead. One of the most popular code
editors used in the software development community is VS Code.
You can download it via https://code.visualstudio.com/.
This will color code your JavaScript and give you a lot of other useful
features.
<script type="text/javascript">
// This is JavaScript!
</script>
Since JavaScript applications can get quite long, you may see this
<script> tag substituted out for a file instead. This can be useful
since it lets us separate our HTML and JavaScript into different files.
For example, if we had a separate JavaScript file called
myScript.js stored in the same folder as index.html file, we
could load that into our HTML document by using the src attribute on
the script tag:
<script src="myScript.js"></script>
You may also see JavaScript embedded into HTML via the attributes
of HTML tags. For example, JavaScript can be put inside a button to
cause something to happen when a user clicks that button:
Then you can execute this file by using the node command in
terminal:
node index.js
Figure 1-3 Running a JavaScript script from the command line is as simple as using the “node”
command followed by the directory link to the file you want to run
Note If you saved your index.js file in another directory, you will
need to provide the full directory link. To navigate directories, use
the cd command. For example, if your index.js file was in
“/Users/JohnDoe/Documents/”, you would run cd
/Users/JohnDoe/Documents/ and only after that, run node
index.js.
Node.js applications like this are frequently used to create APIs,
which we will cover in much more detail later in the book.
Creating Node.js JavaScript Projects
In the above example, we executed a single file using Node.js It is more
common, though, to create a Node.js project when you start something
new in Node.js. This is also done via terminal or the cmd. The first step
is to make a new folder and navigate to it using the cd command.
In this example, I made a folder called “node-project” on my desktop
and navigated to it using the following command in Terminal:
cd ~/Desktop/node-project
After that’s done, you can use the npm init command, which is
installed along with Node.js, to initiate your project. You can see how
that looks in Figure 1-4.
Figure 1-4 When using the npm init command, you will be asked to enter some information
about your new project as shown earlier
All you have to do now is type in answers to each question and
press enter. For example, the first question asks what you want to call
your project – so type in the name of your project, and press enter.
Your folder will now contain a package.json file summarizing
the information you provided. Since you’ve initialized your Node.js
project, you’ll now be able to run other commands like npm install
now, which lets you install third party dependencies.
JavaScript Support
Traditional software is usually written by a developer and downloaded
onto a user’s computer or device. This is the case with things like video
games, apps on your phone, or big applications like Adobe Photoshop.
When writing code in JavaScript, things are very different. The
software the user installs is the browser, not your website! The browser
then loads your web page within it. Since everyone has their own
browser preference, and not everyone keeps their browsers up to date,
JavaScript that works in one browser can oftentimes not work in
another. For example, Firefox may support a new JavaScript feature, but
Chrome may not. The worst thing about this is you can’t really use a
new JavaScript feature on the front end until a majority of browsers
have implemented it.
If you are coming from other languages, then worrying about
browser support will be a foreign concept to you. In JavaScript, it is a
real thing. In recent times, since most browsers are “evergreen”
(meaning they auto-update), this has become less of a problem than it
used to be, but sometimes different browsers just disagree on what
should and shouldn’t be implemented. Promising new features may end
up implemented in just Chrome, just Safari, or just Firefox.
Throughout this book, we’ll only be looking at JavaScript with broad
browser support, meaning you don’t need to worry about if you can or
can’t use it. However, when you start exploring JavaScript in your own
time, and especially when looking at more advanced functionality, it’s
important to check if browsers support it. You can find good browser
support tables on websites like https://caniuse.com/ or
https://developer.mozilla.org/.
An example of a browser support table can be found in Figure 1-5,
for the GPU feature.
Figure 1-5 Not all browsers support every new JavaScript feature. In the preceding example,
only Chrome and Edge have support. Other browsers only have partial support or none at all.
That means if you tried to implement this on a website, only some users could use it!
Summary
In this chapter, we’ve looked at how to set up your workspace to begin
writing code with JavaScript. We’ve discussed what JavaScript is
typically used for and some of the pitfalls or differences between it and
other languages. Now that we’ve covered the basics let’s look at how to
write JavaScript code.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
J. Simpson, How JavaScript Works
https://doi.org/10.1007/978-1-4842-9738-4_2
Getting Started
As we go through this chapter, it will be good to have a work space
where you can write and test your JavaScript. For these purposes, I’ve
created a folder called “javascript-project” in my documents
folder. Within that, I have created two files – index.html and
index.js.
Since our focus will be writing JavaScript, your HTML file can be
relatively simple:
<!DOCTYPE html>
<html>
<head>
<title>My First JavaScript</title>
</head>
<body>
<p>Hello World</p>
<script src="index.js"></script>
</body>
</html>
Any JavaScript code you want to try out can be put in index.js.
For now, I’ve only put a simple console.log method:
console.log("Hello World!")
Figure 2-1 Right-clicking in the web browser and selecting “Inspect” in Google Chrome (or
other browsers) allows you to access the console log. If you do this with the index.html file we
defined before, you’ll see “Hello World!” written here. The console is a powerful tool used for
debugging. When we use the console.log method, it shows up here!
Semicolons
For readability, JavaScript is sometimes written with a semicolon at the
end of each line. For example:
console.log("Hello World!");
console.log("Goodbye World!");
However, this is not necessary, and it’s also just as common to see
the same code written without semicolons:
console.log("Hello World!")
console.log("Goodbye World!")
console.log(5 +
6)
For the code in this book, we will be omitting the semicolon unless
it is really needed.
Spacing
One of the most vigorously fought over code conventions is whether to
use tabs or spaces for indenting. While there is essentially no right or
wrong answer to this, it is important to be consistent. If you use tabs,
then always use tabs for indents and likewise for spaces.
Unlike Python, indents play no functional role in JavaScript, but they
do serve to make your code more readable when others look at it.
While it is certainly fine to use tabs, spaces are going to cause you less
of a headache. That’s because different ecosystems and operating
systems can be configured to handle tabs differently, whereas spaces
are consistently sized across all systems.
In this book, we will indent with four spaces. Here is an example of
how that will look:
let myVariable = 5
if(myVariable === 5) {
console.log("The variable is 5!")
}
Note If you use the tab key instead of spaces in VS Code to indent
your code, you can configure VS Code to automatically convert these
to spaces if you want it to. The configuration option is found by
opening any file and selecting the “Spaces/Tab Size” option in the
bottom right-hand corner.
JavaScript Variables
As we begin writing JavaScript, the first thing you’re going to need to
learn about are variables. Variables are a way to assign a fixed name to
a data value. There are three ways to create a variable in JavaScript,
using three different keywords:
var
let
const
All JavaScript variables are case-sensitive, so myVariable is
different from MYVARIABLE. In JavaScript nomenclature, we
usually say that we “declare” variables.
let myVariable = 5
console.log(myVariable)
Note It may seem like we are putting data into the variable, but a
better way to think about it is we are making data and then pointing
the keyword “myVariable” at the data we just made.
It’s not possible to assign a variable with let twice. If you think of your
variable as pointing to some data, it’s easy to see why – the same
variable can’t point to two different pieces of data. For example, the
following code will produce the error, which is shown in Figure 2-2.
let myVariable = 5
let myVariable = 10
console.log(myVariable)
Figure 2-2 Variables defined with let cannot be defined multiple times. If you try to, it will
produce an error like the preceding one
let myVariable = 5
myVariable = 10
console.log(myVariable)
It may seem like the data has changed (or “mutated”), but actually
we’ve just made new data somewhere and pointed our variable to that
instead. The data “5” still exists somewhere. It just has no variable
pointing to it anymore. When a piece of data is no longer referenced in
our code, JavaScript may remove it from memory using something
called “garbage collection.” This allows JavaScript to free up memory
when data is no longer used.
let myVariable = 5
{
let myVariable = 10
console.log(myVariable)
}
console.log(myVariable)
Figure 2-3 While using let, our console produces two different lines, 5 and 10. This is
because let is assigned to its current scope – so setting myVariable to 10 in a separate scope
does not affect the original variable. If we used var instead, both lines would say 10 since
scope is ignored
Setting Variables with var
Most variables are set with let, but you may also see the keyword var
being used to set variables sometimes. Using var is the original way to
set variables in JavaScript. It is valuable to know this exists, but it is
generally not recommended that you use it over let.
Setting a variable with var looks a lot like what we did with let.
For example, here is a variable called myVariable, with a value of 5:
var myVariable = 5
The reason why we use let rather than var is because var has a
few quirks that let does not. For example, you can define a variable
twice with var, and no errors will be thrown:
var myVariable = 5
var myVariable = 10
console.log(myVariable)
Variables defined with var are also not block-scoped, meaning your
code can produce some odd results when redefining variables in block
scopes with var.
You may be wondering, “Why does JavaScript have two ways of
defining variables when let is a more controlled version of var?” The
answer to that is pretty simple, and it’s because var used to be the only
way to define variables in JavaScript, and a lot of legacy code uses it.
Later on, JavaScript created a better way to define variables using let,
but var couldn’t be removed since it would break many older code
bases.
let myVariable = 5
myVariable = 10
console.log(myVariable)
const myConst = 5
console.log(myConst)
const myConst = 5
myConst = 10
console.log(myConst)
Using const to define variables is better when you’re able to use it.
To understand why, you can think about the example we
discussed earlier where we used let to reassign a variable from “5” to
“10”. We talked about how the value “5” still exists in memory unless it
gets garbage collected. Since const variables cannot be changed,
garbage collection never has to run. That means less cleanup is
required, resulting in more efficient memory utilisation.
Arrays can contain a lot of data, and we can push new data to an
array using a special method called push:
let myVariable
console.log(myVariable)
This is sometimes done when a variable does not have a value when
you declare it but may be assigned a value later on in the code. When
many variables need to be declared without values, they can be
separated by commas. In the following example, we define three
variables with the let keyword:
Assignment Operators
Now that we’ve covered the basics of setting variables, let’s look at
assignment operators. These allow us to modify an existing variable, by
changing its value. For example, consider this variable:
let x = 5
let x = 5
x *= 5
console.log(x) // Console logs 25 (5 multiplied by
5 = 25)
There are many other assignment operators. They are shown in the
following example:
let x = 5
x *= 5
console.log(x) // Console logs 25 (5 multiplied by
5 = 25)
x += 5
console.log(x) // Console logs 30 (25 plus 5 = 30)
x /= 5
console.log(x) // Console logs 6 (30 divided by 5
= 6)
x -= 1
console.log(x) // Console logs 5 (6 minus 1 = 5)
x %= 4
console.log(x)
/*
Console logs 1 (if you divide 5 by 4, the
remainder is 1.
% is the remainder operator
*/
Variable Concatenation
When we have variables that consist of at least one string, using the +
operator causes the strings to become concatenated. To understand
this, take a look at the following example, where we concatenate two
strings into a new variable:
// "hello world"
let combine = myVariable + " " + myOtherVariable
Just be careful, since if you try to use a + with numbers, it will add
them up instead!
let myVariable = 5
let myOtherVariable = 5
Template Literals
Another final way to concatenate more elegantly is through a type of
functionality called template literals. Template literals are still strings,
but they use the backtick "`" to transform any content into a template
literal. Template literals have the added benefit of allowing line breaks
– something that numbers and quotation marks do not. They also allow
for substitution. Here is an example of a particularly messy template
literal with line breaks throughout:
JavaScript Comments
You may have already noticed that in the preceding code, I used double
slashes to leave some comments on what the code does. As our code
gets more complicated, it’s useful to leave messages to yourself or other
developers about what is going on. For this purpose, comments are
used.
A comment in JavaScript can take one of two forms. The first looks
like this:
// I am a comment!
And the second looks like this, where the comment is enclosed in /*
and */:
/* I am a comment! */
Both work the same, but the second allows for multiline comments.
Comments have no bearing on the functionality of your code and
instead can provide useful information on what’s going on. For
example, we could comment our previous code like so:
Logical Statements
Now that we’ve covered variables, you’ll probably be wondering how
we can use them. Logical statements are one of the ways we can start to
put our variables to good use.
Logical statements are used when we want to check if something is
true or false and then run a particular action based on that outcome. If
a logical statement is found to be true, everything within its “block
scope” is executed. Likewise, if a logical statement is false, then the
block scope will never run at all. In other words, logical statements
allow us to build conditionality into our programs.
If…else Statements
if...else are perhaps one of the most commonly used logical
statements around. All they do is check if a statement is true. If it is,
they run some code, else, they run some other code. In the following
example, we check if myVariable is set to 5. If it is, we show “The
variable is 5!” in the console. If it’s not, then we show alternative text.
You can view this code running in Figure 2-4, where I run it directly
from the console in my web browser. You could also try this out by
updating your index.js file from earlier:
if(myVariable === 5) {
console.log("The variable is 5!")
}
else {
console.log("The variable is not 5.")
}
Figure 2-4 Since myVariable is 5, the statement myVariable === 5 is always true. So the
block of code within the first if statement is executed, and the else statement never fires
if(myVariable === 5) {
console.log("The variable is 5!")
}
else if(myVariable === 6) {
myVariable = 7
console.log("The variable is 6, but I set it
to 7!")
}
else {
console.log("The variable is not 5.")
}
As you can see in the else if condition, any code can be written
in the block scope created by a logical statement. In else if, we
reassigned myVariable to have a value of 7.
If the output of an if statement is one line of code, you can omit the
curly brackets and write it all on one line of code as shown in the
following example. This also applies to else if and else:
Switch Statements
Another common way to create conditionality in your JavaScript is
through switch statements. They take a single variable and check if it
equals certain values using the case keyword to define the value it
might equal and a break to declare the end of that clause. For
example:
// Let's set x to 5
let x = 5
switch(x) {
case 5:
console.log("hello")
break
case 6:
console.log("goodbye")
break
}
// Let's set x to 5
let x = 5
switch(x) {
case 4:
console.log("4!")
case 5:
console.log("hello")
case 6:
console.log("goodbye")
}
Another Random Document on
Scribd Without Any Related Topics
The Project Gutenberg eBook of Trouble
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Title: Trouble
Illustrator: Swenson
Language: English
CHECK!
"Let him try that one, will he?" laughed Tom. The move was basic; in
checking the king and menacing the queen simultaneously, Tom had
—or would upon the next move—collect himself his opponent's queen
with no great loss.
At the shirt and necktie stage, Tom Lionel stood teetering on his heels
before the bookcase on the right of the fireplace. He took from the
case a slim volume and read the title with considerable distaste:
"Theory of Monomolecular Films in Fission-Reaction"
By A. G. Rodan, Ph.D., M.M., LL.D.
"Yipe!" exploded Tom as he opened the book and glanced at the
price: $9.50. With ease he prorated the price against the thickness of
the volume and came to the estimate that the book had cost
approximately nineteen dollars per inch excluding covers. He riffled
through the pages and paused here and there to read, but the pages
themselves were a good average of four lines of text to the rest of the
page full of nuclear equations.
Tom Lionel snorted. He ran down through one of the arguments and
followed it to conclusion.
"Why can't he get something worth reading?" he yawned, putting the
book back in its place. "Darned impractical stuff." As usual with a man
who spends much time in his own company, Tom Lionel talked aloud
to himself—and occasionally was known to answer himself back.
"The whole trouble with the entire tribe of physicists per se is the fact
that once, someone told one of them that he was a theorist, an
idealist, and a dealer in the abstract. Now the bunch of them are
afraid to do anything practical because they're afraid if they do,
people won't know they're physicists. Physicists are a sort of
necessary, end-product evil."
During the breakfast section of Tom's morning duties, Tom read the
latest copy of the "Proceedings of the I.R.E." with some relish. A
paper on the "Crystallographic Generation of Microwaves" complete
with plainly manipulated differential calculus and engineering data
occupied most of his time. The rest of the time through coffee he was
making marks on the tablecloth with the egg-laden end of his fork and
trying to fit the crystallographic generation of microwaves into a
problem that made the article most timely; the solution for which he
had been seeking for a week.
The mail arrived. Three household bills were filed in the desk to await
the first of the month. Two advertisements were filed into the
wastebasket. One thick letter addressed to Thomas Lionel, Ph.D.,
M.M., was taken carefully between thumb and forefinger and
deposited in a letter file.
Tom then inspected the other letter file and found two letters
addressed to Tom Lionel, Consulting Engineer, which he opened and
read. One was from a concern in Cedar Rapids that wanted some
information on a method of induction heating glued joints selectively
without waiting for the normal drying time. The other was a letter from
a medium-sized town in Illinois pertaining to some difficulty they were
having with police-radio coverage of that area.
Both letters meant money, and Tom Lionel set the first aside while he
started to work on the second. From the engineering data supplied by
the local engineer, Tom decided that a change in antenna height and
a conversion from quarter-wave current fed to a one and one quarter-
wave current fed antenna would give the desired coverage. He
concluded his letter with four pages of calc, seven diagrams, and as a
last measure dropped a photograph of a similar installation in the
envelope.
He gloated. That would net him a pretty penny. The guy who hung
that antenna on top of the water tank thought he was smart, getting
all that height. But the roof was metal, and therefore the radiation
angle took off from the rooftop as a basis rather than the true ground
a hundred feet below.
The tank top was greater than three wave lengths in diameter, and
conical to boot. Tom grinned at the maze of mathematics that solved
it—and as far as he was concerned it was solved, for Tom Lionel was
a top-flight engineer.
He checked on his calendar. Metal for the sonic job was not due for a
week yet; a minute casting was still being held up for the foundry's
pleasure; and the life-test of the bearing-jewel for the Watson
Instrument Corporation was still on. Good jewel that. No sign of
freeze-up or wear-out after twenty-seven million cycles.
"Theory of Monomolecular Films be hanged," he snorted. "He's the
kind of a guy that would try to analyze the brew that MacBeth's three
witches were cooking up. And don't ask why!"
What he objected to most was the other's unconcern at spending
money. Nine bucks and fifty cents for a book of the most questionable
theory—and nine fifty that the other didn't really earn. It was getting
worse. The other was really beginning to obtrude. He hadn't minded,
particularly, except for the mental anguish. He'd become reconciled to
it by sheer rationalization. Way, way down deep in his heart he knew
that he'd have enjoyed being a physicist himself. But physicists were
not particularly practical, and money was made with practical things.
He knew, and recognized, that his retreat from being a physicist
himself had given him a dislike for the breed, especially when he
knew that solution of a problem was theirs, but reduction to practice
was his. He was continuously being forced to take some physicist's
wild-haired scheme and making it cook meat, open cans, or dig post
holes. The physicist had all the fun of standing on the threshold and
delving into phenomena that abounded just over the line. And then
instead of working on the suggestion that the physicist had located in
the wilderness, the physicist just tossed it over his shoulder into
Lionel's lap and went on digging.
Obviously it must be fun to dig in the unknown, but why in the name
of sense—
"Theory of Monomolecular Films in Fission-Reaction," scowled Tom
Lionel. "A hypothesis on a theory for an idea, based upon a practical
impossibility, and directed at a problem solvable only by concentrated
masses. He should be working in a negative universe where
nonmatter repels nonmatter disproportionately to the nonmass and
inversely disproportional to the not-square of the not-distance
between. Holy Entropy."
Tom Lionel went out of the house, mentally tinkering with the glue-
joint heating problem. That shouldn't be hard, he thought, high-
frequency heating was no trick, though the furniture company
probably had no one in the place that knew what high frequency
really meant.
He'd take a chair, rip it apart at the joints, and start tinkering with the
big radio-frequency heater in the lab. Another fat consulting fee—
eminently practical and satisfying—from the simple engineering of a
means to accelerate the drying of glue by electronics.
Eminently practi—hell!
Lionel stared. The door closed slowly behind him as he walked ever
so slowly across the floor of the lab. There was his radio-frequency
heater, all right. But it was not in its usual place. It was across the
room nuzzling up against another piece of equipment—the latter new,
shining, and absolutely alien to the lab.
Tom went over to the set-up and inspected it with critical derision.
The alien piece of equipment had been a standard model of mass
spectrograph. Its sleek sides were gaping open, and the high-
frequency heater was permanently wired—piped—into the very heart
of the spectrograph. Peering into the maze of one-inch copper tubing
that led from the output of the high-frequency heater to the insides of
the spectrograph, Lionel saw at once what the reason was.
The spectrograph had been overhauled by the physicist. It now
contained a pair of "D" chambers.
Operating on the cyclotron principle, the spectrograph was using the
output of the high-frequency heater to energize the D chambers.
Lionel nodded. The frequency was about right; could be adjusted to
the proper value without any trouble at all. He felt an infinitesimally
short twitch of admiration for the idea before he started to roar in
anguish.
His first impulse was to rip the gadget apart so that he could go to
work on something practical. But the engineer's admiration for the
idea stopped him.
But this was getting thick.
It had been getting thicker for a long time. It was getting intolerable.
He didn't mind too much having volumes of utterly cock-eyed theory
about the place, but when the physicist starts to appropriate
equipment for his screwball ideas, it was time to call a halt.
Lionel left the laboratory, returned to his house, and called a
psychiatrist.
An hour later he was in Dr. Hamilton's office.
"Why are you here?" asked Hamilton pleasantly.
"I want to get rid of a physicist."
"Tell him to go away."
"Can't. Impossible."
"Nothing is impossible."
"Look, doctor, have you ever tried to light a safety match on a wet bar
of soap?"
"Suppose you tell me about it, then."
CHECK!
and dropped it into the drawer again. He moved his king aside with a
contemplative smile. His queen was gone on the next move, he knew.
So he had lost a major piece. So that other bird thought that losing a
major piece was bad, huh? Well, winning battles does not count—it is
a matter of who wins the last one.
He found the volume on the theory of monomolecular films and
started to read with relish. Over coffee, at breakfast, Thomas made
notations on the margin of the book with a pencil; checked some of
the equations and though he found them balanced properly, the
author was amiss in not considering the lattice-effect in his
presumptions. No monomolecular film could follow that type of
reaction simply because—well, it could follow it, but since the thing
was to take place in a monomolecular film, the fission-reaction and
the radiation byproducts that cause the self-sustaining nature could
only be effective in a plane of molecular thickness. That meant a
.999999% loss, since the radiation went off spherically. Fission-
reaction might take place, but it would be most ineffective. Besides,
the equations should have taken that into account.
He stopped by the desk and wrote for a half hour, filling seventeen
pages full of text and mathematics, explaining the error in the author's
presumption.
He sealed it up and mailed it with some relish. No doubt that letter
would start a fight.
He found his letter in the letter file and read it. It was a request to
indulge in some basic research at a fancy figure, but Thomas was not
particularly interested. He was thinking of another particular line of
endeavor. He dropped the letter into the wastebasket.
He went into the lab and took a look at his cyclotronic spectrograph.
There was a letter hung on the front. Thomas opened it and read:
Dear Isaac Newton:
I don't particularly mind your laying out thirty-five hundred bucks for a
mass spectrograph.
Appropriating my high-frequency generator didn't bother me too
much.
Nor did your unsymmetrical wiring and haywire peregrinations in and
about the two of them annoy (too acutely) my sense of mechanical
and electrical precision.
But the idea of your using the ##&&%!! spectrograph only once—just
for pre-change calibration—makes me madder than mad!
Sincerely,
Tom Lionel,
Consulting Engineer
Thomas grinned boyishly and picked up the notebook on top of the
high-frequency heater. It was Tom's, and the physicist riffled through it
to the last-used pages. He found considerable in the way of notes
and sketches on the cyclotronic spectrograph. Cut in size by about
one quarter, the thing would be not only a research instrument of
value, but would be of a price low enough to make it available to
schools, small laboratories, and perhaps production-lines—if Tom
Lionel could find a use for a mass spectrograph on a production line.
Thomas grinned again. If it were possible, Tom would certainly have it
included on some production line, somewhere.
He looked the spectrograph over and decided that it was a fine piece
of apparatus. So it wasn't the shining piece of commercial panel and
gleaming meters. The high-frequency plumbing in it had the touch of
a one-thumbed plumber's apprentice after ten days' drinking and the
D plates were soldered together with a heavy hand. But it did work—
and that's all he cared. The knobs and dials he had added were
sticking out at all angles, but they functioned.
And the line-voltage ripple present in the high-frequency generator
made a particular mess out of the spectrograph separation. But
electronic heaters do not normally come luxuriously equipped with
rectifiers and filters so that the generator tubes were served with pure
direct current—the circuit was self-rectified which would give a
raucous signal if used as a radio transmitter. That generated a ripple-
varied signal for the D plates and it screwed up the dispersion. The
omission of refinement satisfied Thomas. So it wasn't perfect. It would
be by the time Tom Lionel got through with it.
And for the time being, Thomas would leave it alone. No use trying to
make it work until Tom made an engineering model out of the
physicist's experiment.
Smiling to himself, Thomas went to work in the laboratory. He ignored
Tom's experiments and started a few of his own accord.
Some hours later, the doorbell rang and Thomas went to the door to
find a letter, addressed to Thomas Lionel, Ph.D. It was from an Arthur
Hamilton, M.D.
"Hm-m-m," said Thomas. "Is there something the matter with me?"
He slit the envelope and removed a bill for consultation.
"Consultation? Consultation? What in the name of all that's unholy is
he consulting a doctor about? Or is the doctor consulting—no, the bill
is rendered in the wrong direction. I know my consulting engineer."
The physicist put on his hat and headed forth. It was not much later
that he was sitting again in the same chair, facing Hamilton.
"You're back."
"Nope," smiled Thomas. "I'm here, not back."
"But you were here last week."
"That was another fellow. Look, Hamilton, I think I require your
assistance. I have an engineer that is no end of bother."
"Want to get rid of him, huh?" answered Hamilton. The suppressed
smile fought valiantly and won, and the doctor's face beamed and
then he broke into laughter. "What am I, anyway? Man, I can't take
money from both sides. That's ... that's ... barratry, or something."
"I'm the same man."
"Nope. You are not."
"Well, by and large, I thought it might be of interest to you to hear
both sides. It might be that I am a useful citizen in spite of what the
engineer says."
"The engineer's opinion is that no physicist is worth an unprintable."
"The physicist's opinion is that all engineers are frustrated physicists."
"Might challenge him to a fight."
"Have. But chess isn't too satisfying. I want blood."
"It's your blood."
"That's the annoying part of it all. He seems entirely a different
fellow."
"The cleavage is perfect. You would think him a separate entity."
Hamilton paused, "But neither of you refer to the other by name. That
indicates a psychological block that may be important evidence."
"O.K., what do we do?"
"I must discover the reason for the split personality."
"I can give you that reason. The engineer was forced into being a
practical man because money lies in that direction. Upon getting out
of college, there was a heavy debt. It was paid off by hard work—a
habit formed and never broken. Bad habits, you know, are hard to
break."
"Interesting."
"Well, the desire to delve into the physicist's realm stayed with the
engineer, but people who had heavy purses were not interested in
new ways to measure the ether-drift or the effect of cosmic radiation
on the physical properties of carbon. Money wants more perfect
pencil sharpeners, ways of automatically shelling peas, and efficient
methods of de-gassing oil. All these things are merely applications in
practice of phenomena that some physicist has uncovered and
revealed and put on record so that some engineer can use the effect
to serve his ends.
"At any rate, the desire to be a physicist is strong, strong enough to
cause schizophrenia. I, Dr. Hamilton, am a living, breathing, talking
example that an engineer is but a frustrated physicist. He is the
troubled one—I am the stable personality. I am happy, well-adjusted,
and healthy."
"I see. Yet he has his point. You, like other physicists, are not
interested in making money. How, then, do you propose to live?"
"A physicist—or an engineer—can always make out well. The bank
account at the last sitting was something like ninety-four thousand,
six hundred seventeen dollars and thirty-four cents."
"That's quite a lot of money."
"The engineer considers it a business backlog," said Thomas.
"Equipment is costly. Ergo—see?"
"I see. Seems you laid out a large sum of money for a mass
spectrograph."
"I did."
"And what did he do?"
"He made notes on it and is going to peddle it as a commercial
product. He'll probably make fifty thousand dollars out of it."
"I suggested that," admitted the psychiatrist.
"That's all right. I don't mind. It sort of tickles me, basically. I do things
constantly that make him roar with anguish. And then his only rebuttal
is to take it and make something practical out of it."
"I see."
"That, you understand, is the game that has been going on for some
time between all physicists and engineers."
"If you'd leave one another alone, you'd all be better off," said
Hamilton. "From what I've heard, the trouble lies in the fact that
physicists are not too interested in the practical details, whilst the
engineer resents the physicist's insistance upon getting that last point
zero two percent of performance."
"Are you willing to give me my answer?"
"What answer?"
"How do I get rid of the engineer? One of us has got to go, and being
the stable, happy one, I feel that all in all I am the best adjusted and
therefore the most likely to succeed. After all, I am the ideal
personality according to the other one. He'd like to be me. That's why
he is, from time to time."
"Sort of a figment of your own imagination."
"That's me."
"Then I wonder—Yet, I did accept his case, not yours."