(轉載)幽默:程序員的進化

原文地址:http://coolshell.cn/articles/172.html

高中時期

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

大學新生

  1. program Hello(input, output)  
  2.   begin  
  3.     writeln(\'Hello World\')  
  4.   end.  


高年級大學生

  1. #include <stdio.h>  
  2.   
  3. int main(void)  
  4. {  
  5.    printf("Hello, world!\\n");  
  6.    return 0;  
  7. }  
  8. </stdio.h>  

職業新手

  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. }  
  11. stdio.h>  

職業老手

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

大師級

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

黑客學徒

  #!/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);}  
  4. stdio.h>  

老練的黑客

  % cc -o a.out ~/src/misc/hw/hw.c
  % a.out

超級黑客

  % echo "Hello, world."

一線經理

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

中層經理

  mail -s "Hello, world." bob@b12
  Bob, could you please write me a program that prints "Hello, world."?
  I need it by tomorrow.
  ^D

高級經理

  % zmail jim
  I need a "Hello, world." program by this afternoon.

首席執行官

  % letter
  letter: Command not found.
  % mail
  To: ^X ^F ^C
  % help mail
  help: Command not found.
  % damn!
  !: Event unrecognized
  % logout

來源:未知


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章