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 swiftcoder   Senior Moderators   -  Reputation: 9845

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]


Sponsor:

#22 Ravyne   Crossbones+   -  Reputation: 7116

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?



#23 Luckless   Crossbones+   -  Reputation: 1764

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 Servant of the Lord   Crossbones+   -  Reputation: 18462

Like
12Likes
Like

Posted 03 August 2013 - 11:57 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.

 

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' 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] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#25 SimonForsman   Crossbones+   -  Reputation: 6034

Like
5Likes
Like

Posted 03 August 2013 - 12:05 PM

 

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 Shippou   Members   -  Reputation: 1471

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

 Reactions To Technologies:
1. Anything that is in the world when you’re born is normal and ordinary and is just a natural part of the way the world works.
2. Anything that's invented between when you’re fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it.
3. Anything invented after you're thirty-five is against the natural order of things.

- Douglas Adams 2002


 


#27 Sik_the_hedgehog   Crossbones+   -  Reputation: 1595

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 slicer4ever   Crossbones+   -  Reputation: 3465

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 Shippou   Members   -  Reputation: 1471

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


 Reactions To Technologies:
1. Anything that is in the world when you’re born is normal and ordinary and is just a natural part of the way the world works.
2. Anything that's invented between when you’re fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it.
3. Anything invented after you're thirty-five is against the natural order of things.

- Douglas Adams 2002


 


#30 GeneralQuery   Crossbones+   -  Reputation: 1263

Like
3Likes
Like

Posted 04 August 2013 - 05:52 AM

I say we paint it blue smile.png

#31 ByteTroll   Crossbones+   -  Reputation: 1304

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.

▬▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬▬▬▬▬
I see the future in 1's and 0's
▬▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬▬▬▬▬

"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

#32 Bacterius   Crossbones+   -  Reputation: 8474

Like
5Likes
Like

Posted 05 August 2013 - 06:14 AM

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.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#33 MarkS   Prime Members   -  Reputation: 882

Like
0Likes
Like

Posted 05 August 2013 - 12:03 PM

...snip...

 

...snip...


Thanks for the laugh! laugh.png



#34 slicer4ever   Crossbones+   -  Reputation: 3465

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 swiftcoder   Senior Moderators   -  Reputation: 9845

Like
6Likes
Like

Posted 05 August 2013 - 03:25 PM

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]


#36 Vortez   Crossbones+   -  Reputation: 2697

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 TheChubu   Crossbones+   -  Reputation: 4062

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 slicer4ever   Crossbones+   -  Reputation: 3465

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 Shippou   Members   -  Reputation: 1471

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.

 Reactions To Technologies:
1. Anything that is in the world when you’re born is normal and ordinary and is just a natural part of the way the world works.
2. Anything that's invented between when you’re fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it.
3. Anything invented after you're thirty-five is against the natural order of things.

- Douglas Adams 2002


 


#40 mhagain   Crossbones+   -  Reputation: 7802

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