加载中

I recently took a vacation the same week as the 4th of July and had lots of time to reflect upon my career to date. It was a little shocking to realize I’ve been writing code for nearly 30 years now! I decided to take advantage of some of the extra time off to author this nostalgic post and explore all of the languages I’ve worked with for the past 30 years. So this is my tribute to 30 years of learning new languages starting with “Hello, World.”

The first programming language I learned was TI BASIC, a special flavor of BASIC written specifically for the TI 99/4A microcomputer by Microsoft. BASIC, which stands for Beginner’s All-purpose Symbolic Instruction Code, was the perfect language for a 7-year old to learn while stuck at home with no games. The language organized lines of codes with line numbers and to display something on the screen you “printed it” like this:

最近我在7月4日这一天所在的那周休假了。休假期间,我利用大把的时间对我时至今日的职业生涯进行了反思。 意识到我现在写代码都写了快30年了,不免让我有些许震惊。因此我决定,要利用这段美好的休闲时光,写篇博文来怀怀旧,探究一下我在过去30年的工作中所用到的所有编程语言。且谨以此篇文章献给我以编写“Hello, World.”开始而学习各种新语言的30年美好时光。

TI BASIC是我所学习的第一门编程语言。它是由微软专为TI 99/4A微型计算机编写的一种特殊类型的BASIC方言。BASIC是Beginner’s All-purpose Symbolic Instruction Code的缩写,意思是初学者的通用符号指令代码。对于困在家中又无游戏可玩的7岁孩子来说,BASIC是再好不过的一门编程语言了。该语言采用行号来组织多行代码,要想在屏幕上显示点什么就可以象下面这样把要显示的内容“print出来”:

1981 – TI BASIC

ti994abasic

I spent several months writing “choose your own adventure” games using this flavor of BASIC, and even more time listening to the whistles, crackles, and hisses of a black tape cassette recorder used to save and restore data. Probably the most exciting and pivotal moment of my young life was a few years later when my parents brought home a Commodore 64. This machine provided Commodore BASIC, or PET BASIC, right out of the box. This, too, was written by Microsoft based on the 6502 Microsoft BASIC written specifically for that line of chips that also happened to service Apple machines at the time.

1981 – TI BASIC

ti994abasic

我花了几个月的时间用这种BASIC编写了一些“choose your own adventure(请你来选择你要扮演的角色来进行游戏)”类型的游戏,甚至花了更多的时间听着用来保存和恢复数据的黑色盒式磁带录音机发出的滋滋、啪啪和嘶嘶声。 我人生中最令我激动和最关键的时刻恐怕是多年后我父母把一台Commodore 64带回家的那个时刻。这个机器随机带有Commodore BASIC,或者叫做PET BASIC,而且可开箱即用。这种BASIC也是由微软编写的,它基于6502 Microsoft BASIC,也就是微软专为6520系列芯片而编写的BASIC,而苹果的机器那时所采用的也正好是这个系列的芯片。

1984 – Commodore BASIC

c64basic

The question mark was shorthand for the PRINT command, and the weird characters afterwards were the abbreviated way to type the RUN command (R SHIFT+U - on the Commodore 64 keyboard the SHIFT characters provided cool little graphics snippets you could use to make rudimentary pictures).

I quickly discovered that BASIC didn’t do all of the things I wanted it to. The “demo scene” was thriving at the time and crews were making amazing programs that would defy the limits of the machine. They would do things like trick the video chip into drawing graphics that shouldn’t be possible or scroll content or even move data into the “off-limits” border section of the screen. Achieving these feats required exact timing that was only possible through the use of direct machine language code. So, I fired up my machine monitor (the name for the software that would allow you to type machine codes directly into memory) and wrote this little program:

1984 – Commodore BASIC

c64basic

其中的问号是PRINT命令的简写形式,下面那行中的奇怪字符是RUN命令的一种缩写形式(R SHIFT+U -在Commodore 64的键盘上,SHIFT加字符可以用来输入一些很酷的图形小片段,你可以拿这些图形小片段拼出一些基本看得过去的图片)。

