• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
TrentonK

My OLD Syntax

80 posts in this topic

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.

0

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
1

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
-1

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.

0

Share this post


Link to post
Share on other sites
Some people get religious about the bracing style. Meh. Same with the parentheses.

 

Though, admittedly not always without a reason, if you look at my snippet above (which is a real coding horror).

 

When I was first told "we always use braces, Allman style, even for single liners" long long long ago, my thought was "Bah...". Of course I didn't do such a stupid thing outside work, because it was just too silly. Guess what made me change my mind one day. Exactly... wasting 2 hours of time on trying to figure out why the program logic wasn't correct although it just had to be good -- everything was right. Except, well, you know.

Edited by samoth
0

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.

 

I meant the two @TrentonK in the original post - neither is worse than the other, and there's proponents for both styles.

 

Personally, I prefer is "old horrible nightmarish" style, for two super minor irrelevant reasons.
1) It's easier for me to spot if the first brace is missing.

2) It makes the code less cluttered-feeling by spacing it out more, making it easier for me to skim and comprehend code.

 

Whitespace is free. Monitors are large. Legibility is valuable.

0

Share this post


Link to post
Share on other sites

 

I meant the two @TrentonK in the original post - neither is worse than the other, and there's proponents for both styles.

I have yet to see somebody argue for not using parenthesis in an if clause (and I was talking about the original post).

 


I was waiting for that as well...blink.png

0

Share this post


Link to post
Share on other sites

I meant the two @TrentonK in the original post - neither is worse than the other, and there's proponents for both styles.

I have yet to see somebody argue for not using parenthesis in an if clause (and I was talking about the original post).

I was waiting for that as well...blink.png

4 less keystrokes on a typical keyboard.

Whether you think that's a valid argument or not is another story, but I know people who value minimizing key strokes.
1

Share this post


Link to post
Share on other sites

Curly brace arguments. Keeping programmers busy since 1969. tongue.png

 

Besides, the only correct brace style is the one I use.

Edited by Bacterius
2

Share this post


Link to post
Share on other sites

Is that legal syntax? I tried that in VS 2012 and it yelled at me.

It looks like it's not, at least according to section 6.4 of the C++ standard. It defines selection-statements as:

selection-statement:
if ( condition ) statement
if ( condition ) statement else statement
switch ( condition ) statement
 
The parentheses here are part of the definition of if and switch, so I would conclude that no, they are not optional.
0

Share this post


Link to post
Share on other sites

Syntax aside, what's actually concerning about the OP's before and after code, is that they're tying input processing directly to logic. Its well-enough for prototypes or small things, but it's probably gonna break-down right around the time you want to make the character jump, or do any kind of animation.

 

Be ye character? Or cursor?

1

Share this post


Link to post
Share on other sites

If I'm going to use curly braces, then I want the open and closed characters nicely lined up vertically. Makes things nice and neat by grouping things in blocks.

 

But personally I just use Python these days and ignore these debates.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0