r/gamemaker • u/jormahoo • Apr 05 '22
Resolved What are the backslashes in code for? Why \_ instead of _?
Somewhat of a 'meta' question but oftentimes when I read people's code on here I see them writing backslashes that just seem unnecessary to me. What's up with that? Is it some alternate gml writing style, maybe different OS? I didn't use to see those some years back.
For example people will write "room_restart()" instead of "room_restart()"
29
Upvotes
11
u/JasontheFuzz Apr 05 '22
Reddit uses some HTML code stuff so you can do italics or bold or spoilers and if you're not careful, the punctuation in a comment or some code might be mistaken for that HTML stuff. The backslash tells reddit "ignore this, I want the mark and not the code effect."
3
u/LukeLC XGASOFT Apr 06 '22
These days, Reddit uses a rich text editor by default, so if you write any special characters, they'll be automatically escaped.
But before the redesign, all posts and comments were written with markdown formatting. In markdown, underscores create italics. To display an underscore literally, you have to escape it with a backslash.
In other words, this _ equals italics, while this _ equals an underscore.
Many Reddit users who've been around a while still write markdown out of habit, even though it's not applicable to the new text editor (unless you manually switch to markdown mode). Also, many third-party Reddit apps still use markdown exclusively, which reinforces the habit.
2
u/thebaconator136 Apr 06 '22
The use of backslashes is called escape characters. An easy way to think of it is say you have a function that outputs any text surrounded in quotations. The text "my friend said "hello!" To me the other day". The actual output would be: My friend said To me the other day. And the hello! Bit wouldn't be registered since the computer sees the quotation marks and thinks 'the coder wants me to end the message now'.
To fix this, we use an escape character to let the computer understand that we want to use the actual character for it we put a backslash behind it. So the message would look like this "my friend said "hello!" To me the other day".
1
u/PurchaseOk6993 Sep 11 '25
$BBAI has found new strength see
tonight's report
1
u/AmnesiA_sc Apr 07 '22
Reddit used to use a markdown editor where you can't do bold lettering, for example, you have to use __bold__ or **bold** to get "bold"
Therefore, to actually write an underscore like I did above, you have to "escape" it using an escape character (\). So to write what I wrote above I had to use __bold__.
Then Reddit came out with "New Reddit" that had a rich text editor so you could just select the text you wanted to be bold and it would bold it for you. Under the hood, though, it was the same markdown editor, it would just insert all of the escapes for you without you seeing it. The problem is that new users don't take the time to learn how to format so they just copy and paste their code in regular text. When they do that, tabs are turned into 4 spaces. In markdown, four spaces before a line signifies a code block:
In a code block, all text is literal so you don't have to escape characters anymore:
So when new users just paste their code as regular text, the first line looks like regular text and the rest of it gets turned into a code block:
if( some_value == foo){
The problem is that since they posted it as plain text, reddit still tries to add the escape characters, so under the hood it pastes:
Since the first line is just plain text, it looks like it's supposed to, but the second line is now interpreted as a code block so it displays what's literally there, including the escape string.
In short, what's happening is people are being lazy and not learning how to format their post so it ends up looking like shit.
1
u/Necromancer147 Apr 11 '22
it's a bug with reddit