很快我就发现,BASIC语言做不到我想做的所有事情。此时“演示场景(demo scene)”正在兴起,很多人都在编写令人叫绝的程序来挑战机器的能力极限。 他们会做一些类似让视频芯片画一些根本不可能画出来的图形或者把内容或更多数据滚动到屏幕边上“超界”的部分。完成这类壮举需要严格的时间顺序控制,而这种控制除了直接使用机器语言的代码别无它法。因此,我装上了机器监视器(机器监视器是能够让人将机器代码直接输入到内存中的软件的名字),写出了下面这段小程序:

1985 – 6502 Machine Code

c64machine

This little app loaded the “Y-accumulator” with an index, then spun through memory starting at $C100, sending the characters one at a time to a ROM subroutine that would print them to the display. This is the equivalent of a for loop (for y = 0; y <= 0x0d, y++) in machine code. The RTS returns from the subroutine. In order to execute the program, you had to use the built-in SYS command that would call out to the memory address (unfortunately, you had to convert from hexadecimal $C000 to decimal 49152, but otherwise it worked like a charm). I had the PETSCII characters for “HELLO, WORLD” stored at memory address $C100 (yes, the Commodore 64 had it’s own special character page). Here is the result:

c64machinecall 

1985 – 6502 机器码

c64machine

这段小程序会将一个索引装载到“Y-加法器”中,然后将始于$C100的内存中的字符一个一个的发送给ROM中的一个子程序,从而将这些字符显示出来。这就是for循环(for y = 0; y <= 0x0d, y++)所对应的机器码。RTS命令会从子程序中返回。为了执行这个程序,你还得使用内建的SYS命令呼叫出内存地址(很不幸,为此你不得不将16进制的$C000转换成10进制的49152,但除此之外其它的运行起来那叫一个顺畅)。我将表示“HELLO, WORLD”的PETSCII字符存储在了内存地址$C100处(是的,Commodore 64有它自己特殊的字符页(character page))。程序运行结果如下:

c64machinecall

Of course life got a little easier when I moved from raw machine code to assembly. With assembly, I could pre-plan my software, and use labels to mark areas of memory without having to memorize memory addresses. The exact same program shown above could be written like this:

1986 – 6502 Assembly

* = $C000       ;set the initial memory address
CHROUT = $FFD2  ;set the address for the character out subroutine
         LDY #$00 
LOOP     LDA HELLO, Y 
         CMP #$00          BEQ END 
         JSR CHROUT 
         INY 
         BNE LOOP 
END      RTS
HELLO    ASC 'HELLO, WORLD.' ; PETSCII
HELLOEND DFB 0 ; zero byte to mark the end of the string 

About that time I realized I really loved writing software. I took some courses in high school, but all they taught was a silly little Pascal language designed to make it “easy” to learn how to program. Really? Easy? After hand-coding complex programs using a machine monitor, Pascal felt like a lot of overkill. I do have to admit the syntax for “Hello, World” is straightforward.

当然,当我从原始的机器码转战到汇编语言时,日子就稍微好过了点。使用汇编语言,我就可以预先规划我的软件,而且还不用死记内存地址了,只需用标签来标记内存地址即可。上面那段机器码对应的完全相同的汇编程序可以如下来编写:

1986 – 6502 汇编语言

* = $C000       ;set the initial memory address
CHROUT = $FFD2  ;set the address for the character out subroutine
         LDY #$00 
LOOP     LDA HELLO, Y 
         CMP #$00          BEQ END 
         JSR CHROUT 
         INY 
         BNE LOOP 
END      RTS
HELLO    ASC 'HELLO, WORLD.' ; PETSCII
HELLOEND DFB 0 ; zero byte to mark the end of the string 

大约也就是这个时候,我意识到我是真的喜欢编写软件了。高中时我参加了一些课程,但他们教的不过是一些很愚蠢的小型Pascal语言,设计这种语言就是为了使学习如何编程变得“轻松一些”。真是轻松了吗?经过使用“机器监视器”徒手编写复杂的程序之后,我感觉Pascal实在是太过于轻松了。我还真是不得不承认,用Pascal编写“Hello, World”的语法实在是太简单了。

1989 – Pascal

program HelloWorld;
begin
  writeln('Hello, World.');
end

