• 12
• 27
• 9
• 9
• 20

My OLD Syntax

This topic is 1591 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