Jump to content
  • Advertisement
Sign in to follow this  
TrentonK

My OLD Syntax

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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. smile.png

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!