I thought the cool kids at the time were working with C. This was a fairly flexible language and felt more like a set of functional macros over assembly than an entirely new language. I taught myself C on the side, but used it only for a short while.

1990 – C

#include <stdio.h>
main()
{
  printf("Hello World");
}

The little program includes a library that handles Standard Input/Output and then sends the text on its way. Libraries were how C allowed us to develop cross-platform – the function was called the same thing whether you were on Windows or Linux, but the library itself implemented all of the low-level routines needed to make it work on the target machine. The above code was something I would tinker with on my Linux machine a few years later. It’s hard to describe if you weren’t into computers during this time, but it felt like you weren’t a true programmer unless you built your own custom Linux installation. By “built your own” I mean literally walked through the source and customized it to match the specific set of hardware you owned. The most fun was dealing with video cards and learning about “dot clocks” and all of the nuances of making the motherboard play nicely with the graphics chip. Anyway, I diverge.

1989 – Pascal

program HelloWorld;
begin
  writeln('Hello, World.');
end

我想,在这时候,很时尚的小子们都在用C编程序呢。C是一种非常灵活的语言,它感觉就象是汇编语言之上的一些功能性的宏,而不像是一门新语言。因此我额外自学了C,但C我却只用了不长的一段时间。

1990 – C

#include <stdio.h>
main()
{
  printf("Hello World");
}

这段小程序包含了一个处理标准输入/输出的库,然后就在屏幕上输出了一段文字。C中的库使得C可以开发跨平台的应用 —— 不管是在Windows还是在Linux中调用的都是同一个函数,但库本身实现了能够运行于目标机的所有底层子程序。上面这段代码也是我多年后在Linux机器上首选摆弄的代码。如果那时你还没有入计算机这个行当,有些情况是我光用语言很难说明白的,那时要是你不弄个Linux自定义安装版,大家就觉得你不是个真正的程序员。我所说的“弄个自定义安装版”,意思是梳理Linux的源代码,将其按照你自己独特的硬件对Linux进行定制。其中最有意思的要数对显卡的处理了,要掌握监视器的“点时钟”情况,其中还需要施展各种奇巧淫技才能让主板很好的配合图形芯片一起工作。好吧,我跑题了。

C was not really a challenge for me to learn, but I quickly figured out the cool kids were doing something different and following this paradigm known as “object-oriented programming.” Machine code and assembly are probably the farthest you can get from OO, so the shift from procedural to object-oriented was a challenge I was ready to tackle. At the time you couldn’t simply search online for content (you could, but it was using different mechanisms with far fewer hits) so I went out and bought myself a stack of C++ books. It turns out C++ supports the idea of “objects.” It even used objects to represent streams and pipes to manipulate them. This object-oriented stuff also introduced the idea of namespaces to better manage partitions of code. All said, “Hello, World” becomes:

1992 – C++

#include <iostream>
using namespace std;
int main()
{
  cout << "Hello World";
  return 0;
}

I headed off to college and was disappointed that the place I went did not have courses that covered the “modern” languages I was interested in like C and C++. Instead, I had to muddle through a course where homework was performed on the mainframe we called “Cypher” using an interesting language called Fortran that actually cares about what column you put your code in! That’s right, the flavor of the language at the time designated column 1 for comments, columns 1 – 5 for statement labels, column 6 to mark a continuation, and only at column 7 could you begin to write real code. I learned enough of Fortran to know I never wanted to use it.

C对我来说学起来真的不算是个挑战,但我很快就搞明白了,耍酷的小子们在做着不同的事情,正在学习一种称为“面向对象编程”的编程范型。机器码和汇编语言可能是和OO距离最远的东西了,从面向过程的编程转向面向对象的编程对我来说是个我乐于接受的挑战。在那时你还无法仅仅通过在线搜索来寻找学习资料(搜是可以搜的,但搜索机制和现在不同而且搜索结果也少之又少),因此我就出去买了一摞C++的书。 C++的确支持“对象”这个概念。它甚至还使用对象来表示流和管道,能够以对象的方式来对它们进行操作。面向对象还引入了命名空间的概念,以此来更好的管理代码的划分。说了这么多,这次“Hello, World”变成这样了:

1992 – C++

