存档

2004年6月 的存档

十年学会编程(收藏)

2004年6月15日 hufey 评论已被关闭

比较同意学半打以上语言的说法,虽然自己以前开的语言跟他不一样。如果按他的list,俺差的太远了
=======================================
十年学会编程
信步走进任何一家书店,你会看到名为”如何在7天内学会Java”的书, 还有各种各样的变体: 在几天内或几小时内学会Visual Basic, Windows, Internet等等,等等. 我在Amazon 上做了如下的 强力检索 :
pubdate: after 1992 and title: days and
(title: learn or title: teach yourself)
得到了248个结果. 前78个都是计算机类书籍(第79个是 Learn Bengali in 30 days). 我用”hours”替换”days”,得到了类似的结果: 更多的253书. 前77本是计算机类书籍,第78本是 Teach Yourself Grammar and Style in 24 Hours. 在前200本书中,有96% 是计算机类书籍.
结论是:要么人们都在急急忙忙地学习计算机, 要么计算机比其它任何东西都容易学. 没有书籍教你在几天内学会古典音乐,或量子物理, 或者是养狗,
让我们分析一下,象一本名为三天内学会Pascal的书意味着什么:
* 学习: 在三天里,你没有时间写一些重大的程序,并从成功或失败中得益. 你没有时间与有经验的程序员合作,并理解在那样的环境下工作是怎么回事. 一句话,你不会有时间学到太多东西. 因此他们只能谈论一些肤浅的东西,而不是深入的理解. 正如亚力山大教皇所说, 浅尝辄止是危险的事情.
* Pascal: 在三天时间里,你可能学会Pascal的语法(如果你已经学过类似的语言),但你学不到更多的如何使用这些语法的知识. 也就是说, 假如你曾是个BASIC程序员, 你可以学着用Pascal语法写出BASIC风格的程序,但你不可能了解Pascal真正的好处(和坏处). 那么关键是什么? Alan Perlis 说过: “一种不改变你编程的思维方式的语言,不值得去学.” 一种可能的情况是: 你必须学一点儿Pascal(或可能性更大的象Visual Basic 或 JavaScript之类),因为你为了完成某种特定的任务,需要与一个现存的工具建立接口. 不过那不是学习如何编程,而是在学习如何完成那个任务.
* 三天内: 很不幸, 这不够, 原因由下一节告诉我们.
在十年里学会编程
===========================
研究表明 (Hayes, Bloom)在任何一种领域内,象下棋,作曲,绘画,钢琴演奏,游泳,网球,以及原子物理学和拓扑学,等等,要达到专家水平大约都要化十年时间. 没有真正的捷径:即使是莫扎特, 4岁时就是音乐神童,13年后才开始写出世界级的作品. 在另一方面, 披头士似乎在1964年的Ed Sullivan表演上一炮走红. 但他们从1957年就开始表演,在获得大众青睐后,他们的第一个重大成功, Sgt. Peppers,是1967年发行的. Samuel Johnson 认为要花比十年更长的时间: “在任何领域中出类拔萃都要用毕生的劳作来取得; 它不可能用较低的代价获得.” 而Chaucer感叹到:”人生短暂,学海无涯.”
这是我为编程成功开出的方子:
* 设法对编程感兴趣,并且因为它有趣而编一些程序. 确保编程一直充满足够乐趣,这样你才愿意投入十年宝贵时间.
* 与其他程序员交流; 阅读其它程序. 这比任何书本或训练课程都重要
* 写程序. 最好的学习方式是 从实践中学习. 用更技术性的话说, “在一个给定的领域内,个人的最大能力不是自动地由扩展了的经验取得的,但即使是高度有经验的人也可以通过有意识的努力来提高自己的能力” (p. 366) 和 “最有效的学习需要因人而异的适当难度,目标明确的任务, 丰富的信息反馈,以及重复的机会和错误修正.” (p. 20-21) 此书 Cognition in Practice: Mind, Mathematics, and Culture in Everyday Life 是阐明此观点的令人感兴趣的参考文献.
* 如果愿意,在大学里呆上4年或更长(在研究生院里). 你会接触到一些需要学历证明的工作,你会对此领域有更深的理解. 如果你不喜欢学校, 你可以(通过一些贡献)在工作中获得相似的经验. 在任何情况下,光啃书本是不够的. Eric Raymond, The New Hacker’s Dictionary一书的作者,说过,”计算机科学不能把任何人变成编程专家,就象光研究刷子和颜料不会使人变成画家一样.” 我雇佣过的最好的程序员之一仅有高中程度;他做出了许多优秀的 软件, 有他自己的新闻组, 而且通过股票期权,他无疑比我富有的多.
* 和其他程序员一起做项目. 在其中的一些项目中作为最好的程序员; 而在另一些项目中是最差的. 当你是最好的,你能测试领导项目的能力,用你的观点激发别人. 当你是最差的, 你学习杰出者是怎么做的, 了解他们不喜欢做什么(因为他们吩咐你做事).
* 在其他程序员 之后接手项目. 使自己理解别人写的程序. 当程序的原作者不在的时候,研究什么需要理解并且修改它. 思考如何设计你的程序以便后来者的维护.
* 学习至少半打的编程语言. 包括一种支持类抽象的语言(象Java 或C++),一种支持函数化抽象的语言(象Lisp或ML),一种支持语法抽象的语言(象 Lisp), 一种支持声明规格说明的语言(象Prolog或C++ 的模板), 一种支持 coroutine的语言(象Icon或Scheme), 一种支持并行的语言(象Sisal).
* 请记住”计算机科学”中有”计算机”一词. 了解你的计算机要花多长时间执行一条指令,从内存中取一个字(有cache), 从磁盘中读取连续的字, 和在磁盘中找到新的位置. (答案在此.)
* 使自己卷入一种语言标准化的工作里. 它可以是ANSI C++委员会, 也可以是决定你周围小范围内的编程风格是应该两个还是四个空格缩进. 通过任何一种方式,你了解到其他人在某种语言中的想法, 他们的理解深度,甚至一些他们这样想的原因.
* 找到适当的理由尽快地从语言标准化的努力中脱身.
明白了这些,仅从书本中你能得到多少就成了一个问题. 在我第一个孩子出生前, 我读了所有的(关于育儿的)How to 书籍,仍然感觉是个手足无措的新手. 30个月以后, 我的第二个孩子快要出生了,我回头温习这些书了吗? 没有. 相反,我依靠我的个人经验,它比专家写的数千页书更有用和可靠.
Fred Brooks, 在他的随笔 没有银弹 中定出了一个寻找优秀软件设计者的三步计划:
1. 尽可能早地, 有系统地识别顶级的设计人员.
2. 为设计人员指派一位职业导师,负责他们技术方面的成长,仔细地为他们规划职业生涯.
3. 为成长中的设计人员提供相互交流和学习的机会.
此计划假设某些人已经具备了杰出设计者的必要才能; 要做的只是如何恰当地诱导他们. Alan Perlis 说得更简明扼要: “每个人都能被教会雕刻: 假如米开朗其罗被教成如何不会雕刻. 同样的道理也适用于优秀的程序员.”
所以尽管买那本Java的书吧; 你可能会从中学到点儿东西. 但作为一个程序员,你不会在几天内或24小时内,哪怕是几个月内改变你的人生,或你实际的水平.
参考文献
============
Bloom, Benjamin (ed.) Developing Talent in Young People, Ballantine, 1985.
Brooks, Fred, No Silver Bullets, IEEE Computer, vol. 20, no. 4, 1987, p. 10-19.
Hayes, John R., Complete Problem Solver Lawrence Erlbaum, 1989.
Lave, Jean, Cognition in Practice: Mind, Mathematics, and Culture in Everyday Life, Cambridge University Press, 1988.
答案
2001年夏天典型的1GHz PC的各种操作要花的时间
执行一条指令 1 nsec = (1/1,000,000,000) sec
从L1 cache memory 中取一个字 2 nsec
从内存中取一个字 10 nsec
从磁盘的连续位置取一个字 200 nsec
从磁盘的新位置取一个字(seek) 8,000,000nsec = 8msec
脚注
This page also available in Japanese translation thanks to Yasushi Murakawa, in Spanish translation thanks to Carlos Rueda and in German translation thanks to Stefan Ram.
T. Capey points out that the Complete Problem Solver page on Amazon now has the “Teach Yourself Bengali in 21 days” and “Teach Yourself Grammar and Style” books under the “Customers who shopped for this item also shopped for these items” section. I guess that a large portion of the people who look at that book are coming from this page.
Peter Norvig (Copyright 2001)

