• cornishon@lemmygrad.ml
    link
    fedilink
    arrow-up
    6
    ·
    edit-2
    2 months ago

    I think the simplest benevolent example of this is what I call “the newline virus”.

    Basically, in most programming languages you represent the newline character inside strings with the escape sequence '\n' (or equivalent), so naively you would expect to see a statement translating '\n' into its ASCII code 10 somewhere in the source code of the compiler, like this:

    case "\n":
        emit(10);
    

    but most likely, it will just say something like instead:

    case "\n":
        emit('\n');
    

    That is, the fact that '\n' == 10 is nowhere to be seen!

    You only need the initial version of the compiler to state it explicitly, all future versions can rely on the previous compiler doing the right thing.