‹ BackHN Continuity

Thread

Ten lines of code that changed my world

146 points · 46 comments · dimonomid

Loading the complete thread in the background. This saved snapshot is available now. Refresh

  1. probably_wrong · · focus · HN ↗
    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.

    1. thenthenthen · · focus · HN ↗
      You have this one right?

      (){ :|:& };:

      1. mattrighetti · · focus · HN ↗
        Don’t forget the function name at the very beginning!

        :(){ :|:& };:

    2. apsurd · · focus · HN ↗
      mine would be something like

          p { color: red; }
      
      as a teenager my mind was blown as I reloaded the page and there it was; text now in red. I did that!
  2. irregularbowels · · focus · HN ↗

    [dead]

  3. dahart · · focus · HN ↗
    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!

    1. dgacmu · · focus · HN ↗
      Most definitely the juvenile phrases.

      I think my second BASIC program was the "guess a number" one -- that seemed really popular in intro basic programming things in the 80s also since it showed keyboard input and conditionals and was, uh, fun-adjacent.

    2. mcherm · · focus · HN ↗
      The reason that "Hello, World" is a C thing is that C is the source of the tradition around that phrase. In Kernighan and Richie's "The C Programming Language" printing "Hello, World" is the very first exercise.
      1. gabrielsroka · · focus · HN ↗
        It&#x27;s actually a B thing <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27048024">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=27048024
        1. bojan · · focus · HN ↗
          Interestingly enough, in the linked text, B is referred as a &quot;language&quot;, follow by &quot;the generated code is quite good&quot;, presumably referring to the resulting Assembly code.
        2. NetMageSCW · · focus · HN ↗
          I disagree as that doesn’t introduce using the B environment with a Hello, world program which is the whole point. After K&amp;R it was the canonical first program.
          1. guelo · · focus · HN ↗
            Pulling my copy of K&amp;R from the shelf, it introduces the hello world program with

              The first program to write is the same for all languages:
                Print the words   
                hello, world
            
            Suggesting that this was already an established tradition when the book was written in 1978
    3. andsoitis · · focus · HN ↗
      Concur. Us hackers who got started with BASIC had a more fun and creative ethos.
    4. codazoda · · focus · HN ↗
      I have been building BASIC32, a ROM BASIC like the ones I grew up with.

      The first one runs on an ESP32 that I plan to use as a watch. The software works, I just need to finish the 3D printed case.

      The second runs on an RP2350 connected to my living room TV via an HDMI cord.

      I have some much appreciation for these old machines I grew up with.

          BASIC32
          
          Ready.
    5. yencabulator · · focus · HN ↗
      [delayed]
    6. chihuahua · · focus · HN ↗
      I started with

        10 FOR I = 1 TO 10
        20 PRINT I, SQRT(I)
        30 NEXT I
      
      and struggled to type this without errors into computers in department stores. I must have read this code somewhere and needed to see it working for myself.
      1. dotancohen · · focus · HN ↗
        I remember discovering ? as a shortcut for PRINT on the C64. That was when software development as a profession really started looking like a good choice to young me.
    7. whartung · · focus · HN ↗
      In high school, my friend and I were demonstrating to Fred the magic powers of our IMSAI 8080 with ye olde:

        10 PRINT &quot;FRED IS A GEEK&quot;
        20 GOTO 10
      
      To wit my friend and I would giggle and taunt.

      Undaunted, Fred took a look around, found the power button, and turned the machine off. Yes, that power button next to the &quot;DO NOT TURN OFF&quot; sign.

      As the monitor and LEDs faded to black, the giggling stopped and my friend and I stood aghast at Fred&#x27;s treachery.

      Fred left, and we were tasked with restarting the machine, getting to the monitor, keying in the hex code of the cassette loader, and reloading BASIC from cassette.

      Got it to work on our second try!

    8. tc43 · · focus · HN ↗
      I was too young to understand why, but learning on the Commodore 64 my &quot;Hello world&quot; was always &quot;Frodo lives&quot;.
    9. animal531 · · focus · HN ↗
      On my Spectrum I came up with: 10 GOTO 20 20 GOTO 10

      It would start the Spectrum&#x27;s &quot;loading screen&quot; border which would then scroll infinitely.

      At some point I also opened it up to see what it looked like on the inside, but I managed to damage the keyboard in the process. Thereafter whenever I wanted to play a game (via joystick) I would have to use a piece of wire to manually select the rows&#x2F;columns of the matching keys to enter the load command.

  4. analog8374 · · focus · HN ↗
    My first shipped code was an art thing. C64 Basic. Poke random characters to random locations on the screen. Random colors, screen and border too. On infinite goto loop. Radio Shack (IIRC) in the local mall used it on all their C64s.
  5. throw34889 · · focus · HN ↗
    For debugging CSS, I prefer something along the lines of:

        * {
          outline: 1px solid hotpink !important;
          outline-offset: -1px !important;
        }
    
    As in most cases the above snippet doesn&#x27;t reflow content.

    Exercise to the reader is to turn the above into a javascript bookmarklet toggle, and to add support for shading margins and padding.

    1. chias · · focus · HN ↗
      if you&#x27;re using firefox, you can generally juts ctrl-click on the page. It&#x27;ll draw outlines around every child element without reflowing.
  6. andsoitis · · focus · HN ↗
    Here are 4 lines that capture something profound about Lisp: code can manufacture code that manufactures code:

    ———————

    (defmacro twice (form)

      `(progn ,form ,form))
    
    (twice (print &quot;Reality&quot;))

    ———————

    twice doesn’t execute its argument twice. It rewrites the program itself before execution into:

    (progn (print &quot;Reality&quot;) (print &quot;Reality&quot;))

  7. 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-&gt;kargc, argv, environ));
    
    from FreeBSD crt0; kind of a big moment for me to realize there was more C code underneath main().

    Then:

        statements: &#x2F;*E*&#x2F; | 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&#x27;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 &quot;double the size of the hash table when it fills up&quot;, that&#x27;d deserve a slot here.

    Then, of course (we get to cheat because assembly):

        jmp .call
        .pop: pop esi
        ...
        .call: call .pop
    
    The &quot;delta offset&quot; 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-&gt;left); visit(n); walk(n-&gt;right); }
    
    I should figure out a way to fit a write-select(2) into a line because that&#x27;s another &quot;oh shit&quot; moment for me.

    Similarly: when Vern Paxson explained to me that he&#x27;d implemented TCP reassembly by simply opening up a file and using &quot;seek&quot; to place incoming segments in the right position. I could probably golf that down to a line! But it would be an annoying line.

  8. ulfbert_inc · · focus · HN ↗
    Such a lovely article. Thanks for sharing.
  9. layer8 · · focus · HN ↗
    &gt; This tiny batch script allowed for a poor man’s touch on Windows, which I used extensively from Windows NT to Windows 7. I typed touch filename.txt in the Total Commander mini-shell to quickly generate new, empty files.

    This is funny, because I associate touch more with updating the timestamp of an existing file, and that script would miserably (and destructively) be failing at that.

    1. xp84 · · focus · HN ↗
      yeah i get the utility for the &#x27;making new file&#x27; use case, but aliasing this as touch if you&#x27;re used to touch for both uses scares me!
  10. beanaroo · · focus · HN ↗
    Another fun one for a bit of shenanigans:

      #define true ((rand()&amp;15)!=15)
    1. yencabulator · · focus · HN ↗
      [delayed]
    2. drfloyd51 · · focus · HN ↗
      Cute.

      Back in the day, I looked down my nose at other young fledgling developers that would #define true 1. I knew only clarity and woe lived down that road.

          if(5-2 == true) ;
      
      As verbose as it was stupid.

      I felt superior because I knew that #define false 0 was the only Boolean keyword hack that would work.

          if (5-2 != false) ;
      
      Still verbose, and stupid, but at least it was correct.

      These days… I don’t feel as confident about anything as I did about those #defines.

  11. yboris · · focus · HN ↗
    Loved the The speed-up loop section. Smart move!
    1. 0x000xca0xfe · · focus · HN ↗
      My first thought was: And this is how the author discovered optimizing compilers...
  12. chris_engel · · focus · HN ↗
    The CSS debugger should have been:

    outline: hotpink 1px solid;

    not border! It destroys the layout. I mean, come on :)

    1. yencabulator · · focus · HN ↗
      [delayed]
      1. yencabulator · · focus · HN ↗
        [delayed]
      2. chris_engel · · focus · HN ↗
        Uhm, sorry but this is nonsense. Outline exists since CSS2 in 1998 and I was using it since the early 2000s with great success so this is a rather old trick.

        Maybe you reconsider who&#x27;s the youngling...

  13. readthenotes1 · · focus · HN ↗
    Mine was

    someObject.changeToClassOf(SomrOtherClass);

    (or something like that--i&#x27;m was long ago).

    In Smalltalk, changing an object&#x27;s class preserves instance variable (attribute) values when possible, silently dropping if not, and gives it an SomeOtherClass&#x27;s inheritance (and method dictionaries as a result).

    It forced me to realize that an instance of a class wasn&#x27;t permanently coupled to be an instance of the class that instantiated it or even its current class

  14. awwaiid · · focus · HN ↗
    Sorry this is ten SNIPPETS or BLOCKS of code. I&#x27;m counting more than 10 lines here.

    ... er, but also cool and inspirational :)

  15. metanonsense · · focus · HN ↗
    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
    1. perilunar · · focus · HN ↗
      I did something similar. I remember initially doing y as a function of x, before &#x27;discovering&#x27; parametric functions.
  16. oliyoung · · focus · HN ↗
    &gt; And always hotpink.

    nah, `rebeccapurple` <a href="https:&#x2F;&#x2F;meyerweb.com&#x2F;eric&#x2F;thoughts&#x2F;2014&#x2F;06&#x2F;19&#x2F;rebeccapurple&#x2F;" rel="nofollow">https:&#x2F;&#x2F;meyerweb.com&#x2F;eric&#x2F;thoughts&#x2F;2014&#x2F;06&#x2F;19&#x2F;rebeccapurple&#x2F;

  17. nickthegreek · · focus · HN ↗
    logo writer is what got me hooked. seeing that turtle move from text input really got my attention as a child
  18. ghoul2 · · focus · HN ↗
    it was just

      10 PRINT &quot;my first name&quot;
    
    on my zx spectrum, as a 6 year old. did me in. not even a loop. Just seeing that on our color TV (also new at the time, in my country).
  19. bigbezet · · focus · HN ↗
    The CSS debugger &quot;trick&quot; is really bad advice. CSS borders affect the layout and can break things. Use an outline instead.
  20. bhavaniravi · · focus · HN ↗
    This is modern day touching grass in the era of AI coding
  21. drpython · · focus · HN ↗
    Nice article.

    Brought back a lot of memories.

    In the early 2000s, when video games weren&#x27;t protected against DLL injection hacks, I spent a lot of time writing DLL injectors for fun and learning.

    The line I used in every experiment was:

    `jmp $` (or `EB FE` in machine code)

    It was the shortest infinite loop in x86 assembly, equivalent to `while 1: ;`

    I would create a minimal DLL with this assembly code, inject it into games like Battlefield 1942, and observe it in OllyDbg. The injected DLL would then start on a new thread and access all the game data in memory.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.