• 1 Post
  • 4 Comments
Joined 1 year ago
cake
Cake day: June 25th, 2023

help-circle
  • __LINE__ returns the line of code its on, and % 10 means “remainder 10.” Examples:

    1 % 10 == 1
    ...
    8 % 10 == 8
    9 % 10 == 9
    10 % 10 == 0 <-- loops back to 0
    11 % 10 == 1
    12 % 10 == 2
    ...
    19 % 10 == 9
    20 % 10 == 0
    21 % 10 == 1
    

    In code, 0 means false and 1 (and 2, 3, 4, …) means true.

    So, if on line 10, you say:

    int dont_delete_database = true;
    

    then it will expand to:

    int dont_delete_database = ( 10 % 10 );
    // 10 % 10 == 0 which means false
    // database dies...
    

    if you add a line before it, so that the code moves to line 11, then suddenly it works:

    // THIS COMMENT PREVENTS DATABASE FROM DYING
    int dont_delete_database = ( 11 % 10 );
    // 11 % 10 == 1, which means true
    



  • There’s not enough symbols on my keyboard, so let’s invent a code so we can write other symbols

    1. lets say & means start of code
    2. and say ; means end of code
    3. Between the start and end is the code

    Now let’s make some real symbols

    • ¢ can be &cent;
    • © can be &copy;
    • ÷ can be &divide;

    I want to tell other people how to use our new code, but if I tell them to “just write &divide;” it’ll turn my message into “just write ÷” !! So how can we fix this?

    What if we make & its own code?

    • &amp; —> &
    • &amp;divide; —> &divide; ???

    Yes! That’ll work :)

    This is how &amp; came to be, and it’s specifically used in HTML as a way to write those symbols above (and escape other a few other symbols for similar reasons we did with &amp;)

    As for why & shows up as &amp;, there are 2 main places I can see this happening:

    1. The editor you use to write it automatically converts an & —> &amp;. But the user typed in &amp; (making it &amp;amp;). I think this is most likely. I’m guessing the title of posts automatically do the conversion, but the post body and comments do not because it uses a raw markdown editor
    2. In some contexts the & specifically doesn’t get converted? like how you can write `&amp;` to get &amp; as opposed to seeing