Reading notes on <The Art of Unix Programming>(1)

16 篇文章 0 订阅

(本读书笔记主要是记录个人在阅读Team LiB整理的英文第二版chm格式文档过程中的所思所想。)

     一个程序员对待自己事业的态度不应该仅仅是勉强的糊口过日子,应该在自己的内心有自己的追求,不能仅仅是一个掌握各种技术的容器container而应该具有一定的文化素养,具有transformation能力(参见Harvard open course < positivy philosophy>第一课)。Unix在计算机发展史上的地位是无可替代的。在这个商业帝国暂时统治人类sofware world的时代,我们职业的programer应该勇敢的站立在open source的旗帜下,为人类在信息时代的发展发展共同传递freedom的火种,与 foundation同在!

    一切就让我们从了解Unix/open source的历史、tradition/culture开始吧。


Preface:


        前言中主要介绍了写作本书的目的,本书的主要内容。这本书并不是介绍具体的Unix相关编程技术,而主要是介绍Unix的发展过程汇总一些不成文的设计原则,而这些原则是十分的有效的,对于一般的软件开发也是非常具有启发性的。同时也将Unix的发展过程中渐渐产生的文化基因做一次总结。用作者的原话来说,本书包括四个不同层次的具体内容:“ This book is divided into four parts: Context, Design, Tools, and Community. The first part (Context) isphilosophy and history, to help provide foundation and motivation for what follows. The second part (Design) unfolds the principles of the Unix philosophy into more specific advice about design and implementation. The third part (Tools) focuses onthe software Unix provides for helping you solve problems. The fourth part (Community) is about the human-to-humantransactions and agreements that make the Unix culture so effective at what it does.
         其实一方面看这本书在于体会Unix发展的起起落落中学习到一些历史发展的经验,看一下软件时代是如何发展到今天这一步的,同时通过具体的practical软件的开发学习设计的技巧心得。另外,在这一学习的过程中,这些历史前辈身上的那一种精神会潜移默化的感染我们,能激起我们在前人开辟的道路上继续走下去,担当起程序员的历史使命。

Part 1

Chapter 1. Philosophy: Philosophy Matters


    这里的philosophy主要是指shared culture/tradition以及在软件设计编程方面的原则。实用的角度看,这是在软件开发中一些很有用的经验,可以让你开发出更好的软件,可以让你的编程水平得到更大的提升,另一方面,这代表了一种生活态度,代表了一种编程的方式。这些知识/expertise之前都是需要长期的言传身教才能得到的。“a special transmission, outside the scriptures”(禅宗:教外别传)。所以有必要了解它们。Unix具有如此强的生命力,这么多年来没有在一波又一波的技术更新中被淘汰,主要的核心原因正在于其开创者给其注入的优秀的design 基因。
     Unix的发展史上犯过一些错误,比如“Unix's heritageas an operating system designed primarily for technical users, and a consequent belief that users know better than operating-system designers what their own needs are.”“But the cost of the mechanism-not-policy approach is that when the user can set policy, the user must set policy. Nontechnical end-users frequently find Unix's profusion of options and interface styles overwhelming and retreat to systems that at least pretend to offer them simplicity.”即机制与策略分离的这种设计哲学使得Unix系统显得不那么简单,需要用户自己去配置,使用自己的权利。这自然使得一般的用户难以对Unix有好的第一印象。也正是这一设计思想是得Unix的内核能始终保持一定的稳定,具有很强的生命力而不至于随着各种新潮外部设置的过时而过时,不想windows那样每一代都需要进行非常大的变化,不具有较高的连续性。
Unix发展中的一些正确决策也是很丰富的,这主要体现在(1)开源(2)可
移植性强3)代码的共享与交流(4)高度的灵活性使得开发人员更可以具有创造性的工作(5)FUN,在Unix下的开发能给你带来快乐与激情“Unix is fun to play with and develop for, and always has been.”
Unix的哲学思想主要有那些呢?作者首先在这里给出了一个纲要,简要的说明了17个rule。这可以说是本书的精华之一,故我将会特别的在另一文中单独解读。一言以敝之就是广为人知的KISS原则:K
eep it simple, stupid!
最后我们必须要将这些原则真正的付诸于我们的coding中去,作者在这一章的最后语重心长的吐露了自己的心声,这些话是如此的冲击人心,让我不得不将其全部引用在此,并将常常加以自省

