Question about variables.
#1

Lately I've been downloading gamemodes to learn pawn. I've seen that many people create their variables like this:
Code:
new 
    variable,
    variable2;
instead of

Code:
new variable, variable2;
But why? Why do you put the variable name in a new line? I just don't get it. Maybe there is some general explanation in programming? I'm new to programming.
Reply
#2

Is not any difference.
You can use:
HTML Code:
new variable;
new variable2;
or
HTML Code:
new variable, variable2;
or
HTML Code:
new
    variable,
    variable2;
Is just for make a "great" design to your code lines.
Reply
#3

Yeah, I know, that there is no difference. But why are people creating them like that? Maybe readability? Or is it just a personal preference?
Reply
#4

Its a way to visualize your variables better.
When you write a lot of code and/or create a lot of variables and arrays on the same line, you often have a difficulty finding an array you're looking for and sometimes you even have arrays there that you haven't used or unsure if you even have one.

This is a comfortable way to see how you named your variables and their settings (default value, size)
It has no difference in functionality than the other approach, the only difference is the clearity of seeing and easiness of finding different arrays.


I personally have a game mode with over ~40 variables that are separated by a break line and have declared only once "new", a lot nicer as well than reusing the "new" operator and seeing that blue text on every line.
Reply
#5

So, is it okay to create many variable with only one "new" operator? Maybe I should create variables this way too.
Reply
#6

“As long as it runs”, a phrase that all lazy scripters use as excuses to cover their bad scripting habits, code should also be optimised AND readable too, and what's readable for you, don't mean it's readable for me too, for each their style, that's why you would find a lot of opinions on which on the above is the best and most readable layout.
Reply
#7

Quote:
Originally Posted by RageCraftLV
View Post
So, is it okay to create many variable with only one "new" operator? Maybe I should create variables this way too.
Should be completely fine.

You don't have to use it that way, I usually use it for bigger sets of variables than two, try and see what is most comfortable for you.


Also, a good read for naming these variables
https://sampforum.blast.hk/showthread.php?tid=631607


EDIT:
Quote:
Originally Posted by Eoussama
View Post
“As long as it runs”, a phrase that all lazy scripters use as excuses to cover their bad scripting habits,
You don't have to be lazy to write bad code, it is a good way to reach a destination to give birth to your concept.
After you code it badly, you can optimize it to a good code.

Quote:
Originally Posted by Eoussama
View Post
code should also be optimised AND readable too, and what's readable for you, don't mean it's readable for me too, for each their style, that's why you would find a lot of opinions on which on the above is the best and most readable layout.
As long as you don't work for a company or creating an open source, there is no need to make it universally readable. But only comfortable me, myself and I.
Reply
#8

in my condition or explanation this type of variable system if declare'd on script-er side.

example: you can make variables for the maximum amounts of players that use a variable like toggling settings, toggling messages etc.

Quote:

new
var1,
var2,
var3
;

Reply
#9

No difference at all, output/compiled code will be the same.
But if you add variables in separate line they look nicer, stick out and eye catches them easier.
Also if everything is in new line its easy to comment out single variable if needed
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)