Eloquent Javascript

Page 15

art of programming is the skill of controlling complexity. The great program is subdued—made simple in its complexity. Some programmers believe that this complexity is best managed by using only a small set of well-understood techniques in their programs. They have composed strict rules (“best practices”) prescribing the form programs should have and carefully stay within their safe little zone. This is not only boring, it is ineffective. New problems often require new solutions. The field of programming is young and still developing rapidly, and it is varied enough to have room for wildly different approaches. There are many terrible mistakes to make in program design, and you should go ahead and make them so that you understand them. A sense of what a good program looks like is developed in practice, not learned from a list of rules.

Why language matters In the beginning, at the birth of computing, there were no programming languages. Programs looked something like this: 00110001 00110001 00110011 01010001 00100010 01000011 01000001 00010000 01100010

00000000 00000001 00000001 00001011 00000010 00000001 00000001 00000010 00000000

00000000 00000001 00000010 00000010 00001000 00000000 00000001 00000000 00000000

That is a program to add the numbers from 1 to 10 together and print out the result: 1 + 2 + ... + 10 = 55. It could run on a simple, hypothetical machine. To program early computers, it was necessary to set large arrays of switches in the right position or punch holes in strips of cardboard and feed them to the computer. You can probably imagine how tedious and error-prone this procedure was. Even writing simple programs required much cleverness and discipline. Complex ones were nearly inconceivable. Of course, manually entering these arcane patterns of bits (the ones and zeros) did give the programmer a profound sense of being a mighty wizard. And that has to be worth something in terms of job satisfaction. Each line of the previous program contains a single instruction. It could be

3


Turn static files into dynamic content formats.

Create a flipbook

Articles inside

Compatibility and the browser wars

0
page 231

In the sandbox

0
page 230

The standard

1min
page 234

HTML and JavaScript

1min
page 229

Exercises

4min
pages 221-223

Functions

3min
pages 218-219

The evaluator

1min
page 214

Asynchronous bugs

3min
pages 205-206

The environment

1min
page 217

Special forms

2min
pages 215-216

The event loop

1min
page 204

Generators

1min
page 203

Async functions

3min
pages 201-202

Message routing

4min
pages 198-200

Failure

3min
pages 192-193

Network flooding

1min
page 197

Networks are hard

4min
pages 194-195

Collections of promises

1min
page 196

Promises

1min
page 191

Callbacks

2min
pages 189-190

Crow tech

1min
page 188

Building and bundling

1min
page 181

ECMAScript modules

3min
pages 179-180

Improvised modules

1min
page 175

CommonJS

2min
pages 177-178

Evaluating data as code

1min
page 176

Packages

1min
page 174

Summary

3min
pages 169-170

International characters

1min
page 168

Parsing an INI file

2min
pages 166-167

Greed

1min
page 161

The lastIndex property

2min
pages 164-165

The replace method

1min
pages 159-160

Dynamically creating RegExp objects

1min
page 162

The search method

1min
page 163

Backtracking

2min
pages 157-158

Word and string boundaries

1min
page 155

The Date class

1min
page 154

Cleaning up after exceptions

3min
pages 141-142

Repeating parts of a pattern

1min
page 151

Exceptions

2min
pages 139-140

Assertions

1min
page 145

Selective catching

3min
pages 143-144

Error propagation

1min
page 138

Debugging

2min
pages 136-137

Testing

1min
page 135

Simulation

2min
pages 126-127

Types

0
page 134

Strict mode

0
page 133

Exercises

1min
page 131

Persistent data

1min
page 125

The task

2min
pages 123-124

Exercises

2min
pages 119-120

Summary

1min
page 118

Inheritance

1min
page 116

The iterator interface

2min
pages 112-113

Maps

2min
pages 108-109

Overriding derived properties

2min
pages 106-107

Class notation

1min
page 105

Classes

1min
page 104

Prototypes

2min
pages 102-103

Methods

1min
page 101

Exercises

0
page 99

Recognizing text

1min
page 97

Strings and character codes

2min
pages 95-96

Summary

1min
page 98

Composability

2min
pages 93-94

Summarizing with reduce

1min
page 92

Transforming with map

1min
page 91

Filtering arrays

1min
page 90

Exercises

3min
pages 82-84

Script data set

1min
page 89

5 Higher-Order Functions

1min
page 85

Higher-order functions

0
page 88

Summary

1min
page 81

JSON

1min
page 80

Destructuring

1min
page 79

The Math object

2min
pages 77-78

Rest parameters

1min
page 76

Strings and their properties

2min
pages 74-75

Further arrayology

1min
page 73

The final analysis

3min
pages 71-72

Array loops

0
page 70

Computing correlation

1min
page 69

The lycanthrope’s log

3min
pages 67-68

Mutability

2min
pages 65-66

Data sets

1min
page 60

Properties

1min
page 61

Objects

3min
pages 63-64

Methods

1min
page 62

Exercises

2min
pages 57-58

Summary

1min
page 56

Functions and side effects

1min
page 55

Growing functions

2min
pages 53-54

Recursion

3min
pages 50-52

Closure

1min
page 49

Optional Arguments

2min
pages 47-48

The call stack

1min
page 46

Arrow functions

1min
page 45

Declaration notation

1min
page 44

Functions as values

1min
page 43

Bindings and scopes

2min
pages 41-42

Exercises

2min
pages 38-39

Summary

1min
page 37

Dispatching on a value with switch

1min
page 35

Summary

0
page 21

Updating bindings succinctly

1min
page 34

Indenting Code

1min
page 32

while and do loops

2min
pages 30-31

Conditional execution

2min
pages 28-29

Strings

4min
pages 13-14

Bindings

3min
pages 23-24

Unary operators

1min
page 15
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.