“When you see the right thing, do it—this may look like more work in the short term, but it's the path of least effort in the long run. If you don't know what the right thing is, do the minimum necessary to get the job done, at least until you figure out what the right thing is.

To do the Unix philosophy right, you have to be loyal to excellence.You have to believe that software design is a craft worth all the intelligence, creativity, and passion you can muster.Otherwise you won't look past the easy, stereotyped ways of approaching design and implementation; you'll rush into coding when you should be thinking. You'll carelessly complicate when you should be relentlessly simplifying—and then you'll wonder why your code bloats and debugging is so hard.

To do the Unix philosophy right, you have to value your own time enough never to waste it. If someone has already solved a problem once, don't let pride or politics suck you into solving it a second time rather than re-using. And never work harder than you have to; work smarter instead, and save the extra effort for when you need it. Lean on your tools and automate everything you can.

Software design and implementation should be a joyous art, a kind of high-level play. If this attitude seems preposterous or vaguely embarrassing to you, stop and think; ask yourself what you've forgotten. Why do you design software instead of doing something else to make money or pass the time? You must have thought software was worthy of your passion once....

To do the Unix philosophy right, you need to have (or recover) that attitude.You need to care. You need to play. You need to be willing to explore.


Chapter 2. History: A Tale of Two Cultures

      这一部分重点回顾了Unix的历史以及Hacker的源来直到两者相汇合在对历史加以反思后走上开源的道路,这一部分中我们可以看到Unix以及open source是如何一步一步走到今天的,以及今天open source以及free software的使命。
     具体的历史是很生动的,从中我们可以得到许多的启示,最核心的其实在于要坚持对于open source,坚持community的作用.启示应该是紧紧坚持FUN--> OPEN- -> FREEDOM的进程,从让个体享受不受约束的编程到让社区内的彼此之间充分共享代码共同开发直到让全世界全人类自由的使用人类创造的成果,感受文明的力量!

when and where Unix has adhered most closely to open-sourcepractices, it has prospered. Attempts to proprietarize it have invariably resulted in stagnation and decline.
Another lesson is this: Never bet against the cheap plastic solution. Or, equivalently, the low-end/high-volume hardware technology almost always ends up climbing the power curve and winning.

Finally, the old-school Unix community failed in its efforts to be "professional" by welcoming in all the command machinery of conventional corporate organization, finance, and marketing. We had to be rescued from our folly by a rebel alliance of obsessive geeks and creative misfits—who then proceeded to show us that professionalism and dedication really meant what we had been doing before we succumbed to the mundane persuasions of "sound business practices".
这一句应该是说我们不应该刻意的去使用商业的规则去和商业上的巨头们去拼杀,而是体现我们真正的对于Unix本身的热忱的最好方式是不断的使自己强大起来,通过技术的力量来打败商业巨头,使其向开源妥协。

Chapter 3.  Contrasts: Comparing the Unix Philosophy with Others


操作系统的基本要素elements



Unix has a couple of unifying ideas or metaphors that shape its APIs and the development style that proceeds from them. The most important of these are probably the "everything is a file" model and the pipe metaphorbuilt on top of it.


Unix has preemptive multitasking
, in which timeslices are allocated by a scheduler which routinely interrupts or pre-empts the running process in order to hand control to the next one. Almost all modern operating systems support preemption.


In the Unix experience, inexpensive process-spawning and easy inter-process communication (IPC) makes a whole ecology of small tools, pipes
, and filters possible.

Unix has wired into it an assumption that the programmer knows best.

On the other hand, Unix is rather careful about not letting you step on other people's data.

The strength of an operating system's internal boundaries is not merely an abstract issue of design: It has important practical consequences for the security of the system.



其他各种操作系统的相对特点与弱点

MacOS
MacOS更加注重界面Interface GUI的美学。其更加倾向于从外表到内部。

Windows NT

Windows interfaces for 'professional' programming continued to grow more complex over time, presenting an increasing barrier to casual (or serious!) coding.

