|
楼主 |
发表于 2005 年 2 月 9 日 12:44:20
|
显示全部楼层
程序员的进化--从学生到首席执行官
/*-------------------------------------------
: |! r/ N; U) `$ A: \, s程序员的进化--从学生到首席执行官
# S! \! {% |2 z* f翻译 2002 王咏刚 http://www.contextfree.net/
" C& Q3 G% l7 b( [, X! r7 Q v转译自 Omri's Computer Humor Page* h1 f$ |4 ?' Q' W, g& V4 ~
http://www.cs.bgu.ac.il/~omri/Humor/- p! Q6 y, r1 w" Y
-------------------------------------------*/
& ^% w% X/ M! T2 O% W/ Q( L G- v( ~4 c$ a6 ^1 b
--------------------------------------------------------------------------------
3 x# w, u* X! ^# x5 `2 K/ } B中学阶段
, P8 ?: r& A: Q" i0 N: A# q7 _10 PRINT "HELLO WORLD"- y0 l. s7 G; g ?' [
20 END8 o2 e$ U0 w/ s% \
--------------------------------------------------------------------------------
2 {' v& s/ ?# Q8 o2 k大学一年级( `# X5 e! N) E4 `; [
program Hello(input, output)
. Y3 G8 T' O8 Y: xbegin$ s1 Q. J( Y0 I+ q) W
writeln('Hello World')( ^! q/ K7 V0 C7 w
end.0 h5 S, O. W* C( d0 W' J
--------------------------------------------------------------------------------' L7 g' w" y" i P; Z* F Y2 E& O5 }. M
大学高年级& W4 T9 u/ ^5 t- o ^4 H
(defun hello
: V3 {( U" ~ Q2 J* }: m$ L(print5 e) O$ Y- Z% k; A" _& W) r4 U# F
(cons 'Hello (list 'World))))
1 G5 o* T" c/ }. x/ M# G! W--------------------------------------------------------------------------------
& b; v4 k8 z$ x1 ?初级程序员 J2 J2 n3 Z* ?6 I: M
#include
& j! q$ t1 ?$ J \0 Hvoid main(void); s/ z9 A! u8 v) d
{
7 L) v' n% n& o Xchar *message[] = {"Hello ", "World"};
* N7 ^! K; `8 Y, \7 yint i;
3 h8 h2 U5 j1 P* `: Z) P* Hfor(i = 0; i < 2; ++i)
8 E/ t6 y( i8 C$ _( u( ]( d0 {+ E; ^printf("%s", message);
X5 J- q \* w4 I$ ]& [printf("n");; ~2 {* @7 U$ }' g
}4 w3 r$ j7 k) f5 b/ M; ^
--------------------------------------------------------------------------------
$ t3 n& M& ^; X. A9 }编程老鸟; @3 J! m1 K; X6 f
#include : y/ J& k7 u' y$ {6 M M8 Z. j
#include 4 T: \% D3 o3 L! M- D3 l
class string
0 q: z4 n4 C: ?% ?7 F9 [' V{
8 Z& d3 X4 w" J% p- Sprivate:' W2 X- X% [, C& c
int size;1 | ~9 v6 _/ e, y4 C' K9 N
char *ptr;5 r' c, k" N: |/ g: p
public:: R F$ q* W& P
string() : size(0), ptr(new char('{CONTENT}')) {}
9 s: j, f% f4 y" i9 G, X4 W H9 k! Ustring(const string &s) : size(s.size): c* e6 n8 n; I3 n4 ^2 f
{+ C7 r% K4 s5 ]4 x
ptr = new char[size + 1];" W* M' t4 U/ V3 {
strcpy(ptr, s.ptr);
6 i! x( e& ?4 n) k' i}; Q1 P, d! }8 q& X+ k! N
~string()
2 t. n) c. P% ?5 f- ]3 i# W9 H d$ @{. Q$ c. e) S! Y% o/ Q! V
delete [] ptr;
k; B6 S5 L3 O! I" v# p}6 S5 H! @7 P% f
friend ostream &operator <<(ostream &, const string &);7 D% T1 T+ l; S( i+ a, _$ {
string &operator=(const char *);9 C0 @ N! J; W/ ^
};) B1 w9 V- n4 K- m
ostream &operator<<(ostream &stream, const string &s)3 {' ~# _6 e9 [2 ?8 K8 b4 h0 U
{
m; E! g/ L/ h0 ?return(stream << s.ptr); u# e6 R. n3 P1 v
}
. Q- l8 m$ ` \* j- Y2 |9 s- Estring &string: perator=(const char *chrs)
( @/ G+ i: G: S) Y{5 \: ^1 g- ^! @) @! g' e
if (this != &chrs)! h# E" j& J2 l
{9 U# C3 s0 [8 }
delete [] ptr;
* N$ E) p& f6 t* [* E g/ Asize = strlen(chrs);
% N; ~& H! k! ]) @5 j) vptr = new char[size + 1];+ x' w+ ~0 ^8 U
strcpy(ptr, chrs);
$ T- v$ B/ i/ @: e}8 ]/ y' l; a* I/ {# n, e( n
return(*this);
- k$ Q& T( d# @}$ t0 T! j9 j' L1 `5 b/ {
int main()
* x* U" z$ u! P! c: x% P6 G{
: u T% A' M" i5 j- \* `' Tstring str;
# d/ d' Q9 w0 U5 r* T ~str = "Hello World";
3 ^5 l% {& ?" \8 Jcout << str << end
! }' ~1 i/ z; k& K+ s, }) areturn(0);3 `, \" ~, y+ d4 m1 S# R( I ^
}4 n( L. c7 e {4 m
--------------------------------------------------------------------------------+ C8 {; P+ `0 T( o
编程高手" B9 \6 H, f6 b! w2 b+ d1 Y
[
$ V: {+ w0 E5 h! d$ O% ]uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
: C; t" H0 B! s6 |7 o]
: M/ |; E+ o& l1 k6 I( Ulibrary LHello( G, Y6 f6 j4 O9 c& \( c2 t
{6 y! v, v, e9 w/ d7 C
// bring in the master library
4 w- O- t! I$ Y, P) a. ?+ kimportlib("actimp.tlb");! K! b8 b& d3 P# ^
importlib("actexp.tlb");
% v8 X8 z! W; j" l& G// bring in my interfaces
1 t2 x. [9 ?* o/ r' D#include "pshlo.idl"
2 D+ c, n* l7 V. B6 C9 I3 R& g8 T[7 m* E, {% H# P( y8 p- ~* s4 {' t) i
uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
+ S& ]1 Z- L- d; f; x]" O1 r: D' m4 a6 ^# M
cotype THello
, m0 u, u8 H$ Q* m+ ^8 w4 X; U7 H{8 ^* ]+ ~* F5 F% c
interface IHello;
9 y$ ?/ w% t2 |" v1 W g, Y: kinterface IPersistFile;& Q3 n, g' z7 m* O
};. P/ N) s6 i$ s# Z/ y6 N: U
};0 B; S: J; R' c# i$ s( p
[9 f/ ]: k/ l8 U: t4 a
exe,1 U5 ] s$ K+ d
uuid(2573F890-CFEE-101A-9A9F-00AA00342820)# Z6 N0 h, D, G) P c6 k$ _! ]- C( N
]
# `1 i0 j. b! v1 R9 Y/ Zmodule CHelloLib" n* E# B8 Y( o" u
{9 [3 t7 ~% {4 P: t
// some code related header files3 j" r2 ^- Y$ g P+ Z4 Z
importheader();0 ~' E% G8 a* a" |
importheader();0 U6 Q& R! \% F
importheader();6 V1 w- j u; N. j' V i f
importheader("pshlo.h");
6 M1 w6 u r! Q @2 cimportheader("shlo.hxx");' |1 Q/ C+ C6 ^2 q( V
importheader("mycls.hxx");8 w7 \- c+ H% d2 C
// needed typelibs, C/ a" {( X' O7 V) [/ u- K
importlib("actimp.tlb");1 V5 C1 j6 P8 g1 \; d* I2 g
importlib("actexp.tlb");
* _9 _3 V( r+ h- m7 d) R" {importlib("thlo.tlb");
) z8 Z( |3 [/ v% g% P& w" H3 A4 D[
, v& v. e. n0 E, C! T& G( puuid(2573F891-CFEE-101A-9A9F-00AA00342820),3 G# Z5 A8 i: w7 n7 @
aggregatable
" ~/ R/ J3 R/ O2 B9 Y]% r% z& s2 Z: u7 n$ P, {
coclass CHello
) L. @# ?4 [8 W3 j- O, ?{
2 t$ G' ]9 x- C p6 Jcotype THello;
8 G/ `" ?! m/ z3 G};, q/ O; C* u& C' M. t' O
};3 h3 O7 B- k2 T$ j
#include "ipfix.hxx"# |# O. t3 M6 p7 a
extern HANDLE hEvent;0 B) V0 @- m, v& ^. e. l
class CHello : public CHelloBase
0 i8 ?8 k: c7 F{
; v1 u/ w+ W! ^5 ]- A" Epublic:. i! M, D4 b2 I, C0 o* b. a
IPFIX(CLSID_CHello);
n4 @' M( `9 [3 [/ ?# L$ ?CHello(IUnknown *pUnk);
) S: l% N0 g. d$ i4 ?~CHello();
6 Q( n3 r% ^$ E2 t! c$ Z4 jHRESULT __stdcall PrintSz(LPWSTR pwszString);
+ z; K0 V Q+ Q; }8 G$ g+ S2 Fprivate:
1 ~6 Y; n9 N4 _+ @2 fstatic int cObjRef;& n' U" F2 s$ j. H
};; Y6 K6 ~$ Z+ y, M& x
#include
9 L* m7 _/ W/ d) y7 N% @#include + |3 v* b5 C9 d
#include
4 b+ k1 s8 L* S V Y5 T- i#include
; J# t) b2 K* ?+ }6 E& T#include "thlo.h"
5 I: C+ H, Z3 A# N P#include "pshlo.h"3 P; x- d) u# m [" s9 k n# c
#include "shlo.hxx"/ L1 q, U$ ] y
#include "mycls.hxx"% v3 h9 T' ~; j( X2 L) h$ H2 _
int CHello::cObjRef = 0;
0 l) N( k+ Z vCHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
# K; U* y3 _& t6 ^( e3 C/ o& V' f3 A{
; I& q Y# j: p7 B* M7 x9 IcObjRef++;
( R9 w" }( u2 b/ k areturn;- S3 y) C5 E, b/ n7 x
}
5 Z* N) B: w! ?) ?4 u& F+ vHRESULT __stdcall CHello: rintSz(LPWSTR pwszString)2 y* X. _+ n* Q* L; ~3 i1 Q
{
9 W2 q }7 u) D) b$ Oprintf("%wsn", pwszString);
. M$ ^) s O: D/ v# j+ Lreturn(ResultFromScode(S_OK));8 E; ~- V; Z( ?% Y, z* | G
} F$ t5 G4 I4 n. i; }/ n. C
CHello::~CHello(void)1 N) t+ @! \$ {$ c
{
Q" l2 L& u' Q0 H/ v+ E9 `2 w// when the object count goes to zero, stop the server9 w: m" Z+ j9 X( z
cObjRef--;
g9 ]4 t/ Z; n' P. yif( cObjRef == 0 )' A8 ]5 c% }- _: c
PulseEvent(hEvent);
7 M$ y: P" p/ ~return;5 X( M) ]9 f& w2 h: g7 j" P: H5 v- o
}' Q3 g9 Y8 u! T# ?" P
#include % M/ J) a" a- Q1 R9 m; D1 O
#include ' L% k% i5 B8 `( T/ Z
#include "pshlo.h"
5 B$ s' P% \. g. Q3 y9 E#include "shlo.hxx"" k- ?( V; `# D- j/ l; t' I3 q8 B
#include "mycls.hxx": V, b5 W8 c4 A
HANDLE hEvent;
0 e. s5 y; O. ]int _cdecl main(
* b" ?3 T/ r" J5 dint argc,
: N# x1 {7 I* L% X8 g) Ichar * argv[]( f+ @( U5 c5 w* r
) {( j8 b8 j! Y' V' |7 R1 k% }
ULONG ulRef;/ a, d1 u6 j+ l- D X3 I
DWORD dwRegistration;$ W8 N9 e! |0 t+ Z! I* |: L1 \
CHelloCF *pCF = new CHelloCF();- g4 {9 V2 A& s- I" J9 \
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
) b* ?8 G) ^# P* L// Initialize the OLE libraries
0 A" z( c- c1 I" g. ?4 l9 nCoInitializeEx(NULL, COINIT_MULTITHREADED);
b6 P. W7 z( m wCoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
o. j. h) `: n. F- uREGCLS_MULTIPLEUSE, &dwRegistration);- w9 i5 M6 H1 {3 v6 V8 k
// wait on an event to stop3 u# E8 F7 l; F9 G1 y+ U2 B3 p: v
WaitForSingleObject(hEvent, INFINITE);
1 |. M2 J( B; ?" Q8 v# A3 |! H// revoke and release the class object& X B: l; `! C
CoRevokeClassObject(dwRegistration);! F' k9 q7 C3 r' X
ulRef = pCF->Release();
t* V% {) ]' z9 v/ S7 q1 m4 m' N// Tell OLE we are going away.
8 ^! E( j7 Z, _% f3 y( OCoUninitialize();
6 e" p6 ^' z: t+ i7 w X {return(0);2 u& b4 x" Z4 b, p" e
}
?- o$ e6 m6 p* k& o" U2 Jextern CLSID CLSID_CHello;/ b6 f2 V7 o4 r* z
extern UUID LIBID_CHelloLib;
2 c) X! W+ y8 W; kCLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */$ |, N4 q4 u2 s8 {
0x2573F891,
' Y% w( C3 n+ p7 v! }& w0 j0xCFEE,& B& S- J2 S$ k- a4 I
0x101A,
9 _" B* Z' x: e' x{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 } S. H1 t1 P- J$ R
};' [3 ?9 w3 J3 d7 Y& e( u! E c
UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */
3 v0 o1 W9 b* w9 e0x2573F890,
$ P2 T( T9 R9 d0 s% C: _. {0xCFEE,
# A- V4 G. ?% ^* {8 p0x101A,
/ B6 _$ ~6 d/ I3 N c$ J+ G{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }$ W5 j8 k0 S1 |3 \+ ?
};
" j; Y. b# y$ g9 E& b#include
) G. o1 x3 ~% n9 h1 d. X2 e6 `#include
$ O! k( s; ^. x4 o/ ^. _( ~2 d6 @#include
1 L2 i \9 Z# C5 G- E6 }#include
$ K' U! E8 Z m' }& t" v#include 2 I7 i" {, w( ^9 W( }2 a
#include "pshlo.h"
7 l% k) Q) d# J2 f j: J#include "shlo.hxx"
2 x% v7 F- B- d, C/ l, f#include "clsid.h"8 D/ t6 P: K, U
int _cdecl main(
2 y# n3 s, ?8 P1 tint argc,
& O; V& M, u w% w- N3 ]char * argv[]7 h& p% I$ W, @' x4 n
) {6 x$ P6 V8 r$ ~4 I3 `
HRESULT hRslt;
- w( R$ |8 }8 h' g8 Y" J2 ^5 YIHello *pHello;# V- ]) d* l! E* }+ N% b& \
ULONG ulCnt;" G. I+ p6 z3 g" c5 M
IMoniker * pmk;3 {% c" G+ |6 M; `) C+ u6 f4 z
WCHAR wcsT[_MAX_PATH];# o2 s* Y2 e$ z& w, d
WCHAR wcsPath[2 * _MAX_PATH];
4 Y4 J o: N. u6 }! }// get object path# O1 {: J, W x; m) {1 l
wcsPath[0] = '{CONTENT}';
* Q- C$ F! X2 w/ ywcsT[0] = '{CONTENT}';( _" q7 x: {% }& o" I7 l
if( argc > 1) {
3 w ^/ _6 i1 ?4 w9 c: wmbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);8 P( U& z# l, E! N, i" [% @
wcsupr(wcsPath);2 y! t( f+ N0 ~3 l
}! K: [; `5 y1 |6 Q, a# A$ E8 x
else {
+ L6 F* ]9 `1 |1 d) x% k6 O! Hfprintf(stderr, "Object path must be specifiedn");
3 T' I6 [4 \& S5 breturn(1);5 O1 k/ F* L. [
}$ U; P/ a( m: N
// get print string
7 c5 ~, O1 B+ m* d0 Jif(argc > 2)) C) t) d$ a. b! F2 f1 N
mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
# [7 @2 S: A5 F5 z4 K& `else
% q7 u& u& C k3 twcscpy(wcsT, L"Hello World");
2 A4 ^4 ]& d) c# s1 r% ?# o8 Uprintf("Linking to object %wsn", wcsPath);
6 L8 Y( t; N, I/ J% Q) a. zprintf("Text String %wsn", wcsT);
& }6 f4 W7 Z: \$ b" |// Initialize the OLE libraries: a) p: B7 K' c3 `, C8 w& |( v
hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);
" X: u1 H: y8 \- Iif(SUCCEEDED(hRslt)) {' g5 s. I6 I% F: q" l1 L" x
hRslt = CreateFileMoniker(wcsPath, &pmk);% N0 k, V6 P! @ T% _* | ^# G
if(SUCCEEDED(hRslt))1 `! z! R" Z- C; T! S) E. _
hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);1 S2 C9 A5 }, S! d: p
if(SUCCEEDED(hRslt)) {
6 V- O( s$ F6 h! V7 L1 Y+ E) t// print a string out, w7 x% _' p5 d! J5 Y- X. C; J& T6 c
pHello-> rintSz(wcsT);
c0 E0 _' J6 k, t& hSleep(2000);
- E: D' y5 L) xulCnt = pHello->Release();
% H# U9 H+ ~! G( |2 U) U}- f, R3 i n& G/ Z' E$ d
else, T3 \4 B$ F+ k5 b. A! z6 }" [8 a
printf("Failure to connect, status: %lx", hRslt);
% @$ u/ A: E0 W" G5 a+ i! G2 {0 `// Tell OLE we are going away.# o+ ^3 c; O$ e5 f3 I0 e9 A6 j
CoUninitialize();
' @% g1 H% A5 s}
0 c' `% t+ c( _7 W' O* ?return(0);* B. D4 ?) F3 ?. K' a- |2 w
} % m9 g/ f3 n+ F( _. |
--------------------------------------------------------------------------------7 g* t p# o* I$ g! r7 D# L
黑客初阶
# i& W0 i( g, q2 A- K0 X2 y#!/usr/local/bin/perl
- {# x) q/ F) L& J; ?$msg="Hello, world.n";3 W6 `' v# j; G" m; F& D
if ($#ARGV >= 0) {
`7 T9 i N0 Q& P/ c2 wwhile(defined($arg=shift(@ARGV))) {
/ Z9 m, D/ p( \' b7 i$outfilename = $arg;
+ C2 K9 i( J3 R2 Sopen(FILE, ">" . $outfilename) || die "Can't write $arg: $!n";
& z/ f0 T9 F8 X5 m( x0 Iprint (FILE $msg);
/ M5 r2 h% N/ R$ xclose(FILE) || die "Can't close $arg: $!n";
`& L# ] Q8 g9 d: q: C- U* w}
& t1 h* c5 w2 g. V. E# D! y} else {
$ G5 u/ t8 q) y9 `# h3 @" Fprint ($msg);" x. u& n8 J' H- L: K& Q) P
}
* B; Q* l8 S" q) T1;/ h5 @+ ]- V1 F8 ^2 @- y, c
--------------------------------------------------------------------------------
" @# c9 P- P9 x4 ?4 h9 k8 ~黑客有成( Z1 a3 u9 q H( s& Z. A
#include 0 M P1 Y ~, \" K+ U! c% G
#define S "Hello, Worldn"9 q+ y( ]8 N8 Y& z3 u7 U
main(){exit(printf(S) == strlen(S) ? 0 : 1);}
; }5 \) t: \ ]" u, }--------------------------------------------------------------------------------
$ u& L; _1 r" f; x! B/ g+ J/ v1 V黑客高手' I8 _7 s4 R, @2 N& Z. E
% cc -o a.out ~/src/misc/hw/hw.c
1 W$ O: Y8 Q. n8 ?# p8 G' S: I, V% a.out
, W b# ^. j1 n. L3 y* h9 o$ W7 \--------------------------------------------------------------------------------# R" ?2 z$ |0 ]% k! [" B7 |
黑客大虾. O. u) z4 B0 A1 w [' b
% cat5 A$ Q1 A1 }% x; k
Hello, world.. P. G0 u9 O6 f2 n. y
^D$ j% n2 c l0 H9 u
--------------------------------------------------------------------------------; J. ^6 z, ^0 K# B4 J
初级经理1 J& Q2 t& U8 b! g0 S
10 PRINT "HELLO WORLD" ~. M- o) v6 S0 W& ^
20 END7 }4 J+ I/ C, ^, S0 {1 o: @. e
--------------------------------------------------------------------------------. [3 f5 I7 A5 S6 o
中级经理
0 ?+ o6 b7 |! imail -s "Hello, world." bob@b12$ |, Y. I1 T! B; W
Bob, could you please write me a program that prints "Hello, world."?, p/ y, L+ z& `
I need it by tomorrow.% U& R5 y0 i. G
^D/ H7 e8 p% w$ L
--------------------------------------------------------------------------------8 O; v( h4 u: B2 ^' b7 D6 x8 U9 o
高级经理! M# H9 M9 W0 o3 A, b5 B& U: x: z
% zmail jim9 _/ X2 H n6 q6 y
I need a "Hello, world." program by this afternoon. G2 L, ?) _5 Y. R) \
--------------------------------------------------------------------------------$ p6 P R$ x" C9 j2 i. k0 v
首席执行官
/ e. }+ `! r1 X' n1 T# ^% letter g* G; w! f# I$ Q' Y$ |3 X3 `' R5 n
letter: Command not found.- o! r1 t! M* D* v8 v) \
% mail& D$ T. y7 D9 |" t0 ]
To: ^X ^F ^C
( G5 W; h. {/ V3 o: G% help mail9 {5 J* V4 K: {+ {4 k
help: Command not found.3 l% E. e7 J3 p" c6 a" J, F) E
% damn!. ?$ O/ d) T) t. P M
!: Event unrecognized
2 d; e8 T* P5 ^+ A6 y* `( E' K% logout
) t. k, R& P6 R% l! o" q+ @; u% ~-------------------------------------------------------------------------------- |
|