home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / datafiles / text / fun / programmerevolution.txt < prev    next >
Lisp/Scheme  |  1995-02-28  |  6KB  |  327 lines

  1.   The Evolution of a Programmer
  2.    -----------------------------
  3.   
  4.   High School/Jr.High
  5.   ===================
  6.   10 PRINT "HELLO WORLD"
  7.   20 END
  8.   
  9.   First year in College
  10.   =====================
  11.   program Hello(input, output)
  12.     begin
  13.       writeln('Hello World')
  14.     end.
  15.   
  16.   Senior year in College
  17.   ======================
  18.   (defun hello
  19.     (print
  20.       (cons 'Hello (list 'World))))
  21.   
  22.   New professional
  23.   ================
  24.   #include <stdio.h>
  25.   void main(void)
  26.   {
  27.     char *message[] = {"Hello ", "World"};
  28.     int i;
  29.   
  30.     for(i = 0; i < 2; ++i)
  31.       printf("%s", message[i]);
  32.     printf("\n");
  33.   }
  34.   
  35.   Seasoned professional
  36.   =====================
  37.   #include <iostream.h>
  38.   #include <string.h>
  39.   
  40.   class string
  41.   {
  42.   private:
  43.     int size;
  44.     char *ptr;
  45.   
  46.   public:
  47.     string() : size(0), ptr(new char('\0')) {}
  48.   
  49.     string(const string &s) : size(s.size)
  50.     {
  51.       ptr = new char[size + 1];
  52.       strcpy(ptr, s.ptr);
  53.     }
  54.   
  55.     ~string()
  56.     {
  57.       delete [] ptr;
  58.     }
  59.   
  60.     friend ostream &operator <<(ostream &, const string &);
  61.     string &operator=(const char *);
  62.   };
  63.   
  64.   ostream &operator<<(ostream &stream, const string &s)
  65.   {
  66.     return(stream << s.ptr);
  67.   }
  68.   
  69.   string &string::operator=(const char *chrs)
  70.   {
  71.     if (this != &chrs)
  72.     {
  73.       delete [] ptr;
  74.       size = strlen(chrs);
  75.       ptr = new char[size + 1];
  76.       strcpy(ptr, chrs);
  77.     }
  78.     return(*this);
  79.   }
  80.   
  81.   int main()
  82.   {
  83.     string str;
  84.   
  85.     str = "Hello World";
  86.     cout << str << endl;
  87.   
  88.     return(0);
  89.   }
  90.   
  91.   Master Programmer
  92.   =================
  93.   [
  94.   uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
  95.   ]
  96.   library LHello
  97.   {
  98.       // bring in the master library
  99.       importlib("actimp.tlb");
  100.       importlib("actexp.tlb");
  101.   
  102.       // bring in my interfaces
  103.       #include "pshlo.idl"
  104.   
  105.       [
  106.       uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
  107.       ]
  108.       cotype THello
  109.           {
  110.           interface IHello;
  111.           interface IPersistFile;
  112.           };
  113.   };
  114.   
  115.   [
  116.   exe,
  117.   uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
  118.   ]
  119.   module CHelloLib
  120.   {
  121.   
  122.       // some code related header files
  123.       importheader(<windows.h>);
  124.       importheader(<ole2.h>);
  125.       importheader(<except.hxx>);
  126.       importheader("pshlo.h");
  127.       importheader("shlo.hxx");
  128.       importheader("mycls.hxx");
  129.   
  130.       // needed typelibs
  131.       importlib("actimp.tlb");
  132.       importlib("actexp.tlb");
  133.       importlib("thlo.tlb");
  134.   
  135.       [
  136.       uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
  137.       aggregatable
  138.       ]
  139.       coclass CHello
  140.           {
  141.           cotype THello;
  142.           };
  143.   };
  144.   
  145.   
  146.   #include "ipfix.hxx"
  147.   
  148.   extern HANDLE hEvent;
  149.   
  150.   class CHello : public CHelloBase
  151.   {
  152.   public:
  153.       IPFIX(CLSID_CHello);
  154.   
  155.       CHello(IUnknown *pUnk);
  156.       ~CHello();
  157.   
  158.       HRESULT  __stdcall  PrintSz(LPWSTR pwszString);
  159.   
  160.   private:
  161.       static int cObjRef;
  162.   };
  163.   
  164.   
  165.   #include <windows.h>
  166.   #include <ole2.h>
  167.   #include <stdio.h>
  168.   #include <stdlib.h>
  169.   #include "thlo.h"
  170.   #include "pshlo.h"
  171.   #include "shlo.hxx"
  172.   #include "mycls.hxx"
  173.   
  174.   int CHello::cObjRef = 0;
  175.   
  176.   CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
  177.   {
  178.       cObjRef++;
  179.       return;
  180.   }
  181.   
  182.   HRESULT  __stdcall  CHello::PrintSz(LPWSTR pwszString)
  183.   {
  184.       printf("%ws\n", pwszString);
  185.       return(ResultFromScode(S_OK));
  186.   }
  187.   
  188.   
  189.   CHello::~CHello(void)
  190.   {
  191.   
  192.   // when the object count goes to zero, stop the server
  193.   cObjRef--;
  194.   if( cObjRef == 0 )
  195.       PulseEvent(hEvent);
  196.   
  197.   return;
  198.   }
  199.   
  200.   #include <windows.h>
  201.   #include <ole2.h>
  202.   #include "pshlo.h"
  203.   #include "shlo.hxx"
  204.   #include "mycls.hxx"
  205.   
  206.   HANDLE hEvent;
  207.   
  208.    int _cdecl main(
  209.   int argc,
  210.   char * argv[]
  211.   ) {
  212.   ULONG ulRef;
  213.   DWORD dwRegistration;
  214.   CHelloCF *pCF = new CHelloCF();
  215.   
  216.   hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  217.   
  218.   // Initialize the OLE libraries
  219.   CoInitializeEx(NULL, COINIT_MULTITHREADED);
  220.   
  221.   CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
  222.                     REGCLS_MULTIPLEUSE, &dwRegistration);
  223.   
  224.   // wait on an event to stop
  225.   WaitForSingleObject(hEvent, INFINITE);
  226.   
  227.   //      revoke and release the class object
  228.   CoRevokeClassObject(dwRegistration);
  229.   ulRef = pCF->Release();
  230.   
  231.   // Tell OLE we are going away.
  232.   CoUninitialize();
  233.   
  234.   return(0);
  235.   }
  236.   
  237.   extern CLSID CLSID_CHello;
  238.   extern UUID LIBID_CHelloLib;
  239.   
  240.   CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */
  241.       0x2573F891,
  242.       0xCFEE,
  243.       0x101A,
  244.       { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  245.   };
  246.   
  247.   UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */
  248.       0x2573F890,
  249.       0xCFEE,
  250.       0x101A,
  251.       { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  252.   };
  253.   
  254.   #include <windows.h>
  255.   #include <ole2.h>
  256.   #include <stdlib.h>
  257.   #include <string.h>
  258.   #include <stdio.h>
  259.   #include "pshlo.h"
  260.   #include "shlo.hxx"
  261.   #include "clsid.h"
  262.   
  263.   int _cdecl main(
  264.   int argc,
  265.   char * argv[]
  266.   ) {
  267.   HRESULT         hRslt;
  268.   IHello         *pHello;
  269.   ULONG           ulCnt;
  270.   IMoniker *      pmk;
  271.   WCHAR           wcsT[_MAX_PATH];
  272.   WCHAR           wcsPath[2 * _MAX_PATH];
  273.   
  274.   // get object path
  275.   wcsPath[0] = '\0';
  276.   wcsT[0] = '\0';
  277.   if( argc > 1) {
  278.       mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
  279.       wcsupr(wcsPath);
  280.       }
  281.   else {
  282.       fprintf(stderr, "Object path must be specified\n");
  283.       return(1);
  284.       }
  285.   
  286.   // get print string
  287.   if(argc > 2)
  288.       mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
  289.   else
  290.       wcscpy(wcsT, L"Hello World");
  291.   
  292.   printf("Linking to object %ws\n", wcsPath);
  293.   printf("Text String %ws\n", wcsT);
  294.   
  295.   // Initialize the OLE libraries
  296.   hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  297.   
  298.   if(SUCCEEDED(hRslt)) {
  299.   
  300.   
  301.       hRslt = CreateFileMoniker(wcsPath, &pmk);
  302.       if(SUCCEEDED(hRslt))
  303.           hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);
  304.   
  305.       if(SUCCEEDED(hRslt)) {
  306.   
  307.           // print a string out
  308.           pHello->PrintSz(wcsT);
  309.   
  310.           Sleep(2000);
  311.           ulCnt = pHello->Release();
  312.           }
  313.       else
  314.           printf("Failure to connect, status: %lx", hRslt);
  315.   
  316.       // Tell OLE we are going away.
  317.       CoUninitialize();
  318.       }
  319.   
  320.   return(0);
  321.   }
  322.  
  323.  
  324. MANAGER:
  325.  
  326. Say, can you make me a program that prints out "Hello, World."?
  327.