分类: 未分类 标签:

家花

2004年6月13日 hufey 评论已被关闭

分类: 未分类 标签:

弄好了paowang blog的counter

2004年6月12日 hufey 3 条评论

每个人都能用自己喜欢的图片

分类: 未分类 标签:

美国陆军专用版Windows XP

2004年6月8日 hufey 5 条评论
分类: 未分类 标签:

《Linux Kernel Development》Note 5 — thread

2004年6月6日 hufey 评论已被关闭

Linux has a unique implementation of threads. To the Linux kernel, there is no concept of a thread. Linux implements all threads as standard processes. The Linux kernel does not provide any special scheduling semantics or data structures to represent threads. Instead, a thread is merely a process which shares certain resources. Each thread has a unique task_struct and appears to the kernel as a normal process (which shares resources, such as an address space, with other processes).
This approach to threads contrasts greatly with operating systems such as Microsoft Windows or Sun Solaris, which have explicit kernel support for threads (and sometimes call threads lightweight proesses). The name “lightweight process” sums up the difference in philosophies between Linux and other systems. To these other operating systems, threads are an abstraction to provide a lighter, quicker execution unit that the heavy process. To Linux, threads are simply a manner of sharing resoures between processes.
Threads are created like normal tasks with the exception that the clone() system call is passed flags corresponding to specific resources to be shared:
clone( CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0 ) ;

