====================
Introduction / intro
====================
When personal computers were first introduced, most of them came
equipped with a simple programming language, usually a variant of
_BASIC_. Interacting with the computer was closely integrated with
this language, and thus every computer-user, whether he wanted to or
not, would get a taste of it. Now that computers have become plentiful
and cheap, typical users don't get much further than clicking things
with a mouse. For most people, this works very well. But for those of
us with a natural inclination towards technological tinkering, the
removal of programming from every-day computer use presents something
of a barrier.
Fortunately, as an effect of developments in the World Wide Web, it so
happens that every computer equipped with a modern web-browser also
has an environment for programming JavaScript. In today's spirit of
not bothering the user with technical details, it is kept well hidden,
but a web-page can make it accessible, and use it as a platform for
learning to program.
That is what this (hyper-)book tries to do.
---
| I do not enlighten those who are not eager to learn, nor arouse those
| who are not anxious to give an explanation themselves. If I have
| presented one corner of the square and they cannot come back to me
| with the other three, I should not go over the points again.
|
| -- Confucius
Besides explaining JavaScript, this book tries to be an introduction
to the basic principles of programming. Programming, it turns out, is
hard. The fundamental rules are, most of the time, simple and clear.
But programs, while built on top of these basic rules, tend to become
complex enough to introduce their own rules, their own complexity.
Because of this, programming is rarely simple or predictable. As
Donald Knuth, who is something of a founding father of the field,
says, it is an *art*.
To get something out of this book, more than just passive reading is
required. Try to stay sharp, make an effort to solve the exercises,
and only continue on when you are reasonably sure you understand the
material that came before.
---
| The computer programmer is a creator of universes for which he alone
| is responsible. Universes of virtually unlimited complexity can be
| created in the form of computer programs.
|
| -- Joseph Weizenbaum, *Computer Power and Human Reason*
A program is many things. It is a piece of text typed by a programmer,
it is the directing force that makes the computer do what it does, it
is data in the computer's memory, yet it controls the actions
performed on this same memory. Analogies that try to compare programs
to objects we are familiar with tend to fall short, but a
superficially fitting one is that of a machine. The gears of a
mechanical watch fit together ingeniously, and if the watchmaker was
any good, it will accurately show the time for many years. The
elements of a program fit together in a similar way, and if the
programmer knows what he is doing, the program will run without
crashing.
A computer is a machine built to act as a host for these immaterial
machines. Computers themselves can only do stupidly straightforward
things. The reason they are so useful is that they do these things at
an incredibly high speed. A program can, by ingeniously combining many
of these simple actions, do very complicated things.
To some of us, writing computer programs is a fascinating game. A
program is a building of thought. It is costless to build, weightless,
growing easily under our typing hands. If we get carried away, its
size and complexity will grow out of control, confusing even the one
who created it. This is the main problem of programming. It is why so
much of today's software tends to crash, fail, screw up.
When a program works, it is beautiful. The art of programming is the
skill of controlling complexity. The great program is subdued, made
simple in its complexity.
---
Today, many 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 about the form programs
should have, and the more zealous among them will denounce those who
break these rules as *bad* programmers.
What hostility to the richness of programming! To try to reduce it to
something straightforward and predictable, to place a taboo on all the
weird and beautiful programs. The landscape of programming techniques
is enormous, fascinating in its diversity, still largely unexplored.
It is certainly littered with traps and snares, luring the
inexperienced programmer into all kinds of horrible mistakes, but that
only means you should proceed with caution, keep your wits about you.
As you learn, there will always be new challenges, new territory to
explore. The programmer who refuses to keep exploring will surely
stagnate, forget his joy, lose the will to program (and become a
manager).
As far as I am concerned, the definite criterion for a program is
whether it is correct. Efficiency, clarity, and size are also
important, but how to balance these against each other is always a
matter of judgement, a judgement that each programmer must make for
himself. Rules of thumb are useful, but one should never be afraid to
break them.
---
In the beginning, at the birth of computing, there were no programming
languages. Programs looked something like this:
] 00110001 00000000 00000000
] 00110001 00000001 00000001
] 00110011 00000001 00000010
] 01010001 00001011 00000010
] 00100010 00000010 00001000
] 01000011 00000001 00000000
] 01000001 00000001 00000001
] 00010000 00000010 00000000
] 01100010 00000000 00000000
That is a program to add the numbers from one to ten together, and
print out the result (1 + 2 + ... + 10 = 55). It could run on a very
simple kind of computer. 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 imagine
how this was a tedious, error-prone procedure. Even the writing of
simple programs required much cleverness and discipline, complex ones
were nearly inconceivable.
Of course, manually entering these arcane patterns of bits (which is
what the 1s and 0s above are generally called) 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 program contains a single instruction. It could be
written in English like this:
1. Store the number 0 in memory location 0
2. Store the number 1 in memory location 1
3. Store the value of memory location 1 in memory location 2
4. Subtract the number 11 from the value in memory location 2
5. If the value in memory location 2 is the number 0, continue with instruction 9
6. Add the value of memory location 1 to memory location 0
7. Add the number 1 to the value of memory location 1
8. Continue with instruction 3
9. Output the value of memory location 0
While that is more readable than the binary soup, it is still rather
unpleasant. It might help to use names instead of numbers for the
instructions and memory locations:
] Set 'total' to 0
] Set 'count' to 1
] [loop]
] Set 'compare' to 'count'
] Subtract 11 from 'compare'
] If 'compare' is zero, continue at [end]
] Add 'count' to 'total'
] Add 1 to 'count'
] Continue at [loop]
] [end]
] Output 'total'
At this point it is not too hard to see how the program works. Can
you? The first two lines give two memory locations their starting
values: |total| will be used to build up the result of the program,
and |count| keeps track of the number that we are currently looking
at. The lines using |compare| are probably the weirdest ones. What the
program wants to do is see if |count| is equal to 11, in order to
decide whether it can stop yet. Because the machine is so primitive,
it can only test whether a number is zero, and make a decision (jump)
based on tha
没有合适的资源?快使用搜索试试~ 我知道了~
JavaScirpt经典教程+demo
共106个文件
js:36个
html:28个
png:28个
3星 · 超过75%的资源 需积分: 9 7 下载量 19 浏览量
2011-10-30
11:16:07
上传
评论
收藏 1.55MB ZIP 举报
温馨提示
JavaScirpt经典教程+demo JavaScirpt经典教程+demo JavaScirpt经典教程+demo
资源推荐
资源详情
资源评论
收起资源包目录
JavaScirpt经典教程+demo (106个子文件)
book.css 4KB
console.css 4KB
highlight.css 514B
sokoban.css 393B
boulder.gif 207B
player.gif 191B
.htaccess 146B
print.html 782KB
chapter8.html 147KB
chapter4.html 88KB
chapter6.html 80KB
chapter13.html 78KB
chapter7.html 75KB
chapter2.html 65KB
chapter12.html 43KB
chapter11.html 34KB
chapter3.html 32KB
chapter9.html 30KB
chapter14.html 29KB
chapter10.html 27KB
terms.html 26KB
chapter5.html 21KB
chapter1.html 21KB
appendix2.html 20KB
appendix1.html 10KB
donate.html 4KB
index.html 2KB
contents.html 2KB
chapter15.html 1KB
paper.html 1KB
example_getinfo.html 1KB
example_events.html 738B
example_alchemy.html 537B
sendreaction.html 435B
view.html 340B
paper.js 197KB
ejs.js 147KB
Mochi.js 84KB
highlight.js 19KB
env.js 16KB
book.js 12KB
base-env.js 11KB
select.js 7KB
tokenize.js 6KB
fp.js 6KB
search.js 5KB
bookutil.js 3KB
data.js 3KB
initenv.js 3KB
event_example.js 3KB
FunctionalTools.js 2KB
util.js 2KB
dom.js 1KB
DOMTools.js 911B
ObjectTools.js 728B
Dictionary.js 512B
oo.js 487B
TestModule.js 387B
web.js 339B
params.js 336B
intro.js 318B
before.js 96B
xhr.js 28B
binaryheap.js 28B
basics.js 0B
event.js 0B
modularity.js 0B
error.js 0B
regexp.js 0B
control.js 0B
functions.js 0B
fruit.json 110B
fruit2.json 58B
ejs.js.orig 146KB
height.png 194KB
sheep.png 146KB
ostrich.png 104KB
xkcd_regular_expressions.png 96KB
Hiva Oa.png 85KB
eyes.png 65KB
html.png 38KB
objectchain.png 30KB
tree.png 25KB
diagonalpath.png 24KB
florence_flask.png 23KB
heap.png 9KB
yinyang.png 8KB
react.png 1KB
hr-diamonds.png 808B
player.png 439B
boulder.png 417B
runcode.png 306B
empty.png 304B
runcode_done.png 301B
close.png 263B
hide.png 263B
show.png 253B
resize.png 253B
wall.png 216B
loadcode.png 214B
共 106 条
- 1
- 2
资源评论
- jackxuechen2012-03-21不知道怎么用,全是英文的
zhouli253
- 粉丝: 15
- 资源: 135
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 多机调度问题贪心算法:理论探索与实践应用.zip
- 探索tecreate:软件开发的未来之星.zip
- 打标机项目C#源码连接扫码
- 基于SSM的房屋租赁系统的设计与实现
- xyctf:从入门到精通的实用指南.zip
- mmqrcode1714153659780.png
- Screenshot_2024-04-27-06-08-58-486_com.baidu.xin.aiqicha.jpg
- 基于Javaweb+Tomcat+MySQL的大学生公寓管理系统+sql文件.zip
- 实训作业基于javaweb的订单管理系统源码+数据库+实训报告.zip
- 多机调度问题贪心算法基于最小堆和贪心算法求解多机调度问题.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功