Raised This Month: $ Target: $400
 0% 

Whats the advantage of doing this?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
01101101
BANNED
Join Date: Nov 2009
Location: 9`su 09`n0n7e`r0f76a
Old 12-30-2009 , 14:38   Whats the advantage of doing this?
Reply With Quote #1

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.
01101101 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-30-2009 , 14:48   Re: Whats the advantage of doing this?
Reply With Quote #2

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.
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-30-2009 , 16:22   Re: Whats the advantage of doing this?
Reply With Quote #3

- if random_bullshit() is called by another function.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 12-30-2009 , 17:12   Re: Whats the advantage of doing this?
Reply With Quote #4

so public funcs called slower than non-public ones?
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
stupok
Veteran Member
Join Date: Feb 2006
Old 12-30-2009 , 20:35   Re: Whats the advantage of doing this?
Reply With Quote #5

No, there is no speed difference. The tag public is used because set_task() can only call functions that are labeled public.
__________________
stupok is offline
Mxnn
Veteran Member
Join Date: Aug 2009
Location: AT MY HOME
Old 12-30-2009 , 20:39   Re: Whats the advantage of doing this?
Reply With Quote #6

Is only for delay the task
Mxnn is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-30-2009 , 21:28   Re: Whats the advantage of doing this?
Reply With Quote #7

Quote:
Originally Posted by Mxnn View Post
Is only for delay the task
You don't understand the question.
__________________
fysiks is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 12-30-2009 , 21:38   Re: Whats the advantage of doing this?
Reply With Quote #8

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.
joaquimandrade is offline
01101101
BANNED
Join Date: Nov 2009
Location: 9`su 09`n0n7e`r0f76a
Old 12-30-2009 , 23:30   Re: Whats the advantage of doing this?
Reply With Quote #9

Ok thanks quim, so the only advantage is readability.
01101101 is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 12-31-2009 , 05:19   Re: Whats the advantage of doing this?
Reply With Quote #10

what if you just make all func public? anything gonna change?
__________________
☜ Free Mozy ☂backup\҉sync user
Quote:
Американский форум - Задаёшь вопрос, потом тебе отвечают.
Израильский форум - Задаёшь вопрос, потом тебе задают вопрос.
Русский форум - Задаёшь вопрос, потом тебе долго рассказывают, какой ты мудак.
Owyn is offline
Send a message via ICQ to Owyn
Reply



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 04:05.


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