My OLD Syntax

Started by
79 comments, last by 21st Century Moose 10 years, 5 months ago

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

"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

Advertisement

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.

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

...snip...

...snip...


Thanks for the laugh! laugh.png

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

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. Ex-BigTech Software Engineer. Future farmer. [https://trist.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...

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

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.

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.

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

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

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement