程序员的进化——从学生到首席执行官

本文通过展示从初学者到不同层级程序员乃至黑客编写“Hello World”程序的变化,揭示了编程技能随时间和经验逐步提升的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 翻译 2002 王咏刚 http://www.contextfree.net/
  2. 转译自 Omri's Computer Humor Page
  3. http://www.cs.bgu.ac.il/~omri/Humor/
  4. -------------------------------------------*/


  5. --------------------------------------------------------------------------------
  6. 中学阶段

  7.           10 PRINT "HELLO WORLD"
  8.           20 END
  9. --------------------------------------------------------------------------------
  10. 大学一年级

  11.           program Hello(input, output)
  12.             begin
  13.               writeln('Hello World')
  14.             end.
  15. --------------------------------------------------------------------------------
  16. 大学高年级

  17.           (defun hello
  18.             (print
  19.               (cons 'Hello (list 'World))))
  20. --------------------------------------------------------------------------------
  21. 初级程序员

  22.           #include <stdio.h>;
  23.           void main(void)
  24.           {
  25.             char *message[] = {"Hello ", "World"};
  26.             int i;

  27.             for(i = 0; i < 2; ++i)
  28.               printf("%s", message[i]);
  29.             printf("\n");
  30.           }
  31. --------------------------------------------------------------------------------
  32. 编程老鸟

  33.           #include <iostream.h>;
  34.           #include <string.h>;

  35.           class string
  36.           {
  37.           private:
  38.             int size;
  39.             char *ptr;

  40.           public:
  41.             string() : size(0), ptr(new char('\0')) {}

  42.             string(const string &s) : size(s.size)
  43.             {
  44.               ptr = new char[size + 1];
  45.               strcpy(ptr, s.ptr);
  46.             }

  47.             ~string()
  48.             {
  49.               delete [] ptr;
  50.             }

  51.             friend ostream &operator <<(ostream &, const string &);
  52.             string &operator=(const char *);
  53.           };

  54.           ostream &operator<<(ostream &stream, const string &s)
  55.           {
  56.             return(stream << s.ptr);
  57.           }

  58.           string &string::operator=(const char *chrs)
  59.           {
  60.             if (this != &chrs)
  61.             {
  62.               delete [] ptr;
  63.              size = strlen(chrs);
  64.               ptr = new char[size + 1];
  65.               strcpy(ptr, chrs);
  66.             }
  67.             return(*this);
  68.           }

  69.           int main()
  70.           {
  71.             string str;

  72.             str = "Hello World";
  73.             cout << str << end

  74.             return(0);
  75.           }
  76. --------------------------------------------------------------------------------
  77. 编程高手

  78.           [
  79.           uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
  80.           ]
  81.           library LHello
  82.           {
  83.               // bring in the master library
  84.               importlib("actimp.tlb");
  85.               importlib("actexp.tlb");

  86.               // bring in my interfaces
  87.               #include "pshlo.idl"

  88.               [
  89.               uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
  90.               ]
  91.               cotype THello
  92.            {
  93.            interface IHello;
  94.            interface IPersistFile;
  95.            };
  96.           };

  97.           [
  98.           exe,
  99.           uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
  100.           ]
  101.           module CHelloLib
  102.           {

  103.               // some code related header files
  104.               importheader(<windows.h>;);
  105.               importheader(<ole2.h>;);
  106.               importheader(<except.hxx>;);
  107.               importheader("pshlo.h");
  108.               importheader("shlo.hxx");
  109.               importheader("mycls.hxx");

  110.               // needed typelibs
  111.               importlib("actimp.tlb");
  112.               importlib("actexp.tlb");
  113.               importlib("thlo.tlb");

  114.               [
  115.               uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
  116.               aggregatable
  117.               ]
  118.               coclass CHello
  119.            {
  120.            cotype THello;
  121.            };
  122.           };

  123.           #include "ipfix.hxx"

  124.           extern HANDLE hEvent;

  125.           class CHello : public CHelloBase
  126.           {
  127.           public:
  128.               IPFIX(CLSID_CHello);

  129.               CHello(IUnknown *pUnk);
  130.               ~CHello();

  131.               HRESULT  __stdcall PrintSz(LPWSTR pwszString);

  132.           private:
  133.               static int cObjRef;
  134.           };

  135.           #include <windows.h>;
  136.           #include <ole2.h>;
  137.           #include <stdio.h>;
  138.           #include <stdlib.h>;
  139.           #include "thlo.h"
  140.           #include "pshlo.h"
  141.           #include "shlo.hxx"
  142.           #include "mycls.hxx"

  143.           int CHello::cObjRef = 0;

  144.           CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
  145.           {
  146.               cObjRef++;
  147.               return;
  148.           }

  149.           HRESULT  __stdcall  CHello::PrintSz(LPWSTR pwszString)
  150.           {
  151.               printf("%ws\n", pwszString);
  152.               return(ResultFromScode(S_OK));
  153.           }

  154.           CHello::~CHello(void)
  155.           {

  156.           // when the object count goes to zero, stop the server
  157.           cObjRef--;
  158.           if( cObjRef == 0 )
  159.               PulseEvent(hEvent);

  160.           return;
  161.           }

  162.           #include <windows.h>;
  163.           #include <ole2.h>;
  164.           #include "pshlo.h"
  165.           #include "shlo.hxx"
  166.           #include "mycls.hxx"

  167.           HANDLE hEvent;

  168.            int _cdecl main(
  169.           int argc,
  170.           char * argv[]
  171.           ) {
  172.           ULONG ulRef;
  173.           DWORD dwRegistration;
  174.           CHelloCF *pCF = new CHelloCF();

  175.           hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

  176.           // Initialize the OLE libraries
  177.           CoInitializeEx(NULL, COINIT_MULTITHREADED);

  178.           CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
  179.               REGCLS_MULTIPLEUSE, &dwRegistration);

  180.           // wait on an event to stop
  181.           WaitForSingleObject(hEvent, INFINITE);

  182.           // revoke and release the class object
  183.           CoRevokeClassObject(dwRegistration);
  184.           ulRef = pCF->;Release();

  185.           // Tell OLE we are going away.
  186.           CoUninitialize();

  187.           return(0);
  188.           }

  189.           extern CLSID CLSID_CHello;
  190.           extern UUID LIBID_CHelloLib;

  191.           CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */
  192.               0x2573F891,
  193.               0xCFEE,
  194.               0x101A,
  195.               { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  196.           };

  197.           UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */
  198.               0x2573F890,
  199.               0xCFEE,
  200.               0x101A,
  201.               { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  202.           };

  203.           #include <windows.h>;
  204.           #include <ole2.h>;
  205.           #include <stdlib.h>;
  206.           #include <string.h>;
  207.           #include <stdio.h>;
  208.           #include "pshlo.h"
  209.           #include "shlo.hxx"
  210.           #include "clsid.h"

  211.           int _cdecl main(
  212.           int argc,
  213.           char * argv[]
  214.           ) {
  215.           HRESULT  hRslt;
  216.           IHello        *pHello;
  217.           ULONG  ulCnt;
  218.           IMoniker * pmk;
  219.           WCHAR  wcsT[_MAX_PATH];
  220.           WCHAR  wcsPath[2 * _MAX_PATH];

  221.           // get object path
  222.           wcsPath[0] = '\0';
  223.           wcsT[0] = '\0';
  224.           if( argc >; 1) {
  225.               mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
  226.               wcsupr(wcsPath);
  227.               }
  228.           else {
  229.               fprintf(stderr, "Object path must be specified\n");
  230.               return(1);
  231.               }

  232.           // get print string
  233.           if(argc >; 2)
  234.               mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
  235.           else
  236.               wcscpy(wcsT, L"Hello World");

  237.           printf("Linking to object %ws\n", wcsPath);
  238.           printf("Text String %ws\n", wcsT);

  239.           // Initialize the OLE libraries
  240.           hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);

  241.           if(SUCCEEDED(hRslt)) {

  242.               hRslt = CreateFileMoniker(wcsPath, &pmk);
  243.               if(SUCCEEDED(hRslt))
  244.            hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);

  245.               if(SUCCEEDED(hRslt)) {

  246.            // print a string out
  247.            pHello->;PrintSz(wcsT);

  248.            Sleep(2000);
  249.            ulCnt = pHello->;Release();
  250.            }
  251.               else
  252.            printf("Failure to connect, status: %lx", hRslt);

  253.               // Tell OLE we are going away.
  254.               CoUninitialize();
  255.               }

  256.           return(0);
  257.           }
  258. --------------------------------------------------------------------------------
  259. 黑客初阶

  260.           #!/usr/local/bin/perl
  261.           $msg="Hello, world.\n";
  262.           if ($#ARGV >;= 0) {
  263.             while(defined($arg=shift(@ARGV))) {
  264.               $outfilename = $arg;
  265.               open(FILE, ">;" . $outfilename) || die "Can't write $arg: $!\n";
  266.               print (FILE $msg);
  267.               close(FILE) || die "Can't close $arg: $!\n";
  268.             }
  269.           } else {
  270.             print ($msg);
  271.           }
  272.           1;
  273. --------------------------------------------------------------------------------
  274. 黑客有成

  275.           #include <stdio.h>;
  276.           #define S "Hello, World\n"
  277.           main(){exit(printf(S) == strlen(S) ? 0 : 1);}
  278. --------------------------------------------------------------------------------
  279. 黑客高手

  280.           % cc -o a.out ~/src/misc/hw/hw.c
  281.           % a.out
  282. --------------------------------------------------------------------------------
  283. 黑客大虾

  284.           % cat
  285.           Hello, world.
  286.           ^D
  287. --------------------------------------------------------------------------------
  288. 初级经理

  289.           10 PRINT "HELLO WORLD"
  290.           20 END
  291. --------------------------------------------------------------------------------
  292. 中级经理

  293.           mail -s "Hello, world." bob@b12
  294.           Bob, could you please write me a program that prints "Hello, world."?
  295.           I need it by tomorrow.
  296.           ^D
  297. --------------------------------------------------------------------------------
  298. 高级经理

  299.           % zmail jim
  300.           I need a "Hello, world." program by this afternoon.
  301. --------------------------------------------------------------------------------
  302. 首席执行官

  303.           % letter
  304.           letter: Command not found.
  305.           % mail
  306.           To: ^X ^F ^C
  307.           % help mail
  308.           help: Command not found.
  309.           % damn!
  310.           !: Event unrecognized
  311.           % logout
  312. --------------------------------------------------------------------------------
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值