程序员的进化史

原文链接: Ariel   翻译:  vonmax007

译文链接: http://blog.jobbole.com/41944/

去年发过一篇《Python程序员的进化史》,那篇文章是以阶乘为例,列举了各种程序员所写代码,甚至包括网页设计师的。今天这篇趣文是以 Hello World 为例,列举处于各阶段程序员的代码。另外,这篇有一定历史了,应该至少有 10 年了。

PS:亮点总是在最后。:)

初中/高中(注:Basic)

  1. 10 PRINT “HELLO WORLD”  
  2. 20 END  
10 PRINT "HELLO WORLD" 
20 END

 
大一(注:Pascal)
  1. program Hallo(output);  
  2. begin  
  3.     writeln(‘Hello, world!’)  
  4. end.  
program Hallo(output); 
begin
writeln('Hello, world!')
end.

大三/大四

  1. (defun hello  
  2.   (print  
  3.     (cons ‘Hello (list ‘World))))  
  4.    
(defun hello 
(print
(cons ‘Hello (list ‘World))))



入职第一年

  1. #include <stdio.h>  
  2. void main(void)  
  3. {  
  4.   char *message[] = {“Hello ”“World”};  
  5.   int i;  
  6.    
  7.   for(i = 0; i < 2; ++i)  
  8.     printf(”%s”, message[i]);  
  9.   printf(”\n”);  
  10. }  
#include <stdio.h> 
void main(void)
{
char *message[] = {“Hello “, “World”};
int i;

for(i = 0; i < 2; ++i)
printf(“%s”, message[i]);
printf(“\n”);
}


入职干了几年

  1. #include <iostream.h>  
  2. #include <string.h>  
  3.    
  4. class string  
  5. {  
  6. private:  
  7.   int size;  
  8.   char ptr;  
  9.    
  10. string() : size(0), ptr(new char[1]) { ptr[0] = 0; }  
  11.    
  12.   string(const string &s) : size(s.size)  
  13.   {  
  14.     ptr = new char[size + 1];  
  15.     strcpy(ptr, s.ptr);  
  16.   }  
  17.    
  18.   ~string()  
  19.   {  
  20.     delete [] ptr;  
  21.   }  
  22.    
  23.   friend ostream &operator <<(ostream &, const string &);  
  24.   string &operator=(const char );  
  25. };  
  26.    
  27. ostream &operator<<(ostream &stream, const string &s)  
  28. {  
  29.   return(stream << s.ptr);  
  30. }  
  31.    
  32. string &string::operator=(const char chrs)  
  33. {  
  34.   if (this != &chrs)  
  35.   {  
  36.     delete [] ptr;  
  37.    size = strlen(chrs);  
  38.     ptr = new char[size + 1];  
  39.     strcpy(ptr, chrs);  
  40.   }  
  41.   return(this);  
  42. }  
  43.    
  44. int main()  
  45. {  
  46.   string str;  
  47.    
  48.   str = ”Hello World”;  
  49.   cout << str << endl;  
  50.    
  51.   return(0);  
  52. }  
  53.    
#include <iostream.h>

#include <string.h> class string { private: int size; char *ptr; string() : size(0), ptr(new char[1]) { ptr[0] = 0; } string(const string &s) : size(s.size) { ptr = new char[size + 1]; strcpy(ptr, s.ptr); } ~string() { delete [] ptr; } friend ostream &operator <<(ostream &, const string &); string &operator=(const char *); }; ostream &operator<<(ostream &stream, const string &s) { return(stream << s.ptr); } string &string::operator=(const char *chrs) { if (this != &chrs) { delete [] ptr; size = strlen(chrs); ptr = new char[size + 1]; strcpy(ptr, chrs); } return(*this); } int main() { string str; str = "Hello World"; cout << str << endl; return(0); }
大师程序员

