首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

[通译Joel On Software]回归基础/Back to Basics

2013-11-02 
[翻译Joel On Software]回归基础/Back to BasicsJoel on SoftwareBack to Basics回归基础by Joel SpolskyT

[翻译Joel On Software]回归基础/Back to Basics

Joel on Software

Back to Basics回归基础

by Joel Spolsky

Tuesday,December 11, 2001

Wespend a lot of time on this site talking about exciting Big Picture Stuff like.NET versus Java, XML strategy, Lock-In, competitive strategy, software design,architecture, and so forth. All this stuff is a layer cake, in a way. At thetop layer, you've got software strategy. Below that, we think about architectureslike .NET, and below that, individual products: software development productslike Java or platforms like Windows.

我们在这个站点花了大量时间来讲令人振奋的大场景像:.NET和Java,XML战略,Lock-In,竞争策略,软件设计,架构等等。在某种意义上,所有这些东西就像一个分层的蛋糕。在最顶层,是软件策略。在这下面,我们考虑像.NET一样的架构,在这下面,是单独的产品:像Java这样的软件开发产品或者像Windows一样的平台。

Golower on the cake, please. DLLs? Objects? Functions? No! Lower! At some pointyou're thinking about lines of code written in programming languages.

请往这个蛋糕的再底层走一点。动态链接库?对象?函数? 我!再低一点!在某一点上,你总会开始考虑编程语言写的一行行代码。

Stillnot low enough. Today I want to think about CPUs. A little bit of siliconmoving bytes around. Pretend you are a beginning programmer. Tear away all thatknowledge you've built up about programming, software, management, and get backto the lowest level Von Neumann fundamental stuff. Wipe J2EE out of your mindfor a moment. Think Bytes.

层次还是不够低。今天我想考虑CPU,一小块的硅片承载着的字节流。假装你是个入门程序员。摒弃所有你学到的关于编程,软件,管理的知识,然后回到最底层的冯诺依曼基础计算机结构。忘掉一会儿你脑袋里的J2EE。用字节进行思考。

Whyare we doing this? I think that some of the biggest mistakes people make evenat the highest architectural levels come from having a weak or brokenunderstanding of a few simple things at the very lowest levels. You've built amarvelous palace but the foundation is a mess. Instead of a nicecement slab, you've got rubble down there. So the palace looks nice butoccasionally the bathtub slides across the bathroom floor and you have no ideawhat's going on.

为什么我们要这样做?我觉得人们甚至在最高架构层都会犯的一些最大错误都源于人们对最底层简单概念残缺不全的认识。你造了一座金碧辉煌的宫殿,但基础却一塌糊涂。本该是坚固水泥板的地方,你放置的却是残砖碎瓦。所以宫殿看起来虽然漂亮但是有时候浴缸在浴室滑动你却不知道为什么。

Sotoday, take a deep breath. Walk with me, please, through a little exercisewhich will be conducted using the C programming language.

所以今天,请深呼吸,跟随我做一个用C语言写的小练习。

Rememberthe way strings work in C:they consist of a bunch of bytes followed by a null character, which has thevalue 0. This has two obvious implications:

记住C语言里字符串的工作机制:他们由一串字节然后一个null(值为0)字符构成,两点含义不言而喻:

1.       There is no way to know where the string ends(that is, the string length) without moving through it, looking for thenull character at the end.

2.       如果不遍历这个字符串去寻找null字符,就无法获知它的结尾(也就是获得字符串长度)

3.       Your string can't have any zeros in it. Soyou can't store an arbitrary binary blob like a JPEG picture in a C string.

4.       你的字符串里面不能有0值,所以你不能把任意的块数据(如JPEG图像)存储在C字符串里。

Whydo C strings work this way? It's because the PDP-7 microprocessor, on whichUNIX and the C programming language were invented, had an ASCIZ string type.ASCIZ meant "ASCII with a Z (zero) at the end."

为什么C字符串是这样的呢?因为PDP-7微处理器(在它之上产生了UNIX和C编程语言)有一种ASCIZ字符串类型。ASCIZ的意思是“以0结尾的ASCII码”。

Isthis the only way to store strings? No, in fact, it's one of the worst ways tostore strings. For non-trivial programs, APIs, operating systems, classlibraries, you should avoid ASCIZ strings like the plague. Why?

这是存储字符串的唯一方法么?不,实际上,这是最糟糕的存储字符串的方法之一。 对于重要的程序,接口,操作系统,类库,你应该像避免瘟疫一样避免使用ASCIZ字符串。为什么?

Let'sstart by writing a version of the code for strcat, the functionwhich appends one string to another.
让我们先开始写一遍strcat(也就是把一个字符串接在另一个后面的函数)代码试试,

 [w1]翻译为薛乐蜜?

 [w2]NHK : 1984年...由 Ralph Macchio 主演的美国电影...TheKarate Kid~

热点排行