#include <iostream>
using namespace std;
int main()
{
  cout << "Hello World";
  return 0;
}

我一猛子扎进了大学,但令我失望的是,我的大学里并没有开设教授我所感兴趣的象C和C++这样的现代语言的课程。相反,我不得不应付差事的课程却是让我在一个叫做“Cypher”的大型机上用一种叫做Fortran的很有趣的语言来写作业。Fortran这种语言竟然很在意你把代码放到哪一栏中!没错,那时这种语言规定第1栏用来写注释,第1到5栏写语句的标签,第6栏用于续行字符,只有从第7栏你才能开始写真正的代码,我学到了足够多的Fortran,使我认识到我以后再也不想用这种语言编程了。

1993 – Fortran

       PROGRAM HELLOWORLD
       PRINT *, 'Hello, World!'
       END

Because I wasn’t much into the main courses I spent most of the evenings down in the computer lab logging onto the massive Unix machines the college had. There I discovered the Internet and learned about the “old school” way of installing software: you pull down the source, build it, inspect the errors, tweak it, fix it, and get a working client. Honestly, I don’t know how you could use Unix without learning how to program based on the way things ran back then so I was constantly hacking and exploring and learning my way around the system. One fairly common thing to do would be execute commands that would dump out enormous wads of information that you then had to parse through using “handy” command line tools. One of the coolest languages I learned during that time was PERL. It doesn’t do the language justice to treat it with such a simple example, but here goes:

1993 – PERL

$welcome = "Hello World";
print "$welcome\n";

At the same time I quickly discovered the massive World Wide Web (yes, that’s what we called it back then … the Internet was what all of those fun programs like Gopher and Archie ran on, and the World Wide Web was just a set of documents that sat on it). HTML was yet another leap for me because it was the first time I encountered creating a declarative UI. Instead of loading up variables or literals and calling some keyword or subroutine, I could literally just organize the content on the page. You’d be surprised that 20 years later, the basic syntax of an HTML page hasn’t really changed at all.

1993 – Fortran

       PROGRAM HELLOWORLD
       PRINT *, 'Hello, World!'
       END

那时我翘了大部分课程,把晚上的大部分时光花在了计算机房。在那里我使用的是我们大学的大型Unix机。在机房里我发现了Internet,学到了安装软件的“老式”的方法:下载软件源代码,build出可执行程序,查看错误,然后进行相应的调整和修复才能得到一个好用的软件。实话说,我还真不知道不学会那时的编程技术,你怎么才能学会使用Unix。那时我不断地探索和学习使用计算机系统的方式。当时我所做的最常见的一件事就是执行一个能够倒出大量信息的命令之后,再使用一些非常“顺手”的命令行工具对这些信息进行解析。那年我学到的最酷的语言之一就是PERL。虽然用“Hello, World.”这样简陋的例子做演示对PERL来说很不公平,但就先将就一下吧:

1993 – PERL

$welcome = "Hello World";
print "$welcome\n";

与此同时我很快发现了大量的World Wide Web(是的,那时我们就是这么称呼Internet的。Internet中运行的就是GopherArchie这类好玩的程序,World Wide Web只是Internet之上的一写文档而已)。HTML对我来说又是令一个飞跃,它使我第一次接触到了描述性UI。不用装入变量或字面量并使用一些关键字或子程序,我就能够将内容组织到一个页面之中。你可能会惊奇,直到20年后的今天,HTML页面的基本语法实际上根本都没怎么变。

1993 – HTML 

<html>
<head><title>Hello, World</title></head>
<body><h1>Hello, World</h1></body>
</html>

This was an interesting time for me. I had moved from my personal computers (TI-99/4A and Commodore 64 with a brief period spent on the Amiga) to mainframes, and suddenly my PC was really just a terminal for me to connect to Unix mainframes. I also ran a Linux OS on my PC because that was the fastest way to connect to the Internet and network at the time – the TCP/IP stack was built-in to the OS rather than having to sit on top like it did in the old Windows versions (remember NETCOM anyone?) . Most of my work was on mainframes.