[csharp] view plain copy
print ?
  1.   [  
  2.   uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)  
  3.   ]  
  4.   library LHello  
  5.   {  
  6.       // bring in the master library  
  7.       importlib(”actimp.tlb”);  
  8.       importlib(”actexp.tlb”);  
  9.    
  10.       // bring in my interfaces  
  11.       #include “pshlo.idl”  
  12.    
  13.       [  
  14.       uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)  
  15.       ]  
  16.       cotype THello  
  17.    {  
  18.    interface IHello;  
  19.    interface IPersistFile;  
  20.    };  
  21.   };  
  22.    
  23.   [  
  24.   exe,  
  25.   uuid(2573F890-CFEE-101A-9A9F-00AA00342820)  
  26.   ]  
  27.   module CHelloLib  
  28.   {  
  29.    
  30.       // some code related header files  
  31.       importheader(<windows.h>);  
  32.       importheader(<ole2.h>);  
  33.       importheader(<except.hxx>);  
  34.       importheader(”pshlo.h”);  
  35.       importheader(”shlo.hxx”);  
  36.       importheader(”mycls.hxx”);  
  37.    
  38.       // needed typelibs  
  39.       importlib(”actimp.tlb”);  
  40.       importlib(”actexp.tlb”);  
  41.       importlib(”thlo.tlb”);  
  42.    
  43.       [  
  44.       uuid(2573F891-CFEE-101A-9A9F-00AA00342820),  
  45.       aggregatable  
  46.       ]  
  47.       coclass CHello  
  48.    {  
  49.    cotype THello;  
  50.    };  
  51.   };  
  52.   
  53.   #include “ipfix.hxx”  
  54.    
  55.   extern HANDLE hEvent;  
  56.    
  57.   class CHello : public CHelloBase  
  58.   {  
  59.   public:  
  60.       IPFIX(CLSID_CHello);  
  61.    
  62.       CHello(IUnknown *pUnk);  
  63.       ~CHello();  
  64.    
  65.       HRESULT  __stdcall PrintSz(LPWSTR pwszString);  
  66.    
  67.   private:  
  68.       static int cObjRef;  
  69.   };  
  70.   
  71.   #include <windows.h>  
  72.   #include <ole2.h>  
  73.   #include <stdio.h>  
  74.   #include <stdlib.h>  
  75.   #include “thlo.h”  
  76.   #include “pshlo.h”  
  77.   #include “shlo.hxx”  
  78.   #include “mycls.hxx”  
  79.    
  80.   int CHello::cObjRef = 0;  
  81.    
  82.   CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)  
  83.   {  
  84.       cObjRef++;  
  85.       return;  
  86.   }  
  87.    
  88.   HRESULT  __stdcall  CHello::PrintSz(LPWSTR pwszString)  
  89.   {  
  90.       printf(“%ws  
  91. “, pwszString);  
  92.       return(ResultFromScode(S_OK));  
  93.   }  
  94.    
  95.   CHello::~CHello(void)  
  96.   {  
  97.    
  98.   // when the object count goes to zero, stop the server  
  99.   cObjRef–;  
  100.   if( cObjRef == 0 )  
  101.       PulseEvent(hEvent);  
  102.    
  103.   return;  
  104.   }  
  105.   
  106.   #include <windows.h>  
  107.   #include <ole2.h>  
  108.   #include “pshlo.h”  
  109.   #include “shlo.hxx”  
  110.   #include “mycls.hxx”  
  111.    
  112.   HANDLE hEvent;  
  113.    
  114.    int _cdecl main(  
  115.   int argc,  
  116.   char * argv[]  
  117.   ) {  
  118.   ULONG ulRef;  
  119.   DWORD dwRegistration;  
  120.   CHelloCF *pCF = new CHelloCF();  
  121.    
  122.   hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);  
  123.    
  124.   // Initialize the OLE libraries  
  125.   CoInitializeEx(NULL, COINIT_MULTITHREADED);  
  126.    
  127.   CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,  
  128.       REGCLS_MULTIPLEUSE, &dwRegistration);  
  129.    
  130.   // wait on an event to stop  
  131.   WaitForSingleObject(hEvent, INFINITE);  
  132.    
  133.   // revoke and release the class object  
  134.   CoRevokeClassObject(dwRegistration);  
  135.   ulRef = pCF->Release();  
  136.    
  137.   // Tell OLE we are going away.  
  138.   CoUninitialize();  
  139.    
  140.   return(0); }  
  141.    
  142.   extern CLSID CLSID_CHello;  
  143.   extern UUID LIBID_CHelloLib;  
  144.    
  145.   CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */  
  146.       0x2573F891,  
  147.       0xCFEE,  
  148.       0x101A,  
  149.       { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }  
  150.   };  
  151.    
  152.   UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */  
  153.       0x2573F890,  
  154.       0xCFEE,  
  155.       0x101A,  
  156.       { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }  
  157.   };  
  158.   
  159.   #include <windows.h>  
  160.   #include <ole2.h>  
  161.   #include <stdlib.h>  
  162.   #include <string.h>  
  163.   #include <stdio.h>  
  164.   #include “pshlo.h”  
  165.   #include “shlo.hxx”  
  166.   #include “clsid.h”  
  167.    
  168.   int _cdecl main(  
  169.   int argc,  
  170.   char * argv[]  
  171.   ) {  
  172.   HRESULT  hRslt;  
  173.   IHello        *pHello;  
  174.   ULONG  ulCnt;  
  175.   IMoniker * pmk;  
  176.   WCHAR  wcsT[_MAX_PATH];  
  177.   WCHAR  wcsPath[2 * _MAX_PATH];  
  178.    
  179.   // get object path  
  180.   wcsPath[0] = ’\0’;  
  181.   wcsT[0] = ’\0’;  
  182.   if( argc > 1) {  
  183.       mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);  
  184.       wcsupr(wcsPath);  
  185.       }  
  186.   else {  
  187.       fprintf(stderr, ”Object path must be specified\n”);  
  188.       return(1);  
  189.       }  
  190.    
  191.   // get print string  
  192.   if(argc > 2)  
  193.       mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);  
  194.   else  
  195.       wcscpy(wcsT, L”Hello World”);  
  196.    
  197.   printf(”Linking to object %ws\n”, wcsPath);  
  198.   printf(”Text String %ws\n”, wcsT);  
  199.    
  200.   // Initialize the OLE libraries  
  201.   hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);  
  202.    
  203.   if(SUCCEEDED(hRslt)) {  
  204.    
  205.       hRslt = CreateFileMoniker(wcsPath, &pmk);  
  206.       if(SUCCEEDED(hRslt))  
  207.    hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);  
  208.    
  209.       if(SUCCEEDED(hRslt)) {  
  210.    
  211.    // print a string out  
  212.    pHello->PrintSz(wcsT);  
  213.    
  214.    Sleep(2000);  
  215.    ulCnt = pHello->Release();  
  216.    }  
  217.       else  
  218.    printf(”Failure to connect, status: %lx”, hRslt);  
  219.    
  220.       // Tell OLE we are going away.  
  221.       CoUninitialize();  
  222.       }  
  223.    
  224.   return(0);  
  225.   }  
  226.    
  [
  uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
  ]
  library LHello
  {
      // bring in the master library
      importlib("actimp.tlb");
      importlib("actexp.tlb");

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

      [
      uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
      ]
      cotype THello
   {
   interface IHello;
   interface IPersistFile;
   };
  };

  [
  exe,
  uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
  ]
  module CHelloLib
  {

      // some code related header files
      importheader(<windows.h>);
      importheader(<ole2.h>);
      importheader(<except.hxx>);
      importheader("pshlo.h");
      importheader("shlo.hxx");
      importheader("mycls.hxx");

      // needed typelibs
      importlib("actimp.tlb");
      importlib("actexp.tlb");
      importlib("thlo.tlb");

      [
      uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
      aggregatable
      ]
      coclass CHello
   {
   cotype THello;
   };
  };

  #include "ipfix.hxx"

  extern HANDLE hEvent;

  class CHello : public CHelloBase
  {
  public:
      IPFIX(CLSID_CHello);

      CHello(IUnknown *pUnk);
      ~CHello();

      HRESULT  __stdcall PrintSz(LPWSTR pwszString);

  private:
      static int cObjRef;
  };

  #include <windows.h>
  #include <ole2.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include "thlo.h"
  #include "pshlo.h"
  #include "shlo.hxx"
  #include "mycls.hxx"

  int CHello::cObjRef = 0;

  CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
  {
      cObjRef++;
      return;
  }

  HRESULT  __stdcall  CHello::PrintSz(LPWSTR pwszString)
  {
      printf("%ws
", pwszString);
      return(ResultFromScode(S_OK));
  }

  CHello::~CHello(void)
  {

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

  return;
  }

  #include <windows.h>
  #include <ole2.h>
  #include "pshlo.h"
  #include "shlo.hxx"
  #include "mycls.hxx"

  HANDLE hEvent;

   int _cdecl main(
  int argc,
  char * argv[]
  ) {
  ULONG ulRef;
  DWORD dwRegistration;
  CHelloCF *pCF = new CHelloCF();

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

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

  CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
      REGCLS_MULTIPLEUSE, &dwRegistration);

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

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

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

  return(0); }

  extern CLSID CLSID_CHello;
  extern UUID LIBID_CHelloLib;

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

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

  #include <windows.h>
  #include <ole2.h>
  #include <stdlib.h>
  #include <string.h>
  #include <stdio.h>
  #include "pshlo.h"
  #include "shlo.hxx"
  #include "clsid.h"

  int _cdecl main(
  int argc,
  char * argv[]
  ) {
  HRESULT  hRslt;
  IHello        *pHello;
  ULONG  ulCnt;
  IMoniker * pmk;
  WCHAR  wcsT[_MAX_PATH];
  WCHAR  wcsPath[2 * _MAX_PATH];

  // get object path
  wcsPath[0] = '\0';
  wcsT[0] = '\0';
  if( argc > 1) {
      mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
      wcsupr(wcsPath);
      }
  else {
      fprintf(stderr, "Object path must be specified\n");
      return(1);
      }

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

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

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

  if(SUCCEEDED(hRslt)) {

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

      if(SUCCEEDED(hRslt)) {

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

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

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

  return(0);
  }



新手黑客
[python] view plain copy
print ?
  1. #!/usr/local/bin/perl  
  2. msg=<span class="string">"Hello,&nbsp;world.\n"</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="keyword">if</span><span>&nbsp;(#ARGV >= 0) {  
  3.   while(defined(arg=shift(@ARGV)))&nbsp;{&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;outfilename&nbsp;=&nbsp;arg;&nbsp;&nbsp;</span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;open(FILE,&nbsp;<span class="string">"&gt;"</span><span>&nbsp;.&nbsp;outfilename)&nbsp;||&nbsp;die&nbsp;</span><span class="string">"Can't&nbsp;write&nbsp;arg:&nbsp;!\n"</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">print</span><span>&nbsp;(FILE&nbsp;msg);&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;&nbsp;&nbsp;close(FILE)&nbsp;||&nbsp;die&nbsp;<span class="string">"Can't&nbsp;close&nbsp;arg:&nbsp;!\n"</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class=""><span>}&nbsp;<span class="keyword">else</span><span>&nbsp;{&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;<span class="keyword">print</span><span>&nbsp;(msg);  
  4. }  
  5. 1;  
#!/usr/local/bin/perl
$msg="Hello, world.\n";
if ($#ARGV >= 0) {
  while(defined($arg=shift(@ARGV))) {
    $outfilename = $arg;
    open(FILE, ">" . $outfilename) || die "Can't write $arg: $!\n";
    print (FILE $msg);
    close(FILE) || die "Can't close $arg: $!\n";
  }
} else {
  print ($msg);
}
1;


有经验的黑客
  1. #include <stdio.h>  
  2. #define S “Hello, World\n”  
  3. main(){exit(printf(S) == strlen(S) ? 0 : 1);}  
#include <stdio.h>




#define S "Hello, World\n" main(){exit(printf(S) == strlen(S) ? 0 : 1);}

入行干过好些年的黑客
  1. % cc -o a.out ~/src/misc/hw/hw.c  
  2. % a.out  
  3.    
% cc -o a.out ~/src/misc/hw/hw.c
% a.out
 


黑客大师
  1. % echo “Hello, world.”  
% echo "Hello, world."


新手经理
  1. 10 PRINT “HELLO WORLD”  
  2. 20 END  
10 PRINT "HELLO WORLD"
20 END

中级经理
  1. mail -s “Hello, world.” bob@b12  
  2. 鲍勃,你能帮我写个输出“Hello, world.”的程序么?  
  3. 我明天就要。  
  4. 谢谢~  
  5.    
mail -s "Hello, world." bob@b12
鲍勃,你能帮我写个输出“Hello, world.”的程序么?
我明天就要。
谢谢~
 

高级经理
  1. % zmail jim  
  2. Jim,我今天下午就要输出 “Hello, world.” 的程序!  
  3.    
% zmail jim
Jim,我今天下午就要输出 “Hello, world.” 的程序!
 

CEO/首席执行官

  1. % letter  
  2. letter: Command not found.  
  3. % mail  
  4. To: ^X ^F ^C  
  5. % help mail  
  6. help: Command not found.  
  7. % damn!  
  8. !: Event unrecognized  
  9. % logout  
% letter
letter: Command not found.
% mail
To: ^X ^F ^C
% help mail
help: Command not found.
% damn!
!: Event unrecognized
% logout


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值