11:next_link: 01_values
2+ :load_files: ["js/code/00_intro.js"]
23
34= Introduction =
45
56This book is about talking to computers. Computers have become one of
67the 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
1011There is something of an inherent gap between us, squishy biological
1112organisms with a talent for social and spatial reasoning, and the
@@ -23,13 +24,14 @@ which we understand easily because they imitate the tangible world
2324outside of the machine.
2425
2526Graphical 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
3436Obviously, the touchscreen phone is more accessible, and it is
3537entirely 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
3840compose the functionality provided by the system in new ways, and even
3941to 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
4951indexsee:[web browser,browser]
52+
5053(((JavaScript,availability of)))(((browser))) This has been mostly
5154lost with the shift towards graphical user interfaces. But the
5255language-based interfaces, in the form of programming languages, are
5356still there, on every machine, largely hidden from the casual user.
5457One 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
5760This book intends to show you how to use this language to instruct a
5861computer to perform tasks for you.
@@ -92,8 +95,8 @@ piece of text typed by a programmer, it is the directing force that
9295makes the computer do what it does, it is data in the computer's
9396memory, yet it controls the actions performed on this same memory.
9497Analogies 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
97100whole thing tick we have to consider the ways in which these parts
98101interconnect and contribute to the operation of the whole.
99102
@@ -120,7 +123,8 @@ Some programmers believe that this complexity is best managed by using
120123only a small set of well-understood techniques in their programs. They
121124have composed strict rules (_“best practices”_) prescribing the form
122125programs 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
125129What hostility to the richness of programming—to try to reduce it to
126130something 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
174178could be written in English like this:
175179
180+ [source,text/plain]
181+ ----
1761821. Store the number 0 in memory location 0.
177-
1781832. 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.
1881927. Add the number 1 to the value of memory location 1.
189-
1901938. Continue with instruction 3.
191-
1921949. Output the value of memory location 0.
195+ ----
193196
194197(((naming)))(((variable)))Although that is already more readable than
195198the 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
302305document 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
304307support JavaScript were actually talking about the same language. This
305308is called the ECMAScript standard, after the organization that did the
306309standardization. In practice, the terms ECMAScript and JavaScript can
@@ -323,14 +326,14 @@ advantages, though. It leaves space for a lot of techniques that are
323326impossible in more rigid languages, and, as we will see in later
324327chapters, it can be used to overcome some of JavaScript's
325328shortcomings. 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
329332JavaScript. ECMAScript version 3 was the dominant, widely supported
330333version in the time of JavaScript's ascent to dominance, roughly
331334between 2000 and 2010. During this time, work was underway on an
332335ambitious 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
334337language in such a radical way turned out to be politically difficult,
335338and work on the 4th edition was abandoned in 2008, leading to the much
336339less ambitious 5th edition coming out in 2009. We're now just reaching
@@ -342,7 +345,7 @@ edition is underway.
342345which JavaScript is used. Some databases, such as MongoDB and CouchDB,
343346use JavaScript as their scripting and query language. Several
344347platforms 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
346349powerful environment for programming JavaScript outside of the
347350browser.
348351
@@ -378,16 +381,16 @@ code.
378381
379382endif::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
383386documentation (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-----
402405function 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+
0 commit comments