I did realize that I was losing touch with the PC world. At that time it was fairly obvious that the wild days of personal computing were over and the dust had settled around two machines: the PC, running Windows, for most of us, and the Mac for designers. That’s really what I believed. I had a roommate at the the time who was all over the Mac and at the time he designed coupons. He had all of these neat graphics design programs and would often pull out Quark and ask me, “What do you have on the PC that could do this?” I would shrug and remind him that I can’t even draw a circle or square so what on earth would I do with that graphics software? I liked my PC, because I understood software and I understood math so even if I couldn’t draw I could certainly use math to create fractal graphics or particle storms. Of course, doing this required having a graphics card and wasn’t really practical from a TELNET session to a Unix box, so I began learning how to code on the PC. At the time, it was Win32 and C++ that did the trick. You can still create boilerplate for the stack in Visual Studio 2012 today. I won’t bore you with the details of the original “HELLO.C” for Win32 that spanned 150 lines of code.

1993 – HTML 

<html>
<head><title>Hello, World</title></head>
<body><h1>Hello, World</h1></body>
</html>

对我来说这是一段很有意思的时光。我从个人计算机(TI-99/4A和Commodore 64,还在很短的一段时间中用过Amiga)转向的大型机, 忽然之间我的PC真的只是变成了用来连接到Unix大型机的终端而已。我还在PC上运行了一个Linux操作系统,这是因为Linux是连接到Internet和网络的最快最方便的方式 —— Linux内置了TCP/IP协议栈,无需想老版本的Windows那样在操作系统之上再安装这个协议栈了(还有人记得NETCOM吗?)我的大部分工作是在大型机上完成的。

我真地意识到了,我在间接失去同PC世界的联系。显然那时疯狂的个人计算时代已经结束了,有两种机器渐渐成了接灰的摆设了:一种是对于我们中的大部分人来说的运行Windows的PC,另外一种就是对于设计者而言的Mac机器。PC已经过时了就是我当时的信念。那时我有个室友成天围着Mac转,用Mac来设计各种优惠卷。他有一大堆漂亮的图形设计程序,经常会把一个叫做Quark的软件调出来,然后问我:“你的PC里有这样的软件吗?”我会耸耸肩然后提醒他,我连一个圆或者正方形都不画,我要这样的图形软件有什么用?我喜欢我的PC,因为我懂软件,而且我也会数学,即使我没有画什么图,我肯定能够利用数学在计算机上画出分形图形或者粒子风暴图。当然要做到这些就需要有图形卡,通过TELNET连接到Unix机可干不了这些事,所以我开始学习PC编程了。那时在PC上用来编程的就是Win32和C++了。即使在今天的Visual Studio 2012中,你依然能够运行下面我说的这个例子。我不会用我原先在Win32下编写的有150多行代码的“HELLO.C”程序来烦你的。

1994 – Win32 / C++ (Example is a bit more recent)

 win32

Dropping to the command line and executing this gives us:

win32output

My particle streams and Mandelbrot sets weren’t doing anything for employment, however, so I had to take a different approach. Ironically, my professional start didn’t have anything to do with computers at all. I started working for an insurance company taking claims over the phone in Spanish. That’s right. In the interview for a lower wage job that I was “settling for” to pay the bills while I stayed up nights and hacked on my PC I happened to mention I spoke Spanish. They brought in their bilingual representative to interview me and I passed the test, and within a week I was in a higher paid position learning more Spanish in a few short calls than I had in all my years in high school.

1994 – Win32 / C++ (这个例子要稍稍新一些)

win32

打开一个命令行窗口然后运行这个程序后会得到这样的结果:

win32output

我的粒子流程序和曼德布洛特集合程序肯定在找工作方面帮不上什么忙,所以我必须再找另外的办法。令人啼笑皆非的是,我的职业在开始时同计算机竟然没有丝毫的关系。刚开始我为一家保险公司工作,工作内容是处理来自西班牙的电话索赔事务。情况就是这么个情况。在为一个薪水较低的工作接受面试时,我准备安心用这份微薄的薪水来户口,晚上再熬夜搞PC编程,我偶然提到我会说西班牙语。他们叫来他们的双语业务代表来面试我,我通过了测试。就在一周之内我得到了一个薪水更高的职位,因为我在短短的几个电话中学到了比我在整个高中几年里学到的还有多的西班牙语。

返回顶部
顶部