Skip to content

Commit 79516da

Browse files
committed
Correct intro chapter
1 parent 66fca78 commit 79516da

3 files changed

Lines changed: 77 additions & 53 deletions

File tree

00_intro.txt

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
:next_link: 01_values
2+
:load_files: ["js/code/00_intro.js"]
23

34
= Introduction =
45

56
This book is about talking to computers. Computers have become one of
67
the fundamental tools of our time. Being able to communicate well with
7-
your tools is a useful skill. With the right mindset, it can also be a
8-
very entertaining activity.
8+
your tools is a useful skill. And with the right mindset, it can also
9+
be a very entertaining activity.
910

1011
There is something of an inherent gap between us, squishy biological
1112
organisms with a talent for social and spatial reasoning, and the
@@ -23,13 +24,14 @@ which we understand easily because they imitate the tangible world
2324
outside of the machine.
2425

2526
Graphical interfaces tend to be easier to figure out than
26-
language-based ones—spotting a button is quicker than learning a word.
27-
For this reason, they have become the dominant way to interact with
28-
consumer-oriented systems. Compare today's phones, where you can
29-
accomplish all kinds of tasks by tapping and swiping the elements that
30-
appear on the screen, with the ((Commodore 64)) of 1982, the device
31-
that introduced me to computing, where all you get is a blinking
32-
cursor, and you're supposed to take it from there by typing commands.
27+
language-based ones—spotting a button is quicker than learning a
28+
grammar. For this reason, they have become the dominant way to
29+
interact with consumer-oriented systems. Compare today's phones, where
30+
you can accomplish all kinds of tasks by tapping and swiping the
31+
elements that appear on the screen, with the ((Commodore 64)) of 1982,
32+
the device that introduced me to computing, where all you get is a
33+
blinking cursor, and you're supposed to take it from there by typing
34+
commands.
3335

3436
Obviously, the touchscreen phone is more accessible, and it is
3537
entirely appropriate that such devices use a graphical interface. But
@@ -38,21 +40,22 @@ their language, they tend to be more expressive, by making it easy to
3840
compose the functionality provided by the system in new ways, and even
3941
to create your own building blocks.
4042

41-
(((programming language)))
42-
With the Commodore 64, almost every task in the system was
43-
accomplished by giving commands in the machine's built-in language (a
44-
((BASIC)) dialect). This allowed users to gradually progress from
45-
simply using the computer (loading in programs) to actually
46-
programming it themselves. You were _in_ a programming environment
47-
from the start, rather than having to actively look for one.
43+
(((programming language))) With the Commodore 64, almost every task in
44+
the system was accomplished by giving commands in the machine's
45+
built-in language (a dialect of the ((BASIC)) programming language).
46+
This allowed users to gradually progress from simply using the
47+
computer (loading programs) to actually programming it themselves.
48+
You were _in_ a programming environment from the start, rather than
49+
having to actively look for one.
4850

4951
indexsee:[web browser,browser]
52+
5053
(((JavaScript,availability of)))(((browser))) This has been mostly
5154
lost with the shift towards graphical user interfaces. But the
5255
language-based interfaces, in the form of programming languages, are
5356
still there, on every machine, largely hidden from the casual user.
5457
One such language, JavaScript, is available on just about every
55-
consumer device nowadays, as part of a web browser.
58+
consumer device as part of a web browser.
5659

5760
This book intends to show you how to use this language to instruct a
5861
computer to perform tasks for you.
@@ -92,8 +95,8 @@ piece of text typed by a programmer, it is the directing force that
9295
makes the computer do what it does, it is data in the computer's
9396
memory, yet it controls the actions performed on this same memory.
9497
Analogies that try to compare programs to objects we are familiar with
95-
tend to fall short. A superficially fitting one is that of a machine,
96-
since lots of separate parts tend to be involved, and to make the
98+
tend to fall short. A superficially fitting one is that of a
99+
machine—lots of separate parts tend to be involved, and to make the
97100
whole thing tick we have to consider the ways in which these parts
98101
interconnect and contribute to the operation of the whole.
99102

@@ -120,7 +123,8 @@ Some programmers believe that this complexity is best managed by using
120123
only a small set of well-understood techniques in their programs. They
121124
have composed strict rules (_“best practices”_) prescribing the form
122125
programs should have, and the more zealous among them will consider
123-
those go outside of these rules to be _bad_ programmers.
126+
those that go outside of this little safe zone to be _bad_
127+
programmers.
124128

125129
What hostility to the richness of programming—to try to reduce it to
126130
something straightforward and predictable, to place a taboo on all the
@@ -173,23 +177,22 @@ something in terms of job satisfaction.
173177
(((memory)))Each line of the program contains a single instruction. It
174178
could be written in English like this:
175179

180+
[source,text/plain]
181+
----
176182
1. Store the number 0 in memory location 0.
177-
178183
2. Store the number 1 in memory location 1.
179-
180-
3. Store the value of memory location 1 in memory location 2.
181-
182-
4. Subtract the number 11 from the value in memory location 2.
183-
184-
5. If the value in memory location 2 is the number 0, continue with instruction 9.
185-
186-
6. Add the value of memory location 1 to memory location 0.
187-
184+
3. Store the value of memory location 1 in memory
185+
location 2.
186+
4. Subtract the number 11 from the value in memory
187+
location 2.
188+
5. If the value in memory location 2 is the number 0,
189+
continue with instruction 9.
190+
6. Add the value of memory location 1 to memory
191+
location 0.
188192
7. Add the number 1 to the value of memory location 1.
189-
190193
8. Continue with instruction 3.
191-
192194
9. Output the value of memory location 0.
195+
----
193196

