Ievads
Šis ir viens no varenākajiem hakeru eposiem. Dažos spilgtos
tēlos tas izskaidro vairāk par hakeru ētiku un psiholoģiju, nekā kaudze
pētījumu sējumu, kas salikti kopā.
Tiem, kas prot angļu valodu, vēlams lasīt oriģinālu, pārējiem esmu izveidojis tulkojumu. (Zemāk)
Ja
jūs vēlaties saprast, kas ir īsts hakeris, nevis uzkampt
žurnālistu nožēlojamos centienus nomelnot šo gaišo tēlu, lasiet, šis ir
jums.
The Story of Mel, a Real Programmer
This was posted to Usenet by its author, Ed Nather (utastro!nather), on
May 21, 1983.
A recent article devoted to the macho side of programming
made the bald and unvarnished statement:
Real Programmers write in FORTRAN.
Maybe they do now,
in this decadent era of
Lite beer, hand calculators, and "user-friendly" software
but back in the Good Old Days,
when the term "software" sounded funny
and Real Computers were made out of drums and vacuum tubes,
Real Programmers wrote in machine code.
Not FORTRAN. Not RATFOR. Not, even, assembly language.
Machine Code.
Raw, unadorned, inscrutable hexadecimal numbers.
Directly.
Lest a whole new generation of programmers
grow up in ignorance of this glorious past,
I feel duty-bound to describe,
as best I can through the generation gap,
how a Real Programmer wrote code.
I'll call him Mel,
because that was his name.
I first met Mel when I went to work for Royal McBee Computer Corp.,
a now-defunct subsidiary of the typewriter company.
The firm manufactured the LGP-30,
a small, cheap (by the standards of the day)
drum-memory computer,
and had just started to manufacture
the RPC-4000, a much-improved,
bigger, better, faster -- drum-memory computer.
Cores cost too much,
and weren't here to stay, anyway.
(That's why you haven't heard of the company,
or the computer.)
I had been hired to write a FORTRAN compiler
for this new marvel and Mel was my guide to its wonders.
Mel didn't approve of compilers.
"If a program can't rewrite its own code",
he asked, "what good is it?"
Mel had written,
in hexadecimal,
the most popular computer program the company owned.
It ran on the LGP-30
and played blackjack with potential customers
at computer shows.
Its effect was always dramatic.
The LGP-30 booth was packed at every show,
and the IBM salesmen stood around
talking to each other.
Whether or not this actually sold computers
was a question we never discussed.
Mel's job was to re-write
the blackjack program for the RPC-4000.
(Port? What does that mean?)
The new computer had a one-plus-one
addressing scheme,
in which each machine instruction,
in addition to the operation code
and the address of the needed operand,
had a second address that indicated where, on the revolving drum,
the next instruction was located.
In modern parlance,
every single instruction was followed by a GO TO!
Put that in Pascal's pipe and smoke it.
Mel loved the RPC-4000
because he could optimize his code:
that is, locate instructions on the drum
so that just as one finished its job,
the next would be just arriving at the "read head"
and available for immediate execution.
There was a program to do that job,
an "optimizing assembler",
but Mel refused to use it.
"You never know where it's going to put things",
he explained, "so you'd have to use separate constants".
It was a long time before I understood that remark.
Since Mel knew the numerical value
of every operation code,
and assigned his own drum addresses,
every instruction he wrote could also be considered
a numerical constant.
He could pick up an earlier "add" instruction, say,
and multiply by it,
if it had the right numeric value.
His code was not easy for someone else to modify.
I compared Mel's hand-optimized programs
with the same code massaged by the optimizing assembler program,
and Mel's always ran faster.
That was because the "top-down" method of program design
hadn't been invented yet,
and Mel wouldn't have used it anyway.
He wrote the innermost parts of his program loops first,
so they would get first choice
of the optimum address locations on the drum.
The optimizing assembler wasn't smart enough to do it that way.
Mel never wrote time-delay loops, either,
even when the balky Flexowriter
required a delay between output characters to work right.
He just located instructions on the drum
so each successive one was just past the read head
when it was needed;
the drum had to execute another complete revolution
to find the next instruction.
He coined an unforgettable term for this procedure.
Although "optimum" is an absolute term,
like "unique", it became common verbal practice
to make it relative:
"not quite optimum" or "less optimum"
or "not very optimum".
Mel called the maximum time-delay locations
the "most pessimum".
After he finished the blackjack program
and got it to run
("Even the initializer is optimized",
he said proudly),
he got a Change Request from the sales department.
The program used an elegant (optimized)
random number generator
to shuffle the "cards" and deal from the "deck",
and some of the salesmen felt it was too fair,
since sometimes the customers lost.
They wanted Mel to modify the program
so, at the setting of a sense switch on the console,
they could change the odds and let the customer win.
Mel balked.
He felt this was patently dishonest,
which it was,
and that it impinged on his personal integrity as a programmer,
which it did,
so he refused to do it.
The Head Salesman talked to Mel,
as did the Big Boss and, at the boss's urging,
a few Fellow Programmers.
Mel finally gave in and wrote the code,
but he got the test backwards,
and, when the sense switch was turned on,
the program would cheat, winning every time.
Mel was delighted with this,
claiming his subconscious was uncontrollably ethical,
and adamantly refused to fix it.
After Mel had left the company for greener pa$ture$,
the Big Boss asked me to look at the code
and see if I could find the test and reverse it.
Somewhat reluctantly, I agreed to look.
Tracking Mel's code was a real adventure.
I have often felt that programming is an art form,
whose real value can only be appreciated
by another versed in the same arcane art;
there are lovely gems and brilliant coups
hidden from human view and admiration, sometimes forever,
by the very nature of the process.
You can learn a lot about an individual
just by reading through his code,
even in hexadecimal.
Mel was, I think, an unsung genius.
Perhaps my greatest shock came
when I found an innocent loop that had no test in it.
No test. None.
Common sense said it had to be a closed loop,
where the program would circle, forever, endlessly.
Program control passed right through it, however,
and safely out the other side.
It took me two weeks to figure it out.
The RPC-4000 computer had a really modern facility
called an index register.
It allowed the programmer to write a program loop
that used an indexed instruction inside;
each time through,
the number in the index register
was added to the address of that instruction,
so it would refer
to the next datum in a series.
He had only to increment the index register
each time through.
Mel never used it.
Instead, he would pull the instruction into a machine register,
add one to its address,
and store it back.
He would then execute the modified instruction
right from the register.
The loop was written so this additional execution time
was taken into account -
just as this instruction finished,
the next one was right under the drum's read head,
ready to go.
But the loop had no test in it.
The vital clue came when I noticed
the index register bit,
the bit that lay between the address
and the operation code in the instruction word,
was turned on -
yet Mel never used the index register,
leaving it zero all the time.
When the light went on it nearly blinded me.
He had located the data he was working on
near the top of memory -
the largest locations the instructions could address -
so, after the last datum was handled,
incrementing the instruction address
would make it overflow.
The carry would add one to the
operation code, changing it to the next one in the instruction set:
a jump instruction.
Sure enough, the next program instruction was
in address location zero,
and the program went happily on its way.
I haven't kept in touch with Mel,
so I don't know if he ever gave in to the flood of
change that has washed over programming techniques
since those long-gone days.
I like to think he didn't.
In any event,
I was impressed enough that I quit looking for the
offending test,
telling the Big Boss I couldn't find it.
He didn't seem surprised.
When I left the company,
the blackjack program would still cheat
if you turned on the right sense switch,
and I think that's how it should be.
I didn't feel comfortable
hacking up the code of a Real Programmer.
This is one of hackerdom's great heroic epics, free verse or no. In a few spare images it captures more about the esthetics and psychology of hacking than all the scholarly volumes on the subject put together.
[1992 postscript -- the author writes: "The original submission to the net was not in free verse, nor any approximation to it -- it was straight prose style, in non-justified paragraphs. In bouncing around the net it apparently got modified into the `free verse' form now popular. In other words, it got hacked on the net. That seems appropriate, somehow." The author adds that he likes the `free-verse' version better...]
Mela, Īstā Programmētāja, stāsts
To Tīklā 1983. gada 21. maijā nosūtīja autors, cilvēks vārdā Ed Nather. Tulkojums, 2002 (c) Vladislav Kugelevich
Nesenā rakstā par programmēšanas "krutajām" pusēm tika izteikta taisna kā baļķis, pilnīgi neslēpta tēze:
Īsti Programmētāji raksta Fortrānā.
Varbūt tagad tas tā ir,
Šajā pagrimuma ērā,
Starp bezalkoholisko alu,
Kabatas kalkulatoriem
Un draudzīgiem interfeisiem.
Bet vecajos labajos laikos,
Kad pats vārds "programma" izklausījās smieklīgi,
Un Īstie Datori bija būvēti uz trumuļiem un vakuuma lampām,
Īsti programmētāji rakstīja mašīnkodā.
Ne Paskālā. Ne Fortrānā. Un pat ne Asemblerā.
Mašīnkodā.
Jēli, neizpušķoti, nesaprotami sešpadsmitnieku skaitļi.
Pa tiešo.
Un lai jaunā programmētāju paaudze
Neuzaugtu neziņā par šo lielo pagātni,
Es izjūtu vajadzību aprakstīt,
Cik vien labi spēju
Caur paaudžu aizu,
Kā Īsts Programmētājs rakstīja kodu.
Es viņu saukšu par Melu,
Jo tāds bija viņa vārds.
Pirmo reizi es viņu satiku,
Kad atnācu strādāt uz Royal McBee Computer Corp.,
Mūsdienās mirušu meitasuzņēmumu
Kompānijai, kas ražoja rakstāmmašīnas.
Firma ražoja LGP-30,
Nelielu, lētu (tiem laikiem)
Datoru ar trumuļa atmiņu,
Un nupat bija sākusi ražot
RPC-4000, ievērojami uzlabotu,
Lielāku, labāku un ātrāku - datoru ar trumuļa atmiņu.
Ferīta gredzeni maksāja pārāk dārgi,
Un, jebkurā gadījumā, to laiks bija pagājis.
(Lūk, kāpēc jūs nekad neesat dzirdējuši
Ne par šo kompāniju, ne par tās lolojumu)
Mani nolīga, lai izveidotu Fortrāna kompilatoru
Šai apbrīnojamajai ierīcei,
Un Mels bija mans pavadonis tās noslēpumos.
Mels neatbalstīja kompilatorus.
"Ja programma nevar pārrakstīt pati savu kodu",
viņš mēdza teikt, - "Kāds no tās labums?"
Mels bija uzrakstījis,
Sešpadsmitnieku sistēmā,
Vispopulārāko programmu no tām,
Kas piederēja kompānijai.
Tā darbojās uz LGP-30
Un spēlēja Blekdžeku ar potenciālajiem pircējiem
Datoru izstādēs.
Efekts bija satriecošs.
LGP-30 vienmēr bija aizņemts visās izstādēs,
Un IBM pārdevēji stāvēja apkārt,
Sarunājoties viens ar otru.
Vai tas tiešām palīdzēja pārdot datorus -
Jautājums, ko mēs nekad neapspriedām.
Mela darbs bija pārrakstīt
Blekdžeku priekš RPC-4000
(Portēšana? Kas tas tāds?)
Jaunajam datoram bija adresācijas shēma viens-plus-viens,
Kurā katra mašīninstrukcija
Papildus operācijas kodam
Un darba operanda adresei
Saturēja otro adresi, kas norādīja, kur uz rotējošā trumuļa
Atrodas nākamā instrukcija.
Runājot mūsdienu valodā,
Katru atsevišķu instrukciju
Pavadīja pārejas komanda.
Izbaudiet to, strukturālie programmētāji!
Mels mīlēja RPC-4000
Jo viņš varēja optimizēt savu kodu:
Proti, tā izvietot instrukcijas uz trumuļa,
Lai tiklīdz viena pabeigtu darbu,
Nākamā atrastos tieši zem "lasošās galviņas"
Un būtu pieejama nekavējošai izpildei.
Bija programma šī darba veikšanai,
"Optimizējošais asemblers",
Bet Mels atteicās to izmantot.
"Nekad nevar zināt, kur tas izdomās novietot komandu",
Viņš paskaidroja, "un tev nākas izmantot atsevišķas konstantes".
Pagāja ilgs laiks, pirms es sapratu šo piezīmi.
Tā kā Mels zināja katras operācijas
Koda skaitlisko vērtību,
Un pats piešķīra savas adreses uz trumuļa,
Katra viņa rakstītā instrukcija,
varēja tik uzskatīta arī par
Skaitlisku konstanti.
Teiksim, viņš varēja paņemt instrukciju "ADD"
Un reizināt ar to.
Ja tai bija vajadzīgā skaitliskā vērtība.
Citiem nebija viegli mainīt viņa kodu.
Es salīdzināju Mela manuāli optimizētās programmas,
Ar to kodu, ko veidoja optimizējošais asemblers,
Un Mela programmas vienmēr strādāja ātrāk.
Tas bija tāpēc, ka "no-augšas-uz-leju" programmēšanas metode vēl nebija izgudrota,
Un Mels vienalga to nebūtu izmantojis.
Viņš vispirms rakstīja savu programmu iekšējās daļas,
Lai tām būtu pirmā izvēle
Uz optimālajām izvietojuma adresēm uz trumuļa.
Optimizējošais asemblers nebija pietiekami labs, lai darītu tā.
Mels arī nekad nerakstīja aiztures ciklus,
Pat tad, kad stūrgalvīgais "Flexowriter"
Pieprasīja aizturi starp izvadāmajiem simboliem
Viņš vienkārši tā izvietoja instrukcijas uz trumuļa,
Lai nākamā jau būtu garām lasošajai galviņai,
Kad tā bija nepieciešama;
Un trumulim nācās veikt pilnu apgriezienu,
Lai atrastu nākamo instrukciju.
Viņš radīja neaizmirstamu terminu šai procedūrai.
Lai gan "optimāls" ir absolūts jēdziens,
Tāpat kā "unikāls",
Sarunvalodā bija kļuvis par normu
Padarīt to par relatīvu:
"nepietiekami optimāls" vai "mazāk optimāls",
vai "ne pārāk optimāls".
Mels izvietojumus ar maksimālo aizturi sauca par
"Vispesimālākajiem".
Pēc tam, kad viņš pabeidza rakstīt Blekdžeku
Un piedabūja to strādāt,
("Pat inicializators ir optimizēts",
lepni teica Mels),
Viņš saņēma Lūgumu Pēc Izmaiņām no pārdošanas nodaļas.
Programma izmantoja elegantu (optimizētu)
Gadījuma skaitļu ģeneratoru,
Lai jauktu "kārtis" un dalītu no "kavas",
Un daži Pārdevēji juta, ka tas ir pārāk godīgi,
Jo reizēm pircēji zaudēja.
Viņi gribēja, lai Mels izlabo programmu tā,
Lai ar sensora slēdzi uz konsoles
Viņi varētu mainīt izredzes un ļaut pircējam uzvarēt.
Mels ietiepās.
Viņš juta, ka tas ir acīmredzami negodīgi.
Un tā tas arī bija.
Un ka tas aizskar viņa kā programmētāja godaprātu
Un tā tas arī bija.
Tāpēc viņš atteicās to darīt.
Galvenais Pārdevējs parunāja ar Melu
Tāpat izdarīja arī Lielais Boss un, pēc bosa spiediena,
Vēl daži kolēģi programmētāji.
Mels galu galā padevās un uzrakstīja kodu,
Bet sanāca viss otrādi,
Un, kad sensora slēdzis bija ieslēgts,
Programma šmaucās, visu laiku uzvarot.
Mels bija sajūsmā par to,
Paziņojot, ka viņa zemapziņa ir nekontrolējami ētiska,
Un nelokāmi atteicās to labot.
Pēc tam, kad Mels pameta kompāniju zaļāku ganību meklējumos,
Lielais Boss palūdza mani uzmest aci kodam
Un paskatīties, vai nevaru atrast pārbaudi un izlabot to.
Tā nedaudz negribīgi, es piekritu paskatīties.
Sekot Mela kodam bija īsts piedzīvojums.
Es bieži esmu jutis, ka programmēšana ir mākslas forma,
Kuras patieso vērtību spēj izprast
Tikai cits, kas iesvētīts šajā pašā slepenajā mākslā;
Tur ir burvīgi dārgakmeņi un veiksmīgi gājieni,
Kas paslēpti no cilvēku acīm un apbrīnas, reizēm uz visiem laikiem,
Paša procesa dabas dēļ.
Var daudz ko uzzināt par cilvēku,
Vienkārši lasot viņa kodu,
Pat sešpadsmitnieku sistēmā.
Mels bija, kā es uzskatu, neapdziedāts ģēnijs.
Iespējams, vislielāko šoku es piedzīvoju,
Kad atradu nevainīgu ciklu bez nosacījuma.
Bez jebkāda nosacījuma. Bez.
Pirmā doma bija, ka tam jābūt slēgtam ciklam,
Kurā programma ieciklētos uz visiem laikiem, bez gala.
Taču programma gāja tam cauri,
Un veiksmīgi iznāca ārā otrā pusē.
Man vajadzēja divas nedēļas, lai to atkostu.
Dators RPC-4000 bija aprīkots ar ļoti modernu iekārtu,
Ko sauca par "Indeksu reģistru".
Tas ļāva programmētājam uzrakstīt ciklu,
Kurš izmantoja indeksētu instrukciju;
Katrā gājienā,
Skaitlis indeksu reģistrā
Tika pieskaitīts šīs instrukcijas adresei,
Tā, ka tā norādīja
Uz nākamo virknes elementu.
Vajadzēja tikai palielināt
Indeksu reģistru
Katrā gājienā.
Mels to neizmantoja.
Tā vietā
Viņš iedzina instrukciju mašīnas reģistrā,
Pieskaitīja vieninieku tās adresei
Un saglabāja to atpakaļ.
Tad viņš izpildīja modificēto instrukciju
Tieši no reģistra.
Cikls bija uzrakstīts
Ņemot vērā šo lieko laiku -
Tiklīdz viena instrukcija beidzās,
Nākamā bija tieši zem lasošās galviņas,
Gatava palaidei.
Bet ciklam nebija nosacījuma.
Izšķirošais pavediens bija, kad es pamanīju,
Ka indeksu reģistra bits,
Bits, kas atrodas starp adresi
Un operācijas kodu
Instrukcijas vārdā,
Bija iestatīts -
Neskatoties uz to,
Ka Mels nekad neizmantoja indeksu reģistru,
Vienmēr atstājot to vienādu ar nulli.
Kad mani apgaismoja, es gandrīz apžilbu.
Viņš izvietoja datus,
Ar kuriem viņš strādāja,
Netālu no atmiņas beigām -
Pašās pēdējās šūnās, kuras varēja adresēt instrukcijas -
Un, pēc pēdējā elementa apstrādes,
Instrukcijas adreses palielināšana
Noveda pie tās pārpildīšanās.
Pārnesums pieskaitīja vieninieku operācijas kodam,
Pārvēršot instrukciju par nākamo instrukciju kopā:
Pārejas instrukciju.
Protams, nākamā instrukcija atradās adresē nulle,
Un programma laimīgi gāja tālāk savu ceļu.
Es neuzturēju sakarus ar Melu
Un nezinu, vai viņš padevās tai pārmaiņu jūrai,
Kas mainīja programmēšanas tehniku
Kopš tām sen aizgājušajām dienām.
Gribas domāt, ka nē.
Jebkurā gadījumā
Es biju pietiekami pārsteigts,
Lai pārstātu meklēt
Nokaitinošo pārbaudi,
Pasakot Lielajam Bosam,
Ka nevaru to atrast.
Viņš nebija pārsteigts.
Kad es pametu kompāniju,
Blekdžeka spēle
Vēl aizvien šmaucās,
Ja jūs pieskārāties pareizajam slēdzim.
Es domāju, ka tā tam arī ir jābūt.
Es nejutos omulīgi,
Labojot Īsta Programmētāja kodu.
Šis ir viens no varenākajiem
hakeru eposiem, vienalga, kādā formā tas būtu, brīvā panta vai kādā citā. Dažos
spilgtos tēlos tas izskaidro vairāk par hakeru ētiku un psiholoģiju,
nekā kaudze pētījumu sējumu, kas salikti kopā.
[1992. gada piezīme -- autors raksta "Oriģināls
nebija sarakstīts brīvā panta formā un pat ne tuvu tam --
tā bija parasta proza, ar neizlīdzinātām rindkopām. Klejojot pa tīklu,
tā pārvērtās par "brīvo pantu", kas mūsdienās ir tik populārs. Citiem vārdiem sakot,
to "uzlauza" tīklā. Tā vai citādi, tas šķiet iederīgi."
Autors piebilst, ka šāda forma viņam pašam patīk labāk.]
Tulkojums, (c) 2003, Vladislavs Kugelevičs.
Skatīt arī:
- Izglītojošs ieraksts Vikipēdijā (angļu val.)