# My OLD Syntax

This topic is 2077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I still remember how I used to program. My syntax was horrible:

if keyboard_check(vk_left)
{
x-=5;
}
if keyboard_check(vk_right)
{
x+=5;
}
if keyboard_check(vk_up)
{
y-=5;
}
if keyboard_check(vk_down)
{
y+=5;
}


This is how I do it now...So much better:

if (keyboard_check(vk_left)){
x -= 5;
}

if (keyboard_check(vk_right)){
x += 5;
}

if (keyboard_check(vk_up)){
y -= 5;
}

if (keyboard_check(vk_down)){
y += 5;
}


Just imagine hundreds or sometimes thousands of lines of code similar to the first one....what a nightmare lol.

##### Share on other sites

And this is how you do it in the future:

if (keyboard_check(vk_left))
x -= 5;
if (keyboard_check(vk_right))
x += 5;
if (keyboard_check(vk_up))
y -= 5;
if (keyboard_check(vk_down))
y += 5;

Pay attention to the more compact form at the cost of flexibility.

##### Share on other sites

Seriously though, incase the original poster isn't joking, both those are commonly used syntaxes, and some professionals advocate for one, and some professionals advocate for another, and neither is necessarily superior than the other.

Seriously? I don't think most people know that you can omit the parenthesis, they probably think it'd be a syntax error.

EDIT: it becomes handy with type casting though. Instead of (int)(x) you could write int(x). Looks nifty, and syntax highlight will still make sure it's obvious it's a casting. Probably still better avoided, though.

Edited by Sik_the_hedgehog

##### Share on other sites

And once you've mastered C++, and have the official and secretive gold C++ guru medal around your neck, you code like this:

if(keyboard_check(vk_left))  x -= 5;
if(keyboard_check(vk_right)) x += 5;
if(keyboard_check(vk_up))    y -= 5;
if(keyboard_check(vk_down))  y += 5;

Now if there was a space between the if and the (, it'd be perfect ;)

@OP: it took me a good 5 seconds to even spot a difference between your two styles. The only difference between the two is a set of parentheses and Allman vs K&R bracing. The difference is minor. If you think your old style is horrible, then you must think your new style is at least slightly horrible too, seeing as the difference really is very minor.

Some people get religious about the bracing style. Meh. Same with the parentheses. Edited by Cornstalks

##### Share on other sites

Personally, I greatly dislike the opening bracket on the same line of code.  Instead of just being able to scan horizontally for blocks of code now you must go horizontally until you see a closing bracket and then backtrack to find the open one instead of both being at the same tab stop.  I prefer Waterlimon's way of doing it.  But Servant's doesn't give me too much of a twitch.  I'm very anal about my code looking 'pretty' and well aligned.

• 21
• 11
• 9
• 17
• 13