|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
/*-------------------------------------------! N' p# f4 c1 w3 D: O
程序员的进化--从学生到首席执行官
, e/ J% c3 N/ R# S$ h. r* n, x8 X4 y翻译 2002 王咏刚 http://www.contextfree.net/
/ g8 c' H$ {) j8 z( @# c转译自 Omri's Computer Humor Page
& W" V1 l# B1 r: ] ohttp://www.cs.bgu.ac.il/~omri/Humor// {# Q2 E2 n4 R
-------------------------------------------*/
o" `' ?, O8 ]) ^* I3 p! {; ] m# K: b" |2 `2 Q% g
--------------------------------------------------------------------------------& ^5 b7 \# _/ p* `( d9 W" e
中学阶段* P# V! p- y6 X M! T
10 PRINT "HELLO WORLD") w- M# M5 Y& B/ }
20 END
. O' @' L0 G) k' `# C--------------------------------------------------------------------------------( Z" X' }' f8 X: v9 P
大学一年级
5 a0 b: @& r$ u {; Dprogram Hello(input, output)1 Y, ?3 @8 |0 D3 y8 w! f' V
begin5 j: R& g# ]. H* O8 z& t# R
writeln('Hello World')
$ p6 L5 Z5 l0 J: ?& T% Gend.
: s( ~. S+ k9 }2 u: T# E; E--------------------------------------------------------------------------------
' V# y3 p- ]* V% f+ J; x大学高年级# F! y% n- C+ y0 ]
(defun hello3 \7 U; D# [$ v3 D
(print
. a% q6 {2 k+ {' e(cons 'Hello (list 'World))))1 m$ G/ }5 I& e. g# o3 }
--------------------------------------------------------------------------------
4 M$ D9 I5 C/ S0 w' r4 D- k初级程序员
2 C6 ]5 n) I1 ~' q% S#include
) v( e0 y! O0 z$ v0 x evoid main(void)" I2 l7 g( z: T$ G; u% x8 f
{
1 {; b) z& q# t; ?% l6 ^9 tchar *message[] = {"Hello ", "World"};
( R2 F4 f3 }. ?/ H6 ~% K9 Eint i;
& t4 r) g/ ]3 x/ Yfor(i = 0; i < 2; ++i)# v4 Q$ N2 x/ n: E! m/ Y' s: \
printf("%s", message);; W3 a- Z. L* b1 e- r
printf("n");: }6 K0 i, ^' C: A/ c
}
# f1 k4 {) X% V, p; U' |. j) n+ ~--------------------------------------------------------------------------------3 ?% D8 ]- a' N" l( m5 b
编程老鸟
! a) Z8 c- I9 D' b/ |4 [, m4 ?#include + c! C: n0 f7 \4 ~, K$ A+ z
#include * E% P6 A3 O: [
class string+ d& h9 T" B3 X! `" m9 `
{
8 q& B8 C2 P( B# ~private:
* ]) G2 A# p1 ^- t) |: Z% `( Bint size;
. j% F) g& @6 O4 qchar *ptr;2 ?, g, j, b' X( [5 d
public:
9 j# u6 D* O ~string() : size(0), ptr(new char('{CONTENT}')) {}
! D1 A2 x4 G, |" X$ Cstring(const string &s) : size(s.size)0 C* V# s7 C% f6 r& ]
{
' }" {: Y& U7 J9 cptr = new char[size + 1];
5 v6 f9 N" O5 q5 j0 _8 Z2 P5 \% Bstrcpy(ptr, s.ptr);# R; X& b6 G F: X* `) t1 \" d6 O
}$ z# Y' W* {4 P* E* ?
~string()
- `( p1 Q% w( ]& |7 b* R# c1 m$ d{
5 n H1 O; ?5 [1 ^6 a% ^8 k! jdelete [] ptr;5 B* h- b$ b, R) W
}
0 Y/ R; T1 V. x1 vfriend ostream &operator <<(ostream &, const string &);0 u2 |8 B$ I' K7 ^7 L) X4 ]
string &operator=(const char *);5 C$ e; e2 D4 n
};
& B! \4 B( W( Q$ {ostream &operator<<(ostream &stream, const string &s)
8 {- a! T4 n( J! J2 }! x{
, r5 A& u4 d2 U yreturn(stream << s.ptr);
2 V4 M8 P3 C! `" P+ q. w# s" D; c}/ L' {- m6 v- q* H# N; o* T
string &string:perator=(const char *chrs)& m; P) l, O. f
{( u! \7 l4 C: r, |# Q5 T, ~7 `$ ^ y
if (this != &chrs)
* i- |8 v0 R0 J4 z{7 Z% d" F" k1 E6 I' `" V, C
delete [] ptr;
) h5 j; G- \- K- h9 zsize = strlen(chrs);
, t" Q" Q/ V# c# z' m* T0 rptr = new char[size + 1];! n8 A1 [* F+ z+ U% c9 l6 u1 B' c8 ~" {
strcpy(ptr, chrs);: m8 a# V* z1 f, ]& h% ?
}
8 e1 ]* m( H- _return(*this);% X; p% L& ~, y' |( Z
}8 [2 i6 [- z/ @% L6 y9 ?. Q
int main()
7 q6 [8 Q3 x& N# |; F# k: M9 R{5 B' l+ U9 A# D: x: {: w
string str;: F% l" y2 Z, W% E. o% Q
str = "Hello World";
8 W8 g: O6 f+ [cout << str << end, h- u" m V1 `, h/ A# C
return(0);
0 O* R7 g# n6 l8 X}
; a% H- L: [' l-------------------------------------------------------------------------------- l$ s) x3 z1 `! c5 S
编程高手
" E9 z+ P3 [0 m; Q% S[0 g4 r- N6 m7 J" t/ n P& s% e8 d" ~
uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)7 X0 y! L+ S7 x, [4 Q
]
' c& {+ S- R |& t3 F4 G4 blibrary LHello% c& y. e# \6 \1 [, b- j
{
9 X7 X( B& i; x5 Z4 L }3 q, w// bring in the master library2 u6 ^1 _+ l1 Z% N) S
importlib("actimp.tlb");
& k/ V( Q0 T0 [1 {# U* limportlib("actexp.tlb");0 J4 J0 D. R& }6 q8 P
// bring in my interfaces
7 g) a3 O6 v2 u' L7 W& ^0 M, N#include "pshlo.idl"
6 c# ]2 z2 U% F0 z \: s[
$ M/ w( e4 o# D/ Y6 D3 E8 Nuuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)" g5 p" u) T; _4 Z
]
2 v: i) L3 x+ f' V/ [& xcotype THello
. @5 a- o& O) z, |4 b1 O7 d{% I7 d# I9 L0 C2 N
interface IHello;9 v+ t4 |0 m" }3 F; `0 [
interface IPersistFile;+ f Z7 H3 z" F \5 Y7 j- ^( F
};2 c2 Y* o; g* y5 \) ^* v
};
~2 f* Z* M2 Z! c- C4 q! l% m[ S1 D4 g# n2 [ ?* x5 h6 s
exe,
$ V# Q, Z: Y4 L, juuid(2573F890-CFEE-101A-9A9F-00AA00342820)
1 s. }( S4 c& X! b]
( m% S4 v, d, Mmodule CHelloLib
, h( p+ r: ]0 J{
! E* \5 w# O. K1 X J2 Y" \6 I% W// some code related header files4 ]0 t: u$ L( A
importheader();' T( l. M' p' f( k: ]- X' X
importheader();
# J0 o9 P+ ^6 J- t9 e# dimportheader();$ j( J Z" e8 V# J1 J/ I
importheader("pshlo.h");) w6 R3 P3 a# I0 C7 o9 w- q" R
importheader("shlo.hxx");; _& k7 o. }" {: [' l
importheader("mycls.hxx");
9 g, _. A: z) ~" p+ \% ~// needed typelibs
T6 E3 H. `8 _ s. ~importlib("actimp.tlb");
) \ ~# y+ w u. B ]- j; G+ uimportlib("actexp.tlb");
# D6 P4 Y- }2 H Z6 {! |( Eimportlib("thlo.tlb");0 v. i' E7 q. g# t4 l
[
5 f; C8 V2 h1 b9 C2 x6 P, K0 R# A/ ruuid(2573F891-CFEE-101A-9A9F-00AA00342820),; b5 ~9 N" y' I. F2 h
aggregatable
6 E8 H+ K# ?# L1 u% k; `) [$ s x]
I2 y- S6 y) r- p' pcoclass CHello; n' I" |$ {" t8 h/ q2 \
{
# G- M, _$ _3 t# ?$ ncotype THello;
- Z/ }1 t* }9 o& u};
* p z& M! {. o- r" s6 E6 |};6 S( a3 W( j& m. n2 y
#include "ipfix.hxx". m7 Y, _$ f. M1 V+ e8 E+ N/ g
extern HANDLE hEvent;8 ^0 G2 A' ^& ~8 _$ e5 x9 Z
class CHello : public CHelloBase8 V! G% c+ L/ ?
{! L# m( h5 I0 E; v8 B l
public:9 n' B$ J0 N7 ]5 \( R
IPFIX(CLSID_CHello);
& d' r# ]' U7 L4 y0 X: u8 hCHello(IUnknown *pUnk);6 F9 ?- Z5 h$ U& m
~CHello();) L, s. P5 V* c, e6 x e9 i B0 O+ ~5 n* x
HRESULT __stdcall PrintSz(LPWSTR pwszString);
1 D5 D7 T! s7 g* G+ h" D; fprivate:
/ H0 t8 z; Z$ ^6 ^& ]+ j3 S! ^( Q+ nstatic int cObjRef;
* f v8 F7 d; R+ Z5 E8 B6 v};
- R' N5 [ `8 {/ s4 d#include 5 C; Y* q# U/ t M! ~, ^4 I2 `0 s
#include * G5 F2 i) _+ W# {6 g
#include
5 z$ B4 n3 l7 A/ T#include l& c8 l8 u8 v4 A& f
#include "thlo.h"
2 O7 y! q, x( l#include "pshlo.h"5 G6 f3 j& h: E( o
#include "shlo.hxx"
3 y' J6 e' N! Q! M1 T- i- x4 W#include "mycls.hxx"
0 |# I$ [6 s+ _! m- ?! bint CHello::cObjRef = 0;0 G( G3 R/ [) F2 Q+ D
CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
, P0 Z% V7 n5 F{, ^; ]+ p1 K+ m. S- Z) N
cObjRef++;
7 |& a1 i, h' b! l3 s8 I ureturn;
, O9 G+ t1 h# `: I/ ~/ N}& r0 v3 o4 p. ~% H6 `
HRESULT __stdcall CHello:rintSz(LPWSTR pwszString)
8 F; u7 m/ M3 l% N$ u3 ~# l{5 t( z6 L; s# I* Q" a) S
printf("%wsn", pwszString);
' ?- J3 \) T$ J* J0 {return(ResultFromScode(S_OK));
# F, {4 ` D7 v}! g5 N5 a# h' X4 n( r& t
CHello::~CHello(void)
6 ]/ ~% [1 c+ a7 D1 r$ C9 c1 ^( e{
) Z3 I, ?& c. J: Q& I/ ]0 R// when the object count goes to zero, stop the server) I; l+ J% i& `+ e9 L
cObjRef--;) b3 h- ?, N, a4 w( ]
if( cObjRef == 0 )0 C% j- U( r- l! z
PulseEvent(hEvent);
5 v2 k" X" ^2 C) H0 Hreturn;
2 k, Q& K% x3 c}. X1 t$ z1 \3 G+ L1 ^
#include / P- r D4 ^6 \& ^7 T" S# _
#include
$ l. A ^( T0 V7 m% B#include "pshlo.h"! `; C* c% q4 p' i
#include "shlo.hxx"" L0 `1 F9 w. @/ C+ @
#include "mycls.hxx"
3 B6 H5 T8 |7 @9 n b) Z) CHANDLE hEvent;% n: n0 m$ d" v" f( G
int _cdecl main(, n) b) {9 Q+ D1 X Q
int argc,$ X, m: c. `5 T" t" W' _6 E9 Z
char * argv[]
/ p% ^) \9 _) {# d$ ^) {
* ~- n, {8 |! I6 C+ S; O* {ULONG ulRef;
i; [0 w4 h; B: D9 i6 w6 b% ^DWORD dwRegistration;
7 G5 M' E. @3 ~" x+ A9 O! gCHelloCF *pCF = new CHelloCF();
0 s8 }2 X- E/ r: _hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);2 l* Z& S5 P9 g6 i
// Initialize the OLE libraries
& a1 D. c' q' Q8 t, v( qCoInitializeEx(NULL, COINIT_MULTITHREADED);$ v! }' @ g4 E. }
CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
! n5 G. f( W* AREGCLS_MULTIPLEUSE, &dwRegistration);
" P% o( c$ u0 }% e* a// wait on an event to stop
8 j" J* j# s- J, w# U; e0 O' b8 B; FWaitForSingleObject(hEvent, INFINITE);
& D$ U* }6 L( p& _. _- v$ w// revoke and release the class object
* J! V; m% A" A+ s/ Y3 a! DCoRevokeClassObject(dwRegistration);
9 O2 v$ e3 C7 H4 ^) O& c4 BulRef = pCF->Release();. j+ [; Q8 _* l. j* R
// Tell OLE we are going away.- O) q: G$ I0 P# g7 R+ a
CoUninitialize();4 d+ ~3 d2 I- u/ o( u+ ?
return(0);: ]- ?0 D6 g: N, K
}( p) x* R7 u; T+ ?1 }7 s# `
extern CLSID CLSID_CHello;4 [2 c4 {3 V. `9 r5 k3 Z3 L- Z
extern UUID LIBID_CHelloLib;- E% A% @, {5 k
CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */3 c* }2 _4 b8 J: @4 H" o1 I
0x2573F891," R0 v/ H3 M: e3 Y' Q
0xCFEE,
7 e5 h2 s3 Z/ n* ~( @1 H7 R# O0x101A,
9 u6 O2 B! m, U- w{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }/ ?1 W+ F0 k9 Y i( l
};3 c: g b+ p `7 g$ x/ u0 X
UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */# g+ V& P# a4 `& Y) F( a
0x2573F890,# k4 _# H( e) l$ g( K" Z
0xCFEE,
( H( M$ ~% E( T) x8 @! ], j0x101A,
* Q5 a: h( ?1 j' |8 V/ b5 J{ 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }. e. s* P+ ^6 p8 Z* X* L4 T
};
7 n4 T; y ?# |% Y; X5 z- b1 ]#include 4 F& G: u4 Z; T3 n X0 ^5 e
#include
) s1 D0 v3 ]& T/ R8 h#include
. i( |: m$ [" ^+ ?6 f' C#include 5 M8 \" P$ f9 D- w; a4 T
#include 6 _4 c: H% K1 ~& S9 Z0 e) O0 c
#include "pshlo.h"
7 m7 ~; u! p( W; x0 g {( g! z#include "shlo.hxx"
9 Y1 A& _4 X. X2 b( G9 v- B#include "clsid.h") r5 n1 Y% E; ]( q: @! x
int _cdecl main(
, K9 J3 p5 Y2 E8 V! p9 `5 Sint argc,& f3 g! k, C/ c* ?/ j2 T1 i
char * argv[]
K4 l$ c0 Z8 G" N' O) {
$ u$ l$ ^ h' f+ FHRESULT hRslt;% C6 s" I* t/ {0 M5 `4 S/ M* l" {
IHello *pHello;
: a$ O6 u1 l; L9 ~8 ]/ SULONG ulCnt;; f, b7 z8 E8 M9 R! q/ p
IMoniker * pmk;
9 U& ?5 {+ s/ \1 E$ B. r7 ], r8 y7 TWCHAR wcsT[_MAX_PATH];5 Z0 u3 j/ E* f1 i6 |
WCHAR wcsPath[2 * _MAX_PATH];! R p) ^. p5 T! M3 ?& l
// get object path
5 D" a! W7 d6 C& E+ H% p- T1 j* rwcsPath[0] = '{CONTENT}';
5 N. [2 j. \" \2 IwcsT[0] = '{CONTENT}';
4 L$ j3 p, b9 g- K- @$ d$ g0 ]if( argc > 1) {
7 F- a4 ~0 g- W( r$ gmbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);) t4 r. a [8 M% Y9 x
wcsupr(wcsPath);
( W O3 y6 [% z7 h) O. x- c1 }}
q& u' r9 A) @2 _2 Belse {3 n2 Z9 C4 k! K
fprintf(stderr, "Object path must be specifiedn");
7 a) U- {+ a' ]' o; u$ ?1 A9 Creturn(1);0 L" I1 Y k/ ]
}
4 T$ N# Q! L+ Q1 U// get print string7 O6 m& F- L* N. Q# u( m0 d
if(argc > 2)$ o, \- ^2 l9 w5 s( | W
mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
$ ~, s/ C- G0 S0 r$ g$ [: Gelse [/ U) l; ~: @4 D
wcscpy(wcsT, L"Hello World");0 k; g" Y5 E. w' M: t
printf("Linking to object %wsn", wcsPath);
0 T. a8 W5 z* g' V6 Q1 Fprintf("Text String %wsn", wcsT);3 T' K) D8 ^+ ^/ Q4 `3 }3 h; H
// Initialize the OLE libraries: K4 h9 k: O9 E/ o1 a
hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);
$ d4 m" Y% U8 \3 eif(SUCCEEDED(hRslt)) {5 K( c! J$ j7 P5 _6 @2 i/ o
hRslt = CreateFileMoniker(wcsPath, &pmk);
3 j0 R4 e+ S, r8 A" oif(SUCCEEDED(hRslt))5 G5 x$ u) J. C/ X6 h/ j
hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);
# \/ ^6 [( q ]- {9 A* f$ i% Q. Eif(SUCCEEDED(hRslt)) {
- N, {( V ^# {8 J: @/ `* u0 i7 G& }// print a string out, |( ~% S, I% U+ ~" f ]; a
pHello->rintSz(wcsT);! o! X6 C; O% n5 [0 G
Sleep(2000);
/ A0 X6 G! s0 a2 @2 \ulCnt = pHello->Release();0 }5 z* d1 L) e/ T1 S
}
, P) B& G. B: M, v& W- Xelse* Q" Z$ h7 N5 d" t; F* R
printf("Failure to connect, status: %lx", hRslt);; O* R f) k8 z/ y# V& h- w
// Tell OLE we are going away.# W$ w' ~* r1 e/ ^ o8 @
CoUninitialize();# K# y, X0 W i- K, O
}
+ m# p- c: j8 C+ U1 w, N1 s4 V/ treturn(0);
' d& r/ q3 ?, ~% A3 i) J/ F2 O}
9 s: h5 `% p9 G6 x9 l--------------------------------------------------------------------------------
6 `% c4 e/ E4 |黑客初阶
8 R4 o- i4 O0 Q#!/usr/local/bin/perl
% U/ z$ n% x4 E' k7 y/ Z$msg="Hello, world.n";8 Z7 y: w1 I% }: ^3 j- B8 G
if ($#ARGV >= 0) {9 @# R& L. x# _$ B+ K: ^9 A) j8 y
while(defined($arg=shift(@ARGV))) {
+ D/ i) G3 U/ f$outfilename = $arg; P- x; E4 ^, }
open(FILE, ">" . $outfilename) || die "Can't write $arg: $!n";
. I( s1 o& r7 C% iprint (FILE $msg);
# j/ e8 @7 f) l# R6 ~3 `close(FILE) || die "Can't close $arg: $!n";
{: u% [$ I3 A$ ~, J* z}
2 W- x+ z! }0 n# S3 k5 h- R! W' i4 y} else {
# }! N4 |, f U) h1 {$ J- i9 Yprint ($msg);8 n p5 |" o. V. w
}
( i% ]- e. l- h6 a% r6 L2 ^1;4 G, d2 |% |) T( p; E
--------------------------------------------------------------------------------
/ C; C) D$ Y6 W: R2 @黑客有成9 \- l" ?1 Y' d( I/ z
#include + J: K0 F* @' _
#define S "Hello, Worldn"
" L3 @" X% j) P8 V" }main(){exit(printf(S) == strlen(S) ? 0 : 1);}
7 d% ?7 e- Y: M! v5 V5 D--------------------------------------------------------------------------------
2 e3 a; R O1 q/ ^) z- Q- v黑客高手# t8 D( X g4 x7 X
% cc -o a.out ~/src/misc/hw/hw.c! R+ f* P. |: H2 E- R0 i3 K
% a.out
) s' q- {$ A' N+ a--------------------------------------------------------------------------------
# D w/ R3 D- }7 W+ e黑客大虾2 r) f! Z- M, \* ~
% cat
- o/ f7 p: v6 c3 d' G0 v& [Hello, world.$ m' i+ o8 b0 y# ^
^D
- `3 h7 o) K& j5 u, E--------------------------------------------------------------------------------, ? `; s6 W' W% ~
初级经理0 S3 e5 J! o1 A; g- _- X1 h
10 PRINT "HELLO WORLD", r9 Y: d4 n; k6 n- l; @
20 END
9 K$ j" G7 w, C4 L& A1 C2 Y1 t--------------------------------------------------------------------------------
+ k( c; r: d2 H: T6 m2 M6 p中级经理
0 @5 ^) R; D" V9 @2 Smail -s "Hello, world." bob@b12" `( g% f/ z) W/ ~
Bob, could you please write me a program that prints "Hello, world."?
) r) n3 Q% B6 {; Q" D6 WI need it by tomorrow.! c1 x( _2 {0 v$ P: i" {
^D
5 g- S( F _" W7 `3 p, e* b( P--------------------------------------------------------------------------------. ~; L2 l4 ~% L8 Q6 j' [* _
高级经理
) b, s& _% w. Z$ ~. Q% zmail jim: P- C, Y+ p# |1 o' {% B3 W
I need a "Hello, world." program by this afternoon.$ J# Y/ }0 X# {% \0 g3 X2 d+ t
--------------------------------------------------------------------------------7 O, _+ d3 F4 I. i
首席执行官2 r: [9 _5 a" {1 c8 t) m# [
% letter
- d6 ~- S+ o% E0 h) n% O* Oletter: Command not found.
& [7 z' D3 Z" @% n% mail
$ u, ~) ]8 |1 c K# \4 Z( ^) }To: ^X ^F ^C
9 y, O z9 a' h% help mail, H" A. J! ]0 _6 v. L. t) t
help: Command not found., k! E- a: N1 {7 q
% damn!
' H. V' \' h; e3 O% x9 v5 e!: Event unrecognized
& ]. |; j- w: Q8 c) T$ r% logout1 O" g- W$ ?1 g0 }& p7 b
-------------------------------------------------------------------------------- |
|