194197
(((naming)))(((variable)))Although that is already more readable than
195198
the soup of bits, it is still rather unpleasant. It might help to use
@@ -300,7 +303,7 @@ to try to ride along on this success. Now we are stuck with the name.
300303

301304
(((ECMAScript)))After its adoption outside of Netscape, a standard
302305
document was written to describe the way the language should work, in
303-
an effort to make sure the various piece of software that claimed to
306+
an effort to make sure the various pieces of software that claimed to
304307
support JavaScript were actually talking about the same language. This
305308
is called the ECMAScript standard, after the organization that did the
306309
standardization. In practice, the terms ECMAScript and JavaScript can
@@ -323,14 +326,14 @@ advantages, though. It leaves space for a lot of techniques that are
323326
impossible in more rigid languages, and, as we will see in later
324327
chapters, it can be used to overcome some of JavaScript's
325328
shortcomings. After learning it properly and working with it for a
326-
while, I have really learned to _like_ this language.
329+
while, I have learned to really _like_ this language.
327330

328331
(((JavaScript,versions of)))There have been several _versions_ of
329332
JavaScript. ECMAScript version 3 was the dominant, widely supported
330333
version in the time of JavaScript's ascent to dominance, roughly
331334
between 2000 and 2010. During this time, work was underway on an
332335
ambitious version 4, which planned a number of radical improvements
333-
and extensions to the langauge. Changing a living, widely used
336+
and extensions to the language. Changing a living, widely used
334337
language in such a radical way turned out to be politically difficult,
335338
and work on the 4th edition was abandoned in 2008, leading to the much
336339
less ambitious 5th edition coming out in 2009. We're now just reaching
@@ -342,7 +345,7 @@ edition is underway.
342345
which JavaScript is used. Some databases, such as MongoDB and CouchDB,
343346
use JavaScript as their scripting and query language. Several
344347
platforms for desktop and server programming, most notably the
345-
_((node.js))_ project, the subject of chapter (NODE), are providing a
348+
_((node.js))_ project, the subject of chapter (FIXME), are providing a
346349
powerful environment for programming JavaScript outside of the
347350
browser.
348351

@@ -378,16 +381,16 @@ code.
378381

379382
endif::tex_target[]
380383

381-
Running JavaScript programs outside of this book's sandbox is also far
382-
from hard. You can opt to install node.js, and read enough of its
384+
Running JavaScript programs outside of this book's sandbox is also
385+
possible. You can opt to install node.js, and read enough of its
383386
documentation (or of chapter (NODE)) to figure out how to use it to
384-
run text files that contain programs. Or you can use your browser's
385-
developer console (typically found somewhere under a “tools” or
386-
“developer” menu) and play around in there. In chapter (WEB), the way
387-
in which JavaScript programs are embedded in web pages (HTML files) is
388-
explained. In the meantime, you could head over to `http://jsbin.com`
389-
for another friendly interface for running JavaScript code in a
390-
browser.
387+
evaluate text files that contain programs. Or you can use your
388+
browser's developer console (typically found somewhere under a “tools”
389+
or “developer” menu) and play around in there. In chapter (WEB), the
390+
way in which JavaScript programs are embedded in web pages (HTML
391+
files) is explained. In the meantime, you could head over to
392+
`http://jsbin.com` for another friendly interface for running
393+
JavaScript code in a browser.
391394

392395
== Typographic conventions ==
393396

@@ -400,16 +403,22 @@ follows:
400403
[source,javascript]
401404
-----
402405
function fac(n) {
403-
return n == 0 ? 1 : n * fac(n - 1);
406+
if (n == 0)
407+
return 1;
408+
else
409+
return fac(n - 1) * n;
404410
}
405411
-----
406412

407-
Sometimes, in order to demonstrate what happens when certain
408-
expressions are evaluated, the produced value is written below, with
409-
two slashes and an arrow in front of it:
413+
Sometimes, in order to show the output that a program produces, the
414+
expected output is written below it, with two slashes and an arrow in
415+
front:
410416

411417
[source,javascript]
412418
-----
413-
1 + 1
414-
// → 2
419+
console.log(fac(8));
420+
// → 40320
415421
-----
422+
423+
Good luck!
424+

code/00_intro.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function range(start, end) {
2+
var out = [];
3+
for (var i = start; i <= end; i++) out.push(i);
4+
return out;
5+
}
6+
function sum(array) {
7+
return array.reduce(function(a, b) { return a + b; }, 0);
8+
}
9+
10+
function fac(n) {
11+
if (n == 0)
12+
return 1;
13+
else
14+
return fac(n - 1) * n;
15+
}

html/ejs.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ ol li:before {
108108
position: absolute;
109109
width: 2em;
110110
text-align: right;
111-
left: -2.5em; bottom: 0;
111+
left: -2.5em; top: 1px;
112112
font-size: 90%;
113113
}
114114

@@ -130,11 +130,11 @@ blockquote {
130130
margin: 0 0 0 2em;
131131
padding: 0;
132132
position: relative;
133+
font-size: 95%;
133134
}
134135

135136
blockquote p {
136137
color: #333;
137-
font-size: 95%;
138138
}
139139

140140
blockquote:before {

0 commit comments

Comments
 (0)