[Tutorial] Stop the abuse of stock!
#21

There is no point to say whether write stock in front of functions in GM's/FS's or not.

It's the same discussion doing

PHP Code:
MyItem() {
    
// Some shit

PHP Code:
MyItem() 
{
    
// Some shit

Its just estetic, and will provoke only infinite discussions.
Reply
#22

Let me explain again....

Put #define Function at the top of your script
Then denote any functions with that...

Function Test1() {}
Function Test2() {}
Function Test3() {}
Function Test4() {}
Function Test5() {}

It won't do anything but make it easier to search for your function declaration.
Reply
#23

Quote:
Originally Posted by Onfroi
View Post
I thought stock is faster as well, more optimized, it's not?
Quote:
Originally Posted by Gammix
View Post
No, i think bit slower than a function.
Quote:
Originally Posted by ipsLeon
View Post
Nice tutorial, will help a lot of beginners, and one more reason for don't use stock: your code will be faster, stocks are "lazy". If you want to do a smart and fast script its a nice way to start.
Adding that modifier won't make a difference, it will NEVER make your function faster nor slower. Your piece of code reflects the optimization and the speed of it. For example, calculating something very intensive in your function will obviously make that function "abit" slower than the normal one having nothing just a "printf()" statement for say.

@ipsLeon: I don't know if you implied the laziness of the scripter, or the speed comparison of "stock", I apologize if I quoted you wrongfully.

Quote:
Originally Posted by arakuta
View Post
There is no point to say whether write stock in front of functions in GM's/FS's or not.

It's the same discussion doing

PHP Code:
MyItem() {
    
// Some shit

PHP Code:
MyItem() 
{
    
// Some shit

Its just estetic, and will provoke only infinite discussions.
Sorry but discussion about indentation is not the same with something logical. This discussion is not something "esthetic" it is just a piece of advice for scripters and it won't provoke infinite discussion, it will just answer some unanswered questions.
Reply
#24

@Emmet_ : static globals are useful. But only in libraries.

OT : Nice tut. I was aware of it, though never told it to correct someone - I'm maybe guilty or maybe not, not that I answered much helping threads - IMO that was useless since, as someone (sorry to not remember the name) said above, the lambda samp user won't learn from this. Some of them will read, but none of them will learn. Their only point being here is to get their scripting problems solved by someone else.

By the way we're talking about functions, I read somewhere that you could "forward" public functions using the "static" keyword. This way, the public function will be static : if another function with the same name exists in a gamemode where your library is included, it won't create compiling errors.

PHP Code:

// in mylib.inc

static myPublic();
public 
myPublic()
{
      
printf("Called from library");
}

// in gm

#include <mylib>

forward myPublic();
public 
myPublic()
{
      
printf("Called from gamemode");
      return 
1;

Reply
#25

...it's doesn't matter for the .amx if you write stock in front of a function or not, if you use it.

So...why not
Reply
#26

Quote:
Originally Posted by Kaliber
View Post
...it's doesn't matter for the .amx if you write stock in front of a function or not, if you use it.

So...why not
I don't really know if removing it will affect anything like performance...
But what everyone is trying to say is that everyone are using stock wrong.
Reply
#27

Thank you for posting this. It really irks me that people write code when they don't really know what it does.
Reply
#28

@Kaliber : Probably one of the most stupid things I've ever read here.

Indentation also doesn't matter for the amx file. Your whole gamemode is actually one line.
Doing that is thus perfectly acceptable (and will compile fine) :

PHP Code:

main
{printf("My gamemode is loaded !");} public OnPlayerConnect(playerid){if(isBanned(playerid)) Kick(playerid); SendClientMessage(playerid,-1,"Welcome to my server mate !");} public OnPlayerDisconnect(playeridreason){if(reason==1SendClientMessage(playerid,-1"See you soon mate !"); else SendClientMessageToAll(-1"Someone got a problem and got disconnected :(");} 
So...Why not ?

You know that it won't affect the amx file to put spaces, though, you still do it.
It's the same way with stock. It won't affect the amx file whether you put it or not, but if you put it everywhere, you simply forget why this keyword has been made for.
Reply
#29

Quote:
Originally Posted by S4t3K
View Post
you simply forget why this keyword has been made for.
Ahh yes sure...

Seems legit
Reply
#30

I'm using stock instead public for a whole time, it's that correct? :/
Reply
#31

Thanks for the info.
Reply
#32

There are a couple of points in this topic that I disagree with.

Is there any evidence to suggest the use of stock has any impact on the code or performance whatsoever?

It was highlighted in a previous post that prefixing functions with "stock" is useful for searchability which is an important thing when we have such limited IDE's for PAWN.
Yes, you can add preprocesser defines for "function", but if the use of stock doesn't make a difference, why bother? Also, "function" is a very broad term - what about callbacks or mutator methods?

Quote:
Originally Posted by Vince
View Post
  • 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
Perhaps you need to elaborate on the term "internal" here. The static keyword will bind a function/variable to the specific file that it is being declared in (think of it as the private access modifier).
One could argue that in the context of which you're using this term, filterscripts or gamemodes which may consist of many different files would be classed as "internal" as they're not includes.
Reply
#33

I use stock but only in one file normally.
The reason is I have a include with many functions i wrote or some from the useful functions thread.
These are functions that may or may not be used in a gamemode.
Now instead of making a new include for each game mode and picking and hunting only the "stock functions"
i need i just include the same one with every mode.(lazy yes i know)


Also when i start a new mode, i may plan to use most/all the functions in the final release however
impossible to use them all right away. As my mode grows the functions are available to me.(I kinda thought this is what stock was for)
I suppose when something becomes a release it would not be a bad idea
to remove the stock modifier from the include and remove unused functions.

anyhow good insights
thanks.
Reply
#34

This topic really need an explanation.
#57
Reply
#35

So, at the same time there's no disadvantage in using stocks?
(of course, unless you add random stocks to your script that you don't even use)

On the contrary, there is an advantage in using stocks, say you're using the same function on your gamemode like a hundred times, but you want to find the actual function that contains all the code, how do you find it? You can't just do CTRL + F and "MyFunction" because that would give you 100 finds, but if you use stocks, you can easily search "stock MyFunction" and find what you're looking for
Reply
#36

Nice Tutorial.
Reply
#37

https://sampforum.blast.hk/showthread.php?tid=585465

This thread is pure non-sense.
Reply
#38

Another reason why you would use a stock is that you can search for "stock Functionname" if you don't use stock you will need to search for "functionname" which will bring in results that the function itself is used.

A way to counter this is moving all functions to a module / include. But that doesn't help either if you are doing a "search all" at sublime text or anyother text editor though.
Reply
#39

So, am I right in thinking.... that Stock is a modifier that hides the function at compile-time if its not used anywhere in the script?

If that's all it does, then why not use it? What's the fuss over not using the stock modifier?
Reply
#40

Quote:
Originally Posted by Darrenr
Посмотреть сообщение
So, am I right in thinking.... that Stock is a modifier that hides the function at compile-time if its not used anywhere in the script?

If that's all it does, then why not use it? What's the fuss over not using the stock modifier?
There is nothing wrong with using it, Vince is trying to imply that when you are using 'stock' modifier to create functions it does not show if it is not in use and you could forget about it and it just wastes your space in the gamemode, you'll only get warnings/errors if the function that has the 'stock' modifier is used.

There is advantages to it as well, it allows you to access the core of the function faster rather than going through every single line to find the source of the function.

Don't get confused you are allowed to use it in the gamemode there is barely a disadvantage in using it except for what Vince stated.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)