• Create Account

## My OLD Syntax

83 replies to this topic

### #21swiftcoder  Senior Moderators

Posted 01 August 2013 - 07:05 PM

The real WTF is that on my keyboard only 2 of the conditions can possibly be true at any one time.

Keyboard ghosting, FTW.

Tristam MacDonald - Software Engineer @ Amazon - [swiftcoding] [GitHub]

### #22Ravyne  Members

Posted 01 August 2013 - 07:13 PM

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?

throw table_exception("(ノ ゜Д゜)ノ ︵ ┻━┻");

### #23Luckless  Members

Posted 03 August 2013 - 11:50 AM

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.

If your signature on a web forum takes up more space than your average post, then you are doing things wrong.

### #24Servant of the Lord  Members

Posted 03 August 2013 - 11:57 AM

POPULAR

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.

Well, if you insist:

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;
}


It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

### #25SimonForsman  Members

Posted 03 August 2013 - 12:05 PM

POPULAR

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.

Well, if you insist:

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;
}


You're wasting vertical space ... this is much better

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


Edited by SimonForsman, 03 August 2013 - 12:06 PM.

I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

### #26Code Fox  GDNet+

Posted 03 August 2013 - 09:50 PM

The OP code is not much different, however I find that

if (!something)
{
do stuff;
}


is a lot harder to read when I have a nest that is 5+ deep.

I personally prefer

if (!something){
do stuff;
}


I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

### #27Sik_the_hedgehog  Members

Posted 03 August 2013 - 10:59 PM

If you have a nesting that deep probably the issue is the excessive nesting... (easier said than done, since this is not just a coding style issue, it's a programming issue as it's directly tied to the code structure)

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

### #28slicer4ever  GDNet+

Posted 04 August 2013 - 02:35 AM

I swear we had a programming style's discussion/argument not less than a month ago.  will it never end?!

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #29Code Fox  GDNet+

Posted 04 August 2013 - 05:14 AM

If you have a nesting that deep probably the issue is the excessive nesting... (easier said than done, since this is not just a coding style issue, it's a programming issue as it's directly tied to the code structure)

Hmm, let me dig around and see if I can find one of my "overly nested" projects . ( LSL is a nightmare for nests, however I do not believe I have any examples in that language left . )

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

### #30GeneralQuery  Members

Posted 04 August 2013 - 05:52 AM

I say we paint it blue

### #31ByteTroll  Members

Posted 05 August 2013 - 05:52 AM

I swear we had a programming style's discussion/argument not less than a month ago.  will it never end?!

Nope, it is a hazard of the profession

You're wasting vertical space ... this is much better

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

There is nothing wrong with wasting space.  As Servant said "Whitespace is free.  Monitors are large."  Everyone knows this is the right way:

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

Edited by ByteTroll, 05 August 2013 - 06:02 AM.

"The code you write when you learn a new language is shit.
You either already know that and you are wise, or you don’t realize it for many years and you are an idiot. Either way, your learning code is objectively shit." - L. Spiro

"This is called programming. The art of typing shit into an editor/IDE is not programming, it's basically data entry. The part that makes a programmer a programmer is their problem solving skills." - Serapth

"The 'friend' relationship in c++ is the tightest coupling you can give two objects. Friends can reach out and touch your privates." - frob

### #32Bacterius  Members

Posted 05 August 2013 - 06:14 AM

POPULAR

Who needs vertical space?

k\
e\
y\
b\
o\
a\
r\
d\
_\
c\
h\
e\
c\
k\
(\
v\
k\
_\
l\
e\
f\
t\
)\

/* ... */


As a bonus, all curly brace, whitespace, and indentation arguments are solved.

PS: the alternative is using absolutely no newlines, which in my opinion is less readable and doesn't take advantage of large monitors as well as this variant.

Edited by Bacterius, 05 August 2013 - 06:17 AM.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #33MarkS  Members

Posted 05 August 2013 - 12:03 PM

...snip...

...snip...

Thanks for the laugh!

### #34slicer4ever  GDNet+

Posted 05 August 2013 - 03:05 PM

...snip...

As a bonus, all curly brace, whitespace, and indentation arguments are solved.

I think you have an incorrect definition for the word "solved".

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #35swiftcoder  Senior Moderators

Posted 05 August 2013 - 03:25 PM

POPULAR

I think you have an incorrect definition for the word "solved".

It's the corporate definition of "solved".

As in: "You contracted with us to build a text-based MUD, so we licensed the Unreal engine".

Tristam MacDonald - Software Engineer @ Amazon - [swiftcoding] [GitHub]

### #36Vortez  Members

Posted 06 August 2013 - 09:16 AM

Since the 4 ifs are nearly identical, why not wrap this up in a function or something?

Ex:

void CheckKeyboard(int k, int *p, int i)
{
if(keyboard_check(k))
*p += i;
}

...

const int i = 5;
int x, y;

CheckKeyboard(vk_left,  &x, -i);
CheckKeyboard(vk_right, &x,  i);
CheckKeyboard(vk_up,    &y, -i);
CheckKeyboard(vk_down,  &y,  i);



I Should have used a better function name than CheckKeyboard but none came to mind...

### #37TheChubu  Members

Posted 06 August 2013 - 10:00 AM

Do you check the keyboard or do you keyboard the check?

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

### #38slicer4ever  GDNet+

Posted 06 August 2013 - 10:13 AM

Since the 4 ifs are nearly identical, why not wrap this up in a function or something?

Ex:

void CheckKeyboard(int k, int *p, int i){	if(keyboard_check(k))		*p += i;}...const int i = 5;int x, y;CheckKeyboard(vk_left,  &x, -i);CheckKeyboard(vk_right, &x,  i);CheckKeyboard(vk_up,    &y, -i);CheckKeyboard(vk_down,  &y,  i);
I Should have used a better function name than CheckKeyboard but none came to mind...
Just get rid of the if's and use the result of keyboard_check directly:

x += (int)keyboard_check(vk_right);X -= (int)keyboard_check(vk_left);y += (int)keyboard_check(vk_down);y -= (int)keyboard_check(vk_up);
and bam, no more indentation/brace positioning problems. =-)
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #39Code Fox  GDNet+

Posted 06 August 2013 - 11:03 AM

Since the 4 ifs are nearly identical, why not wrap this up in a function or something?

Ex:

void CheckKeyboard(int k, int *p, int i){	if(keyboard_check(k))		*p += i;}...const int i = 5;int x, y;CheckKeyboard(vk_left,  &x, -i);CheckKeyboard(vk_right, &x,  i);CheckKeyboard(vk_up,    &y, -i);CheckKeyboard(vk_down,  &y,  i);
I Should have used a better function name than CheckKeyboard but none came to mind...

Just get rid of the if's and use the result of keyboard_check directly:

x += (int)keyboard_check(vk_right);
X -= (int)keyboard_check(vk_left);
y += (int)keyboard_check(vk_down);
y -= (int)keyboard_check(vk_up);

and bam, no more indentation/bracket positioning problems. =-)

If the language your using uses "1", "0", and "-1" for boolean that might work ( if you can deal with the "-1" ) ,  HOWEVER the increments the OP used are by 5, which throws a wrench in your example.

Edited by Shippou, 06 August 2013 - 11:05 AM.

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

### #40mhagain  Members

Posted 06 August 2013 - 12:40 PM

Do you check the keyboard or do you keyboard the check?

In Soviet Russia the keyboard checks you!  (...or maybe the check keyboards you, which sounds a mite painful...)

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.