83

I feel like whenever I see the ampersand on this website, it’s followed with “amp;”. I’ve noticed it other places on the internet also. Why does this happen? Is it some programming thing?

Just for a test: &

you are viewing a single comment's thread
view the rest of the comments
[-] JakenVeina@lemm.ee 9 points 1 year ago* (last edited 1 year ago)

Let's see of I can give a trimmed-down explanation of what "character escapement" is, because others have covered that & in web-land is an escapement character.

The simplest type of escapement is probably quotes.

var myString = "This is a string";

This little line of pseudo-code is roughly what you would write (depending on language) to make a program write the text This is a string into some location in memory, that is, a sequence of numbers that are the standard numbers for representing those letters.

Here, the double-quote character is serving a special purpose, to designate that the characters within the set of quotes represent not instructions for things that the program should do, but instead just bits of data that the program should load.

Now consider: what if the character data that you want to load into memory has an actual double-quote character within it? How does the compiler (the program that turns your code into its own program) know the difference between a double-quote character that's supposed to serve the special purpose, and a double-quote character that's just supposed to be a piece of data like the other characters? The answer is escapement.

var myString = "This is a \"string\"";

Here, the backslash character serves its own special purpose of escaping other characters. When the compiler is reading this code, it knows that whatever character follows the backslash is supposed to be interpreted specially: in this case, the double-quote should not be interpreted as the end of the string, as usual, but as just a character to be put within the string. The backslash doesn't end up in memory with the other characters, but it tells the compiler how to interpret things.

In web-land, ampersand is an escape character. If you want to embed plain text to be displayed on the screen, within HTML, you need to "escape" special characters that have a non-text purpose normally, in order to get those characters to display as text. Ampersand is the escape character in HTML, and by extension, it also has its OWN escape sequence, which is &.

The reason you see & in places across Lemmy is likely just due to a bug of some kind. Somewhere between when the user is entering this text, and when it later gets displayed, there's code that's adding escapement to the text an extra time than is necessary.

this post was submitted on 12 Aug 2023
83 points (97.7% liked)

Explain Like I'm Five

14224 readers
1 users here now

Simplifying Complexity, One Answer at a Time!

Rules

  1. Be respectful and inclusive.
  2. No harassment, hate speech, or trolling.
  3. Engage in constructive discussions.
  4. Share relevant content.
  5. Follow guidelines and moderators' instructions.
  6. Use appropriate language and tone.
  7. Report violations.
  8. Foster a continuous learning environment.

founded 1 year ago
MODERATORS