Thread: [Tutorial] Stop the abuse of stock!
View Single Post
Old 12/04/2015, 09:26 AM   #1
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,977
Reputation: 2649
Default Stop the abuse of stock!

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

Last edited by Vince; 07/06/2016 at 12:26 PM. Reason: Some typos
Vince is offline   Reply With Quote