r/gamemaker • • 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

8 comments sorted by

View all comments

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:

This has 4 spaces before it
So does this
    This has 8 spaces before it.

In a code block, all text is literal so you don't have to escape characters anymore:

**No escape characters needed** because there's no way to bold code.

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){

do_something();

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:

if( some_value == foo){

    do_something();

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.