分类: 未分类 标签:

《Linux Kernel Development》 Note 4

2004年6月6日 hufey 评论已被关闭

The Process Descriptior and Task Structure
The kernel strores the processes in a circular doubly linked list called the task list. Each element in the task list is a process descriptor of the type struct task_struct, which is defined in include/linux/sched.h. The process deescriptor contains all the information about a specific process.
The task_struct is a relatively large data structure at around 1.7 kilobytes on a 32-bit machine. This size, however, is quite small considering that the structure contains all the information the kernel needs about a process. The process descriptor contains the data that describe the executing program — open files, the process’s address space, pending signals, the process’s state, and much more.
Allocating the Process Descriptor
The task_struct is allocated via the slab allocator to provide object reuse and cache coloring. Prior to the 2.6 kernel series, the task_struct was stored at the end of the kernel stack of each process. This allowed architectures with few registers, such as x86, to calculate the location of the process descriptor via the stack pointer without using an extra register to store the location. With the process descriptor now dynamically created via the slab allocator, a new structure, struct thread_info, was created that again lives at the bottom of the stack (for stacks that grow down) or at the top of the stack (for stacks that grow up).
Each task’s thread_info structure is allocated at the end of its stack. The task element of the structure is a pointer to the task’s actual task_struct.
Storing the Process Descriptor
The system identifies processes by a unique proess identification value or PID. The PID is a numerial value that is represented by the opaque type pid_t, which is typially an int. Because of backward compatibility with earlier Unix and Linux versions, however, the default maximum value is on 32767 (that of a short int). The kernel stores this value as pid inside each process descriptor.
If the system is willing to break comatibility with old applications, the administrator may increase the maximum value via /proc/sys/kernel/pid_max.
Contrast this approach with that taken by PowerPC, which stores the current task_struct in a register. Thus, current on PPC merely returns the value stored in the register r2. PPC can take this approach because, unlike x86, it has plenty of registers. Because accessing the process descriptor is a common and important job, the PPC kernel developers deem using a register worthy for the task.

分类: 未分类 标签:

《Linux Kernel Development》 Note 3

2004年6月5日 hufey 评论已被关闭

Processes provide two virtualizations: a virtualized processor and virtual memory. The virtual processor gives the process the illusion that it alone monopolizes the system, despite possibly sharing the processor amongst dozens of other processes. Virtual memory lets the process allocate and manage memory as if it alone owned all the memory in the system.
Note that a program itself is not a process; a process is an active program and related resources. Indeed, two or more processes can exist that are executing the same program. In fact, two or more processes can exist that share various resources, such as open files or an addressspace. A process beins its life when, not surprisingly, it is created. In Linux,this occurs by means of the fork() system call, which creates a new process by duplicating an existing one. The process that calls fork() is the parent, whereas the new process is the child. The parent resumes execution, and the child starts execution, at the same place, where the call returns. Often, following a fork it is desirable to execute a new, different, program. The exec() – family of funcation calls is used to create a new address space and load a new program into it.
Finally, a program exits via the exit() system call. This function termiates the process and frees all its resources. A parent process can inquire about the status of a terminated child, via the wait4() system call that enables a process to wait for the termination of a specific process. When a process exits, it is placed into a special zombie state that is used to represent terminated processes until the parent calls wait() or waitpid().

分类: 未分类 标签:

北京天气,阴有小雨

2004年6月4日 hufey 评论已被关闭

:(

分类: 未分类 标签: