Raised This Month: $12 Target: $400
 3% 

In general, when should I use stock vs public vs [blank]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-31-2014 , 02:43   In general, when should I use stock vs public vs [blank]
Reply With Quote #1

Whenever I make new functions I usually just use stock Function() because I see that used a lot, or sometimes just Function() for absolutely no reason.

What difference does it all make? When should I use what?

(If its a native or something that normally requires public or whatever it requires, of course, I'll use that).
__________________

Last edited by Chdata; 01-31-2014 at 02:44.
Chdata is offline
floube
SourceMod Donor
Join Date: Jan 2013
Location: Austria
Old 01-31-2014 , 02:49   Re: In general, when should I use stock vs public vs [blank]
Reply With Quote #2

AFAIK when using something like SomeRandomFunction(data=0) you must use stock or [blank].
__________________

Last edited by floube; 01-31-2014 at 02:50.
floube is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 01-31-2014 , 03:38   Re: In general, when should I use stock vs public vs [blank]
Reply With Quote #3

If you apply a stock prefix, then the compiler won't be yelling at you if you don't use the function somewhere in the plugin.
__________________
thetwistedpanda is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-31-2014 , 04:19   Re: In general, when should I use stock vs public vs [blank]
Reply With Quote #4

stock is for functions in include files (they don't get compiled into the plugin if unused), public is for functions that other plugins or SourceMod needs to be able to call (i.e. forward callbacks), and no specifier is for everything else (there is also static which is used for "internal" functions in include files, which are only visible to other functions in that file).
__________________
asherkin is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 01-31-2014 , 16:13   Re: In general, when should I use stock vs public vs [blank]
Reply With Quote #5

Try to avoid using stock in standard .sp files since the larger the code gets the more likely your source code will still be containing a function that you no longer require, and with stock you'll forget it's hiding there.
__________________
11530 is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 01-31-2014 , 21:11   Re: In general, when should I use stock vs public vs [blank]
Reply With Quote #6

stock are just going to get compile if you use the function, public is basically for callbacks (functions called into your plugin but that not coming from your plugin), nothing just mean your function is private, you use private function for everything that stay inside your codes.

EDIT: What asherkin said.

Last edited by Mathias.; 01-31-2014 at 21:12.
Mathias. is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 02-01-2014 , 04:52   Re: In general, when should I use stock vs public vs [blank]
Reply With Quote #7

use public for every function
new for every variable
IsValidClient in every loop

who needs parsimony in programming when you have 8+ core xeons at ~3ghz
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 02-01-2014 , 07:56   Re: In general, when should I use stock vs public vs [blank]
Reply With Quote #8

Quote:
Originally Posted by friagram View Post
use public for every function
new for every variable
IsValidClient in every loop

who needs parsimony in programming when you have 8+ core xeons at ~3ghz
Error: BIG FAIL detected
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 02-01-2014 , 14:19   Re: In general, when should I use stock vs public vs [blank]
Reply With Quote #9

Quote:
Originally Posted by friagram View Post
use public for every function
new for every variable
IsValidClient in every loop

who needs parsimony in programming when you have 8+ core xeons at ~3ghz
There is more than that to it, IsValidClient can die long ago, such a lazy horrible piece of code, making every possible CHECKS that most of them is impossible to happen in every piece of code.

Sourcemod is a scripting language, every single variable you create are using 32 bits and every NEW clear the whole memory for you. If you understand the difference between static, new, decl and dynamic array (YEA DYNAMIC ARRAYS YEA YEA YEA), it shouldnt slow you down and it will optimize the process of your plugin which can definitely affect the game performance.

It like valve saying, cs:go going to use 4 gb of ram per server and a total of 8 threads doing back ground work because we have today technology (lazy and/or don't have knowledge). Hope you understand that the price of the servers come with it since the point is to host as many server as you can on a 8+ core xeons.

Quote:
Originally Posted by berni View Post
Error: BIG FAIL detected
LOL

Last edited by Mathias.; 02-01-2014 at 14:29.
Mathias. is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 02-01-2014 , 14:25   Re: In general, when should I use stock vs public vs [blank]
Reply With Quote #10

Quote:
Originally Posted by berni View Post
Error: BIG FAIL detected
LOL

("But, can't Mantle optimize it?")
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode