Posts: 56
Threads: 10
Joined: Jun 2016
Reputation:
0
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?
Posts: 3,004
Threads: 12
Joined: May 2011
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.
Posts: 56
Threads: 10
Joined: Jun 2016
Reputation:
0
So, is it okay to create many variable with only one "new" operator? Maybe I should create variables this way too.
Posts: 1,076
Threads: 70
Joined: Jul 2016
Reputation:
0
“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.
Posts: 3,004
Threads: 12
Joined: May 2011
Quote:
Originally Posted by RageCraftLV
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
“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
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.
Posts: 2,203
Threads: 154
Joined: Oct 2009
Reputation:
0
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