|
楼主 |
发表于 2005 年 2 月 9 日 12:44:20
|
显示全部楼层
程序员的进化--从学生到首席执行官
/*-------------------------------------------
# ?2 i4 L5 E( n5 o3 u程序员的进化--从学生到首席执行官% S, }+ V* l* {4 Z8 a1 j- j
翻译 2002 王咏刚 http://www.contextfree.net/
6 H5 B$ v) G; c8 C转译自 Omri's Computer Humor Page0 I6 j- c5 Y1 k- X
http://www.cs.bgu.ac.il/~omri/Humor/
( ~ O$ f6 O: I3 G [- z-------------------------------------------*/
. C% H# U1 ]1 {4 k$ V0 W, g
9 u" w/ Z4 f1 ^) E: N4 y" J. t$ D--------------------------------------------------------------------------------
% d4 J7 [3 h! }. @8 ^中学阶段
* Z- Z8 y0 {% w6 c& d10 PRINT "HELLO WORLD"; K0 `! w* e/ {$ ~9 c: n6 T. w
20 END( ~/ K$ o# G# c, J# I; L+ D, e, e/ }: i/ |
--------------------------------------------------------------------------------5 i1 r& }# h6 ]+ u$ p
大学一年级
, E7 W1 f9 w# b% }* t2 N8 Eprogram Hello(input, output)2 R% c; T" E( ~& G: @) \
begin4 U8 x! M0 }# G: A! R) E
writeln('Hello World')6 m$ F9 m( W' E
end.
# o/ d2 _5 _0 \! b3 m( T--------------------------------------------------------------------------------' z# }7 }; Y8 b
大学高年级
- o6 p$ l! \& r* y" w(defun hello
! X& _% d+ g1 [+ [- E(print: q5 k8 x+ @& k0 M9 P
(cons 'Hello (list 'World))))
+ }0 `3 H( H2 n7 l% J--------------------------------------------------------------------------------3 O4 n' f/ f0 l: K$ V* G/ t
初级程序员
8 W* A5 N/ G( X$ d# F; Y#include
, t3 A4 m1 q% H% |+ lvoid main(void)3 J: ^- I/ Z( W) J( R- g4 R
{$ I0 r+ I6 i( K$ B4 Q' w
char *message[] = {"Hello ", "World"};
/ @- d- }" r+ o5 `& K0 Aint i;+ v% `0 Z. \8 f% o- F4 i" n
for(i = 0; i < 2; ++i)7 l1 q# w% c8 ^9 H* x
printf("%s", message);' y: t+ e: f: n5 a2 y+ u: V. R
printf("n");
# M; e3 o, v$ m3 z& Y% G# T/ W! E}
% R" ^7 I9 R# u3 q7 M4 v! ?7 f+ Y--------------------------------------------------------------------------------
$ a: O: j8 Z" D* T* k编程老鸟
G% j& ~0 l- `" t#include
! f+ F7 z( M% W#include
2 e& p& i! R7 ?) {8 K3 |class string
3 v0 |9 g$ T6 H{
, l/ c( M! D% @0 q- J$ j# Pprivate:
7 W" o2 C& N/ `int size;
" y8 m4 D( G4 H f; o$ P, Ochar *ptr;
8 S' z. [. p B3 j& gpublic:
: R N8 w+ J: ]9 L7 Rstring() : size(0), ptr(new char('{CONTENT}')) {}
. t( v4 b, `# Lstring(const string &s) : size(s.size). n: D @- Z- U! m
{; t! k4 ?; C9 Y; W$ V
ptr = new char[size + 1];: }% K" d, ~0 v6 ]
strcpy(ptr, s.ptr);! ~5 c, j4 |7 E X8 V( }
}
: w4 A1 H( Y% K( ^! I6 v1 \5 ^5 {~string()
8 \( M, u ]" _{
m- M7 }" C, A" N3 f. o- o- ^8 rdelete [] ptr;& b% _/ M, T( G) P1 X f
}1 T5 P3 _% F: d8 t- Q/ j5 Q
friend ostream &operator <<(ostream &, const string &);( M1 [" x% J6 U
string &operator=(const char *);; G% e+ p% N) l1 F( v: Z- N
};( \+ O6 c) [! A2 p' W
ostream &operator<<(ostream &stream, const string &s)0 @' t9 I$ b' t; {6 |
{: u. m7 @, Y8 @6 X0 |( h2 ~2 j
return(stream << s.ptr);4 F( G) k9 h' n* w
}
2 S0 U# v* c* G5 j" c6 [2 R- Pstring &string:perator=(const char *chrs)
+ d. n% i/ P! M+ k0 @. G{. u/ D4 K2 R& v1 Z
if (this != &chrs)9 C: [# E; x! F; H
{
0 V& `8 D1 }# k; hdelete [] ptr; s+ U5 u/ b% ]8 f5 E* a* }
size = strlen(chrs);8 ^9 ^3 \( E v5 V a& ?) }% T: O
ptr = new char[size + 1];- }0 c1 }1 A& r; R2 l
strcpy(ptr, chrs);
* r5 ^* o b, l, o/ c* P! ]}
9 L' M. j& b( O0 G' ereturn(*this);$ W3 e3 u5 X. ?& M! N
}
( Q5 N/ D: i9 a& R) v; Jint main(); O; u4 h- x/ [# T9 S, S6 ^/ h- K
{+ Q+ q+ K' ]9 d% e7 E+ M# M
string str;
; \5 m$ f+ u: l( z4 H; e& Pstr = "Hello World";( \- E/ A8 ^' C) A! E& b2 v
cout << str << end
; Z) U: E: n9 f/ c/ g; P {return(0);; @' N" j2 O+ @4 P! L. d8 F; H, t7 b
}& D [1 z6 ^: A
--------------------------------------------------------------------------------
3 R. ?' a, V M5 H5 D% ~- v编程高手
, x1 }& d7 f/ z2 o# F[
) |1 ^4 B. W: M5 m( W4 d+ q! vuuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)" W' {0 Q3 S2 x* l6 [
]
- k. E0 ^& `& ]3 ?% J) @' S" _library LHello& |" M L6 c/ G
{
3 a; b' w1 D; F$ J! Y3 P6 @2 r// bring in the master library
! o) E6 Y! e# L8 d- w7 k5 zimportlib("actimp.tlb");
$ G2 l1 w+ r4 |importlib("actexp.tlb");2 t+ `* S: @% Z0 u5 b3 l' I* [
// bring in my interfaces
- X( @6 s3 n3 h, L#include "pshlo.idl"4 a0 O2 M) g7 L
[
, B- U) ]8 Z+ Y8 P; I! ^uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
1 Y [! u- E3 s5 Z7 \]
E5 L! Z% j, v; Icotype THello
; B$ n, g7 j- N& Y9 _{0 \* N( p/ u( S, r, {5 K) O
interface IHello;
& k6 R3 l5 Q( G; J& J' z% T& t; [interface IPersistFile;5 ^8 F" V: e/ H- i5 o
};
+ ?9 j3 [% g4 q" w};" p% K5 f: Y' l
[
/ x9 D/ Z1 E3 @9 C7 _exe,- s K* H) E1 g
uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
7 X; _- l: p7 X+ Z0 []/ T# T( N3 ]; D+ k9 y i; d+ o, f' P
module CHelloLib
! o) R' S* c* ~. V{
( f3 W' \8 p* n) b// some code related header files1 O, L$ u# @4 m. g& C' D: b; h: U
importheader();3 P2 i) n4 _+ h5 f/ M; b6 q
importheader();
, O/ l2 `! D s$ Q' gimportheader();
& j' @: s! K+ ^, S8 w/ Wimportheader("pshlo.h");, o( U' ` K+ }# S" u9 X
importheader("shlo.hxx");
$ g& a/ u9 j) K" l ?/ zimportheader("mycls.hxx");! i! P8 B2 C- d+ i2 C
// needed typelibs
" W5 O3 M6 e5 N& x. u- V6 Oimportlib("actimp.tlb");
3 c0 l: ]# J; d% W7 Qimportlib("actexp.tlb");: d7 G% C, F' y6 E3 f
importlib("thlo.tlb");
F5 ~/ j0 x9 g& k[- V* w% @/ q+ |6 c& b
uuid(2573F891-CFEE-101A-9A9F-00AA00342820),. W9 _0 F& Y; `) O
aggregatable* R) b F% E* z6 ]2 f% N
]" F6 K+ R0 N* n8 E
coclass CHello
9 q7 [ Q9 e' s& r{/ \- d5 P8 K2 E5 x6 y
cotype THello;
7 y# G9 Z) `+ {6 }% P1 }% g; i& N}; A7 z5 L' U: ~, E3 O0 w
};
3 G! v% a3 E1 ?/ ^( T#include "ipfix.hxx"0 s# m- _7 z# Z% n6 `) {. d3 f5 R
extern HANDLE hEvent; C% q% F) u2 a' ]" u: F$ m7 @
class CHello : public CHelloBase8 D' [9 g9 q y9 B. K% l( a! p. ]* C
{0 Z, C3 R Q2 Y- o: c& o7 o
public:
. H( y9 Y5 e, i( b" ?6 `* AIPFIX(CLSID_CHello);' n3 F7 s+ f) C9 K' {* \" o3 p) ?
CHello(IUnknown *pUnk);( w% m4 t! r+ q4 A/ h* |- y2 |& ]$ O
~CHello();
6 s4 F: ^0 p& |3 T9 {/ aHRESULT __stdcall PrintSz(LPWSTR pwszString);; o2 a4 T3 l& V# }( u
private:! @* g' u& [* k- V
static int cObjRef;5 `: H; _( @! R8 n1 L
};" G- G2 {2 J+ l" p( a/ k3 g8 f
#include
6 f# A* g T# Q#include
3 E3 b1 r7 k; @! q# g- q#include ; }' q7 y9 R; D8 M. n( P
#include
1 N0 ^" C: z! }) m0 k/ ?1 Y6 K. `#include "thlo.h"
" ^' _9 W1 E* ~# x+ t#include "pshlo.h"
) ]. j' ?$ }' U/ a4 D. u#include "shlo.hxx"5 @- c. P1 F/ m6 E
#include "mycls.hxx"
4 a6 E; F+ J( B0 s1 I5 sint CHello::cObjRef = 0;
% O4 e8 v4 G' M4 nCHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)0 k ~. B: I$ x
{
' v- _' r1 |8 |+ {cObjRef++;, ^0 |3 x" i/ Q. K _" ^
return;8 u) n7 c% @, O( N/ v3 F
}
9 }0 R+ G5 I6 E. m! mHRESULT __stdcall CHello:rintSz(LPWSTR pwszString)
1 H9 K3 I6 R! U+ v ^) \{9 p G5 }# i h" n& t( g; _; G# @
printf("%wsn", pwszString);$ y& F% D& M. e9 ]
return(ResultFromScode(S_OK));( G8 y& K, q0 u5 e* h* C6 l
}
6 O- k% s, j+ ECHello::~CHello(void)
! \4 {& T$ r5 ^1 d5 ^; p{
& Q5 L+ [6 d) m$ Q- K& c// when the object count goes to zero, stop the server
1 |: ~' J) ?' G) W2 Z4 v# [: WcObjRef--;% i0 P9 z0 b1 N! V
if( cObjRef == 0 ), V7 R, K4 Y2 d, i
PulseEvent(hEvent);# v% k0 S# X3 Q! k
return;; ?3 K0 o/ u' s6 G0 z
}0 h1 v' l. R9 p# e3 c A/ b
#include
% B/ B" J, C9 q$ F6 u! m#include ; N- ^% {( K) w& D, W8 ]9 ]
#include "pshlo.h"
3 C9 x1 y# V8 T/ Y#include "shlo.hxx"
5 X9 A' B9 S7 n' I, n#include "mycls.hxx"! p0 {- d6 i0 ~ Z2 R
HANDLE hEvent;
' z- l5 F) q( `7 v' w6 Nint _cdecl main(# ~6 p. v: L, d
int argc,4 R+ J# r" E2 N
char * argv[]
% Y |1 P; z* ^, Y' {) {5 g4 I4 c! }# D2 p( T1 @, B, Q2 W
ULONG ulRef;# W. Q7 j3 R6 q, g) i# s
DWORD dwRegistration;
5 N" n6 |2 U' j) B, F3 J2 PCHelloCF *pCF = new CHelloCF();
0 A; \2 {: m' @2 R/ g' V; khEvent = CreateEvent(NULL, FALSE, FALSE, NULL);$ _3 U" Z1 L2 M# ^6 j
// Initialize the OLE libraries/ W# g3 W: r5 w2 }# e# T" x
CoInitializeEx(NULL, COINIT_MULTITHREADED);; E# a* g1 v" A( d6 |3 V+ h
CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
8 K& m+ p$ k# O' T! |, h, x8 MREGCLS_MULTIPLEUSE, &dwRegistration);
) C& a l( ?! P1 b// wait on an event to stop
8 i* v; _* w( l1 XWaitForSingleObject(hEvent, INFINITE);
: q6 c9 E! Z5 k, w4 D% H// revoke and release the class object5 p% }" }, n9 d$ @+ s* _3 w' @/ Q
CoRevokeClassObject(dwRegistration);
0 o9 L, g( T* ~" L5 L* ]ulRef = pCF->Release();
' a8 X4 m0 m P% D1 V// Tell OLE we are going away.
2 r- S4 U% V0 j: a. ZCoUninitialize();! s9 B5 J: t `" n; O2 X
return(0);; x2 g3 E$ a+ j( e: w$ ?5 _
}
- n2 M" j; @7 Z& z( Qextern CLSID CLSID_CHello;, s- \3 n; r0 u4 S. D- ^
extern UUID LIBID_CHelloLib;+ i, {8 [6 X0 g% J9 q4 A
CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */$ R. J! C3 S# Q6 M9 t; S) p
0x2573F891,# C V" I r" Q& J
0xCFEE,1 e# r4 [6 m7 O- ^( |
0x101A,& O0 q# z* R# l# T7 a6 ^
{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }! p' B; R1 G4 h1 F9 v' N. J
};/ |- u; o, p8 W8 w5 @* L
UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */
9 Z5 c; C4 k' w3 ~2 e0x2573F890,
% U7 J7 C9 `/ H; s0xCFEE, K [* r' ]- ~
0x101A,
' x+ ^5 E( Q! t2 M) k4 g o{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
5 }; C* J4 r( q0 c8 @6 x- ^0 D};$ Q: ]/ F- s4 F
#include 5 O6 v0 |* b2 p
#include / ^: G# r" K: e4 z
#include 0 ^3 o- {+ E3 u U
#include . E- W) v+ U* M( u2 Z: F7 I/ ?/ ]9 p
#include ' I1 X! A6 B8 s/ }5 l6 Q
#include "pshlo.h"
* x" R, l# P5 ]9 H- i( i#include "shlo.hxx"7 X1 r$ ~% Y) Z/ j2 N
#include "clsid.h"
; Z* |5 G" c6 W) }8 b o/ Zint _cdecl main(" H8 D+ L' Z) o6 w
int argc,
9 C# \$ L6 P3 n: f! Mchar * argv[]2 [4 f7 u& N1 H# o6 B
) {
8 O Q' s& y7 O- t4 q# gHRESULT hRslt;
0 u: A" O0 y! Y% Z* {1 Z6 HIHello *pHello;
0 `# ?$ n* G# Q8 \/ TULONG ulCnt;5 \/ y" [, i8 j" q3 b+ x: Z
IMoniker * pmk;; e0 |6 a% d! M H- i" N, z
WCHAR wcsT[_MAX_PATH];
1 o; Y7 j! s6 E- ?( K* I: AWCHAR wcsPath[2 * _MAX_PATH];
% q* d+ h2 z* t g// get object path( }) I/ A/ o3 E' l& J J; W; Q' t
wcsPath[0] = '{CONTENT}';. J {/ D7 j# B3 f! L
wcsT[0] = '{CONTENT}';9 a$ y7 J% C! a' ]- k1 n( }
if( argc > 1) {
; u2 t+ z0 l: x) ?" o: u' H! p9 {mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);4 `% z! _# l4 A0 Z( l" @
wcsupr(wcsPath);
" T1 m5 [8 B* E3 a- T: G}7 o% q, @! ?6 [
else {
: m: y0 a r( Z) T; G/ L7 Sfprintf(stderr, "Object path must be specifiedn");) ?, Z* v: c( q1 X
return(1);
3 S2 O& S0 j$ a5 B$ F8 `}
, e; [7 Q# U- w2 \: u# M// get print string
" C. | Z; {( [; O7 q: Bif(argc > 2)
0 y- g+ r0 [4 s* y8 e5 fmbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);* X; y6 A2 E* g1 Q" e. o
else. c6 P! Q8 ?: h) m" m7 g+ {( p+ D
wcscpy(wcsT, L"Hello World");1 ` A. N+ X% g: V" Y2 X' X5 m" l
printf("Linking to object %wsn", wcsPath);
& L% z: f; o" z. _( f; D& Qprintf("Text String %wsn", wcsT);' O- c' `) [* N* q) k( \* @8 F
// Initialize the OLE libraries' x! i6 Q" @4 u- \; m
hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);& e! P2 D: _6 k4 ?2 x- e
if(SUCCEEDED(hRslt)) {
7 U- ~0 R6 V% V B; b1 G2 ZhRslt = CreateFileMoniker(wcsPath, &pmk);
9 ^6 ] O. \( M& K* i: N: pif(SUCCEEDED(hRslt))
/ _& H2 d8 T" A b3 _4 Q5 chRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);
' F/ B4 S" c9 ~. K" E' W' Oif(SUCCEEDED(hRslt)) {5 g( I ~0 V# \# s4 { J
// print a string out
9 o! x- n. [+ q( a5 j+ qpHello->rintSz(wcsT);6 ]2 _! K$ Z& g+ d
Sleep(2000);4 w! U" Y* t1 d" @- a* u5 s2 W$ c
ulCnt = pHello->Release();
4 h4 i% R: B" F) h# Y1 W}
( ]. e4 j- U, p# i1 selse: j7 p- ~- Z/ B
printf("Failure to connect, status: %lx", hRslt);* `2 l- l6 w* b* _" G) A
// Tell OLE we are going away.# Z8 ?6 R3 b* @' c4 m: a- p( o% K
CoUninitialize();7 l& a: i4 ^1 V0 x+ ~1 g8 @
}6 U, w2 N$ r; V
return(0);
. r; Y; u/ o+ d. e}
3 V8 S2 y( X! g) S( t--------------------------------------------------------------------------------3 ]8 G6 f/ A. D( F: e
黑客初阶
9 ~1 A% z8 o& V7 a+ G: r M }3 \#!/usr/local/bin/perl
, C2 m9 s- i1 Y. u9 R" n$msg="Hello, world.n";6 k) a- P# Q& l; h" V/ h. E
if ($#ARGV >= 0) {
2 ?7 s& v6 J4 i8 h; b5 I- Y7 v6 _while(defined($arg=shift(@ARGV))) {
0 r+ o" m$ v4 e5 D6 L$outfilename = $arg;
- |& ~6 d1 ?$ m' u9 _open(FILE, ">" . $outfilename) || die "Can't write $arg: $!n";
! n& K3 M5 P& V6 t: ~1 z) eprint (FILE $msg);, G* `( c' I" M* a" w
close(FILE) || die "Can't close $arg: $!n";+ y' ^ e" w8 S5 f/ f P2 R
}2 r- H! c" h( b2 G; P
} else {
* Q) \- O8 Y- bprint ($msg);
* @( p4 c( w4 \' C, N}" M* ?5 o/ K: K
1;! O0 `+ j5 h( x# B7 S2 h4 @
--------------------------------------------------------------------------------: _# M0 p E9 h6 m9 x
黑客有成5 e! t5 G+ Z7 M" w) P6 l
#include
' \+ F, v8 ], ], i" R& v8 b#define S "Hello, Worldn"0 l+ V3 Z' [; C! l5 Z
main(){exit(printf(S) == strlen(S) ? 0 : 1);}
/ f0 \3 [6 D2 C3 H |3 U; c* H--------------------------------------------------------------------------------
. P+ Z ?0 P) J5 M黑客高手. k; q1 D& c9 M" A9 |2 A5 C& _5 K) A
% cc -o a.out ~/src/misc/hw/hw.c% Q: O5 v* U) T2 x
% a.out; f" k* J/ N) l9 y" k6 ~ E/ Y9 J
--------------------------------------------------------------------------------
# m0 U0 F5 B- w9 J黑客大虾( X; t2 i6 }' \3 L2 v; w$ v; E
% cat# |0 o j% E/ a2 {3 B7 P# ]/ Y
Hello, world.2 d4 z5 [$ p' j1 H. c
^D" _" e0 u4 J! E* I7 U4 f
--------------------------------------------------------------------------------% I9 D& E, o/ `/ ]# h+ H$ B% B
初级经理6 K6 c- t5 O- c2 @: R
10 PRINT "HELLO WORLD"/ |( b' L* Y, `
20 END: O: Y8 N( M" x8 W
--------------------------------------------------------------------------------# Y9 M# W/ h2 }0 u! C- p
中级经理
* x. R, L( f: y5 N7 b5 tmail -s "Hello, world." bob@b12
7 z. @5 x& d0 E% [Bob, could you please write me a program that prints "Hello, world."?6 [( p6 l/ @( Z1 _
I need it by tomorrow.
. m% P ]( j% b7 B^D% ]2 {4 F$ Y& ^+ H
--------------------------------------------------------------------------------" C3 `6 u, C# x i
高级经理
, {2 L) E, G( |: I3 N% zmail jim
3 W8 B% O9 P$ T, W$ pI need a "Hello, world." program by this afternoon.
3 k; z, S0 I( X9 s8 h--------------------------------------------------------------------------------
6 Y2 ^8 R9 u" Y- }+ Z, ~& x首席执行官
7 n3 P$ E/ r& t" N- K$ L: W# ]% letter8 ^+ G- A4 A9 B
letter: Command not found.
, s! n5 m4 L% e. m" v" v% mail
# ^1 x4 q) J* H3 `3 {' WTo: ^X ^F ^C
! P l7 b# b' I" m V- w& }% help mail2 r" V; C$ _' Y8 \- g
help: Command not found.
: Q% }5 Y8 ~$ @" ]* L- G4 z, G; _8 f% damn!* _. k' Z. [) j5 q" x# r- [) ]# ]
!: Event unrecognized
0 H' Y" T; i) ^3 V. B/ ~% logout, a; ~, }: W4 _3 ~, [. n" j. k. K
-------------------------------------------------------------------------------- |
|