Linux
Linux does not include any code from the original Unix source tree, but it was designed from Unix standards to behave like a Unix.
Linux users and developers, on the other hand, have been adapting themselves to address the nontechnical user's fear of CLIs.开始同样的注重GUI界面,以迎合普通用户。
The desire to reach end users has also made Linux developers much more concerned with smoothness of installation and software distribution issues
与商业性的Unix会更加注重在高端硬件上的性能相比,Linux更加注重对于各种普通硬件甚至低端硬件的支持。


操作系统技术本身的相互吸收、融合
宏观上看,第一,在早期,Unix通过很强的硬件兼容性击败了众多受限于某一特定芯片处理器体系的操作系统;第二,网络功能直接蕴含在Unix的核心功能中,Unix的强大网络功能使得它具有处理大量网络请求的能力。三,同样也正是由于网络功能,使得即使是PC也需要具有多用户多任务的功能才能一方面处理众多的后台网络连接而同时为用户提供前端应用,一方面为了安全需要让各种网络连接程序以不同于用户主体的身份于操作系统交互,另外,server的管理也需要变得更加的人性化,需要有GUI的支持。所以近代client与server的功能是在聚合的。


(part I 到此结束)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代码报错properties of null (reading 'addEventListener') at 2.3bkg.html:138:38下面是代码<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>后台管理界面示例</title> <style> body { margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; } header { background-color: #333; color: #fff; display: flex; justify-content: space-between; align-items: center; padding: 20px 20px 20px 20px; position: fixed; top: 0; left: 0; right: 0; z-index: 1; } header h1 { margin: 0; font-size: 24px; } header .user { display: flex; align-items: center; cursor: pointer; } header .user img { width: 30px; height: 30px; border-radius: 50%; margin-right: 10px; } .sidebar { background-color: #eee; position: absolute; top: 70px; left: -200px; bottom: 0; width: 200px; padding: 10px; overflow: auto; z-index: 1; transition: left 0.3s ease-in-out; } .sidebar.show { left: 0; } .sidebar h2 { margin: 0; font-size: 18px; margin-bottom: 10px; } .sidebar ul { padding: 0; margin: 0; list-style: none; } .sidebar li { margin-bottom: 5px; } .sidebar a { display: block; padding: 5px 10px; color: #333; border-radius: 5px; text-decoration: none; background-color: #fff; transition: background-color 0.2s ease-in-out; } .sidebar a:hover { background-color: #ddd; } .content { margin: 60px 0 0 220px; padding: 10px; background-color: #f5f5f5; min-height: calc(100vh - 70px - 10px); } </style> </head> <body> <header> <h1>中央管理平台</h1> <div class="user"> <img src="user.png" alt=""> <span>未登录</span> </div> </header> <div class="sidebar"> <h2>功能模块</h2> <ul> <li> <a href="#">用户管理</a> <ul> <li><a href="#">添加用户</a></li> <li><a href="#">删除用户</a></li> <li><a href="#">修改用户</a></li> </ul> </li> <li> <a href="#">数据库管理</a> <ul> <li><a href="#">备份数据库</a></li> <li><a href="#">还原数据库</a></li> </ul> </li> <li> <a href="#">页面管理</a> <ul> <li><a href="#">添加页面</a></li> <li><a href="#">删除页面</a></li> <li><a href="#">修改页面</a></li> </ul> </li> </ul> </div> <div class="content"> <!-- 这里是内容区域 --> </div> <script> // 动态计算内容区域的左边距,避免与侧边栏重合 function adjustContentMargin() { const sidebarWidth = document.querySelector('.sidebar').offsetWidth; document.querySelector('.content').style.marginLeft = sidebarWidth + 'px'; } adjustContentMargin(); window.addEventListener('resize', adjustContentMargin); // 点击菜单按钮时显示/隐藏侧边栏 document.querySelector('.menu-btn').addEventListener('click', () => { document.querySelector('.sidebar').classList.toggle('show'); }); // 模拟后端数据传来时,只刷新头部和侧边栏之外的区域 setTimeout(() => { document.querySelector('.content').innerHTML = '<h2>欢迎使用中央管理平台</h2><p>这里是内容区域,只有在后端有数据传来时才会刷新。</p>'; adjustContentMargin(); // 内容区域高度可能会变化,需要重新计算左边距 }, 3000); </script> </body> </html>
最新发布
05-29

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值