Ten Lines of Code That Changed My World
A personal collection of ten code snippets that left a mark, from a BASIC infinite loop to self-modifying 6502 assembly and a CSS poem. Each line carries a story: cheating at games with POKE, a Windows touch hack, and a username scanner from the early '90s. The author reflects on the joy, humor, and lessons these fragments brought.
Machine language is as close to the metal as it gets. No warnings, no logs, no guardrails. It even allows you to modify itself, by overwriting the actual bytes of the code while it runs.
- dahart
The BASIC print+goto loop might have been my first ever program too (in the 80s) but one thing for sure for me: it was definitely not “Hello, World”. I and others filled the screen with any number of silly things, random words, jokes and juvenile phrases, whatever, but for some reason, “Hello, World!” was a C thing, and I remember seeing it for the first time in a C class in high school, and then much more often in college.
I have memories of ‘poke’ as well. On the Atari 800 you could poke memory to change the keystroke repeat rate and delay before repeat started, so obviously we would turn down the delay to zero and turn up the repeat to max (it was maybe 60 characters per second), so anyone trying to type couldn’t hit the keys quickly enough to avoid repeating. You’d have to power-cycle the machine to fix it, so it was hilarious to 11 year old me.
Similar to his description of ‘poke’, but different mechanism - using debug.com on an IBM PC jr to edit the Ultimate III save files, and give myself maximum money and lives.
Good times!
- andsoitis
Here are 3 lines that capture something profound about Lisp: code can manufacture code that manufactures code:
———————
(defmacro twice (form)
`(progn ,form ,form))
(twice (print "Reality"))
———————
twice doesn’t execute its argument twice. It rewrites the program itself before execution into:
(progn
(print "Reality")
(print "Reality"))
- probably_wrong
I have been collecting small code snippets that would make for good tattoos and I have to say, some of these ones would probably make a good addition to the collection.
I'm partially more in favor of "red" instead of "hotpink" for CSS, but that's just me.
- tptacek
Hmm. What a great question.
while(1) { fork(); }
Must have meant something to me, because it was in my Usenet sig. And then:
exit(main(kfp->kargc, argv, environ));
from FreeBSD crt0; kind of a big moment for me to realize there was more C code underneath main().
Then:
statements: /*E*/ | statement statements
The moment Yacc clicked for me; that line was profound but a more accurate depiction of the moment was realizing that all you were doing with the parser generator was building a tree, and that's what the side effects of each production were for: returning and plugging in tree nodes.
If there was a single line I could come up with for "double the size of the hash table when it fills up", that'd deserve a slot here.
Then, of course (we get to cheat because assembly):
jmp .call
.pop: pop esi
...
.call: call .pop
The "delta offset" trick, which I believe came from x86 virus culture but was universal in 90s overflow exploits as a way to get position-independent references to strings and other memory things.
For sure:
void walk(node *n) { if(!n) return; walk(n->left); visit(n); walk(n->right); }
I should figure out a way to fit a write-select(2) into a line because that's another "oh shit" moment for me.
Similarly: when Vern Paxson explained to me that he'd implemented TCP reassembly by simply opening up a file and using "seek" to place incoming segments in the right position. I could probably golf that down to a line! But it would be an an […]
- metanonsense
Always ran this to impress my friends
10 for i = 0 to 359
20 plot 100+100*cos(i), 100+100*sin(i)
30 next i