Jump to content

  • Log In with Google      Sign In   
  • Create Account

My OLD Syntax

  • You cannot reply to this topic
83 replies to this topic

#21   Senior Moderators   -  Reputation: 17606

Like
0Likes
Like

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]


#22   GDNet+   -  Reputation: 13672

Like
1Likes
Like

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("(ノ ゜Д゜)ノ ︵ ┻━┻");


#23   Crossbones+   -  Reputation: 2838

Like
0Likes
Like

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.


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

#24   Crossbones+   -  Reputation: 33028

Like
12Likes
Like

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

laugh.png


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 - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal | [Fly with me on Twitter


#25   Crossbones+   -  Reputation: 7496

Like
5Likes
Like

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

laugh.png

 

 

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

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!

#26   GDNet+   -  Reputation: 3039

Like
0Likes
Like

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

Code_Fox_Sig.png


#27   Crossbones+   -  Reputation: 2795

Like
1Likes
Like

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.

#28   Crossbones+   -  Reputation: 6159

Like
0Likes
Like

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.

#29   GDNet+   -  Reputation: 3039

Like
0Likes
Like

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

Code_Fox_Sig.png


#30   Crossbones+   -  Reputation: 1263

Like
3Likes
Like

Posted 04 August 2013 - 05:52 AM

I say we paint it blue smile.png

#31   Crossbones+   -  Reputation: 2850

Like
2Likes
Like

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 rolleyes.gif

 

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

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


#32   Crossbones+   -  Reputation: 12938

Like
5Likes
Like

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.”


#33   Crossbones+   -  Reputation: 2782

Like
0Likes
Like

Posted 05 August 2013 - 12:03 PM

...snip...

 

...snip...


Thanks for the laugh! laugh.png



#34   Crossbones+   -  Reputation: 6159

Like
0Likes
Like

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.

#35   Senior Moderators   -  Reputation: 17606

Like
6Likes
Like

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]


#36   Crossbones+   -  Reputation: 2705

Like
0Likes
Like

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



#37   Crossbones+   -  Reputation: 8590

Like
3Likes
Like

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


#38   Crossbones+   -  Reputation: 6159

Like
0Likes
Like

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.

#39   GDNet+   -  Reputation: 3039

Like
0Likes
Like

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

Code_Fox_Sig.png


#40   Crossbones+   -  Reputation: 12027

Like
1Likes
Like

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.






PARTNERS