‹ BackHN Continuity

Thread

Ten lines of code that changed my world

148 points · 46 comments · dimonomid

  1. tptacek · · focus · HN ↗
    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 annoying line.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.