[Tutorial] Function Type Explanation (stock, public, plain)
#8

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
With all due respect, go make a public function and try to return a string, and try another public function that doesn't return a value.

I think you'll understand what I mean.
I was referring to the code you provided as a response to Cell. I added the returning strings in a public function to the thread, thanks for that.


Quote:
Originally Posted by Simon
Посмотреть сообщение
You make it sound it sound as if a method tagged stock will hide all warnings associated with it. This is a side-effect of what an unused stock method does i.e. nothing because it's not compiled into the P-code. The Pawn compiler will still complain about warnings associated with a stock method if it is referenced in your code.

A stock method is a method that is allowed to be skipped by the parser if it's not used. In other words, you will not be warned that it is unused and it does not exist in the compiled code. A method that is not tagged stock and is also unused is still compiled into the P-code, thus using space in the compiled code.

You might ask now why doesn't the Pawn compiler just remove unused tagged stock or not to save space? One reason being because it cannot infer whether or not the method is compiled into the script for external purposes (i.e. a public method). You may have public "unused" methods that are callable by an external program.



Код:
// start of script
main() {
    foo1(); 
    // foo2() unused, warning
}

foo1() { /* */ }
foo2() { /* */ }
// end script
I personally use stocks wherever you might use a "plain" function, dealing with unused methods/variables warnings is a hassle to me. If you want to enforce that a function MUST be used then don't use stocks. I've never had the case where a function MUST be used... most people won't unless they do a lot of design up front and would like to be warned if they forgot to include a method.
Usually people implement functions into their script because they need it for something they're working on. I'm not against stocks, but apparently not a lot of people actually know the difference between publics, stocks, and plain functions, which is the reason I posted this thread.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)