AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Whats the advantage of doing this? (https://forums.alliedmods.net/showthread.php?t=113843)

01101101 12-30-2009 14:38

Whats the advantage of doing this?
 
PHP Code:

set_task(9999.0"random_shit")

public 
random_shit()
{
   
random_bullshit()
}

random_bullshit()
{
//all the code goes here


I saw that (using tasks in that way, the public calling the private function) in many plugins, but I don't get which is the advantage of doing that.

Arkshine 12-30-2009 14:48

Re: Whats the advantage of doing this?
 
Only that, there is no advantage.

But if you have a lot of code, grouping in functions, I see 2 advantages :

- More readable. You have a main function, then subfonctions grouped intelligently. You can understand better and have a better view what does the main function. ( Too many subfunctions could do the opposite effect )
- More easy to debug. In case of bugs, you will find more fastly the problem if you need to debug the main function since you can debug each subfunctions.

ConnorMcLeod 12-30-2009 16:22

Re: Whats the advantage of doing this?
 
- if random_bullshit() is called by another function.

Owyn 12-30-2009 17:12

Re: Whats the advantage of doing this?
 
so public funcs called slower than non-public ones?

stupok 12-30-2009 20:35

Re: Whats the advantage of doing this?
 
No, there is no speed difference. The tag public is used because set_task() can only call functions that are labeled public.

Mxnn 12-30-2009 20:39

Re: Whats the advantage of doing this?
 
Is only for delay the task

fysiks 12-30-2009 21:28

Re: Whats the advantage of doing this?
 
Quote:

Originally Posted by Mxnn (Post 1037140)
Is only for delay the task

You don't understand the question.

joaquimandrade 12-30-2009 21:38

Re: Whats the advantage of doing this?
 
What he is asking is if bridging a task to a function without the public modifier is an advantage. And the answer is: yes if you pass parameters so is visually nice to pass them as arguments to another function.

01101101 12-30-2009 23:30

Re: Whats the advantage of doing this?
 
Ok thanks quim, so the only advantage is readability.

Owyn 12-31-2009 05:19

Re: Whats the advantage of doing this?
 
what if you just make all func public? anything gonna change?


All times are GMT -4. The time now is 04:05.

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