Stop the abuse of stock! -
Vince - 12.04.2015
What is stock?
The stock keyword, like const, is a
modifier that tells the compiler to hide a variable or a function if it is not used. Contrary to popular believe in the SA-MP community,
stock is not a requirement. Functions do not require a special keyword in Pawn. The word "stock" is not interchangeable with the word "function" either.
Quote:
Originally Posted by random scripting help topic
Hi, I'm writing this stock ...
|
No, you're writing a function!
When to use stock?- I am writing a gamemode.
- You don't need the stock keyword!
- I am writing a filterscript.
- You don't need the stock keyword!
- I am writing an include.
- Is the function or variable required to be used in a gamemode or filterscript? If yes, do not use the stock keyword. Do not use any keyword at all.
- Is the function or variable for internal use only? If yes, use static.
- Is the function or variable for internal use only, but is there a chance that it may not be used (conditional compiling)? If yes, use static stock
- If none of the above are met, only then is it appropriate to use stock.
Removing the stock modifier from ALL functions in your gamemode or filterscript is a good way to start. If you receive a few "symbol is never used" warnings after doing so then that means your gamemode is cluttered. It means you have functions which do nothing but waste your scroll wheel. Consider removing those functions or move them to an appropriate include file.
Re: Stop the abuse of stock! -
Glossy42O - 12.04.2015
Nice, didn't knew
Re: Stop the abuse of stock! -
FernandoLight - 12.04.2015
lool
Re: Stop the abuse of stock! - Emmet_ - 12.04.2015
Nicely written. Hopefully people can understand that "stock" is not a keyword for "function". I used to spam it in my scripts myself, so I am guilty of doing this. I read over the documentation again and came to a conclusion that I don't even need it!
I guess you could say the same thing for global static variables in a gamemode - it's not needed.
AW: Stop the abuse of stock! -
Mellnik - 12.04.2015
Stop stock abuse, NOW!
Sign the petition:
stopstockkeywordabuseinpawnscripts.com
Re: Stop the abuse of stock! - Patrick - 12.04.2015
Amen!
Re: Stop the abuse of stock! -
Abagail - 12.04.2015
Why isn't this a sticky yet
Re: Stop the abuse of stock! -
iZN - 12.04.2015
They STILL won't understand the true meaning of that keyword. I stopped bothering with the current community members since most of them are not learning, they're on Scripting Help board to get an quick answer, and resolve their issues without even looking what that answer holds.
Nice of you to actually post something like that, good piece of advice.
Quote:
Originally Posted by Vince
No, you're writing a function!
|
stock angryface(jpg) {}
Re: Stop the abuse of stock! -
Michael@Belgium - 12.04.2015
I like to use stock, it's short to write and easy to use. Don't tell me what to do.
If it works .. it works.
So you're basicly saying to always write publics and forward them ? I don't like to type much.
Re: Stop the abuse of stock! -
Vince - 12.04.2015
Did you actually read what I wrote? Stock is not a requirement. It is merely a modifier.
pawn Code:
myFunction(parameter)
{
printf("the parameter is %d", parameter);
}
This works. Nothing else required.
Re: Stop the abuse of stock! -
iZN - 12.04.2015
Quote:
Originally Posted by Michael@Belgium
I like to use stock, it's short to write and easy to use. Don't tell me what to do. If it works .. it works.
So you're basicly saying to always write publics and forward them ? I don't like to type much.
|
You got him all wrong, he basically meant, you could simply do like this:
pawn Code:
whateverFunction(with, whatever, parameters = 1) {}
So basically, you're not required to use "stock", you could leave it naked or the other ways of using "static" keyword if it's used locally/internally.
Re: Stop the abuse of stock! -
Michael@Belgium - 12.04.2015
Quote:
Originally Posted by Vince
Did you actually read what I wrote? Stock is not a requirement. It is merely a modifier.
pawn Code:
myFunction(parameter) { printf("the parameter is %d", parameter); }
This works. Nothing else required.
|
Quote:
Originally Posted by iZN
You got him all wrong, he basically meant, you could simply do like this:
pawn Code:
whateverFunction(with, whatever, parameters = 1) {}
So basically, you're not required to use "stock", you could leave it naked or the other ways of using "static" keyword if it's used locally/internally.
|
Alright, i deserve -rep now tbh. I always learned to use stock because those damn tutorials ..
And yes Vince, i did read. But too fast.
Re: Stop the abuse of stock! -
yugecin - 12.04.2015
I always wondered why people would put stock before every function. I would think most scripters know what they're doing, or perhaps "because it looks pretty with a keyword" (the stock keyword is ugly imho).
Just write functions and if you don't use one, the compiler will kindly remember you and then refactor your code instead of filling it with stock modifiers.
Re: Stop the abuse of stock! -
EiresJason - 12.04.2015
I find it much easier putting 'stock' in front of a function to find a particular function though.
Like, I want to edit the function (for example)
pawn Code:
SetPlayerLevel(playerid, level) {
//..code
}
But let's say I actually call it 15 times in my script. Pressing CTRL+F and searching for "SetPlayerLevel" may need to me to skip past a good few calls before I get to the actual function, but having..
pawn Code:
stock SetPlayerLevel(playerid, level) {
//..code
}
lets me just search for "k SetPlayerLevel" and I'm at it right away.
If that makes sense xD
Re: Stop the abuse of stock! -
Onfroi - 13.04.2015
I thought stock is faster as well, more optimized, it's not?
Re: Stop the abuse of stock! -
Gammix - 13.04.2015
Quote:
Originally Posted by Onfroi
I thought stock is faster as well, more optimized, it's not?
|
No, i think bit slower than a function.
Re: Stop the abuse of stock! -
Abagail - 13.04.2015
Quote:
Originally Posted by EiresJason
I find it much easier putting 'stock' in front of a function to find a particular function though.
Like, I want to edit the function (for example)
pawn Code:
SetPlayerLevel(playerid, level) { //..code }
But let's say I actually call it 15 times in my script. Pressing CTRL+F and searching for "SetPlayerLevel" may need to me to skip past a good few calls before I get to the actual function, but having..
pawn Code:
stock SetPlayerLevel(playerid, level) { //..code }
lets me just search for "k SetPlayerLevel" and I'm at it right away.
If that makes sense xD
|
This isn't a good enough reason to use stock, you can even simply do something such as this:
pawn Code:
#define SetPlayerLevelEx FUNC_SetPlayerLevel
pawn Code:
FUNC_SetPlayerLevel(playerid, level) {
// .. code
Then you can just search for "FUNC_Functionname", - calling the function throughout the script as "SetPlayerLevelEx".
If it gets on your nerves so much try this or another method, but as I said this is NOT A GOOD REASON TO USE STOCK!
Re: Stop the abuse of stock! -
EiresJason - 13.04.2015
Quote:
Originally Posted by Abagail
This isn't a good enough reason to use stock, you can even simply do something such as this:
pawn Code:
#define SetPlayerLevelEx FUNC_SetPlayerLevel
pawn Code:
FUNC_SetPlayerLevel(playerid, level) { // .. code
Then you can just search for "FUNC_Functionname", - calling the function throughout the script as "SetPlayerLevelEx".
If it gets on your nerves so much try this or another method, but as I said this is NOT A GOOD REASON TO USE STOCK!
|
Could you explain why it isn't good enough though? At the moment though , when I'm going to compile my GM, I just replace all instances of "stock " with "" so it removes the stock modifier at compile time and I have the easy search functionality when I'm scripting.
Thanks for the suggestion but it doesn't seem reasonable to do that for every single function I use
EDIT: So yeah.. it literally makes no difference? XD
Re: Stop the abuse of stock! -
Pottus - 13.04.2015
Quote:
Originally Posted by Abagail
This isn't a good enough reason to use stock, you can even simply do something such as this:
pawn Code:
#define SetPlayerLevelEx FUNC_SetPlayerLevel
pawn Code:
FUNC_SetPlayerLevel(playerid, level) { // .. code
Then you can just search for "FUNC_Functionname", - calling the function throughout the script as "SetPlayerLevelEx".
If it gets on your nerves so much try this or another method, but as I said this is NOT A GOOD REASON TO USE STOCK!
|
Why even do that? Just put #define Function at the top of your script then.
Ex.
Function Test();
Re: Stop the abuse of stock! -
Abagail - 13.04.2015
Quote:
Originally Posted by Pottus
Why even do that? Just put #define Function at the top of your script then.
Ex.
Function Test();
|
What do you mean by #define function? What I am saying is he should look into internally using a function name for the actual function, while within the .pwn file using another one for within the script(calling the function), however in compilation, everything will be the same.