dimanche 12 avril 2015

[Tutorial] 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 stock!





  • I am writing a filterscript.

    • You don't need stock!





  • I am writing an include.

    • Is the function or variable required to be used in a gamemode or filterscript? If yes, do not use stock. Do not use anything 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.




Aucun commentaire:

Enregistrer un commentaire