Raised This Month: $ Target: $400
 0% 

[HELP] Fast or Readable?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 09-24-2016 , 05:06   [HELP] Fast or Readable?
Reply With Quote #1

Hello guys

If i have 1 function and want to write under statement, which one will be more faster ?

PHP Code:
if( .... )
set_user_health(1,1
OR

PHP Code:
if( .... )
{
set_user_health(1,1)

Ghosted is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-24-2016 , 05:25   Re: [HELP] Fast or Readable?
Reply With Quote #2

They are equal.
klippy is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 09-24-2016 , 09:03   Re: [HELP] Fast or Readable?
Reply With Quote #3

If you're using amx modx studio, i suggest you use the second one. This just because of the indenter build in amx mod x studio. The indenter will indent the second code properly, while your whole code get's fucked with the first structure.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
ESForces
Member
Join Date: Dec 2012
Location: Omniverse
Old 09-24-2016 , 12:31   Re: [HELP] Fast or Readable?
Reply With Quote #4

You can also...

PHP Code:
if(...){    set_user_health(11);} 
Or, in some cases...

PHP Code:
set_user_godmode(__int_Index, .godmode is_user_alive(__int_Index) ? 0); 
__________________
"The happy ends not exists, because the good stories never ends..."

Last edited by ESForces; 09-24-2016 at 12:36.
ESForces is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-24-2016 , 12:34   Re: [HELP] Fast or Readable?
Reply With Quote #5

Since we are talking about this

PHP Code:
number function1 : function 
I have a question, is there a way to do this without an else ? for example
PHP Code:
number ? function 
__________________

Last edited by Depresie; 09-24-2016 at 12:34.
Depresie is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-24-2016 , 12:44   Re: [HELP] Fast or Readable?
Reply With Quote #6

Quote:
Originally Posted by Depresie View Post
Since we are talking about this

PHP Code:
number function1 : function 
I have a question, is there a way to do this without an else ? for example
PHP Code:
number ? function 
I don't think it's worth it. Things like this are typically done by those that care about the number of lines in their plugin. The focus on code, IMO, should be efficient while also being easy to read and understand. Line count means nothing from a performance perspective and it's usually at the expensive of readability.

However, something like this is fine.
PHP Code:
set_user_healthid , ( iSomeValue == 34 ) ? 90 100 );

//instead of 

if ( iSomeValue == 34 )
    
set_user_healthid 90 );
else
    
set_user_healthid 100 ); 
__________________
Bugsy is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 09-24-2016 , 12:50   Re: [HELP] Fast or Readable?
Reply With Quote #7

Yes, there is no performance difference but, it's easier for me to read if there are less lines and braces and stuff and i don't have to scroll down and up so much... that is why i am asking

Using this
PHP Code:
blabla this 
instead of
PHP Code:
if(bla bla )
{
    
this

will save me some visual space and time
__________________

Last edited by Depresie; 09-24-2016 at 12:52.
Depresie is offline
ESForces
Member
Join Date: Dec 2012
Location: Omniverse
Old 09-24-2016 , 12:55   Re: [HELP] Fast or Readable?
Reply With Quote #8

This can not be done because it is a type of logical operator, and needs to return a value for both cases, however you can make multiple statements in a same line...

Indeed, if there is a difference in performance and optimization. On the other hand, you're looking for save space in lines of code writing.
__________________
"The happy ends not exists, because the good stories never ends..."

Last edited by ESForces; 09-24-2016 at 13:13.
ESForces is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-24-2016 , 12:56   Re: [HELP] Fast or Readable?
Reply With Quote #9

Quote:
Originally Posted by Depresie View Post
Yes, there is no performance difference but, it's easier for me to read if there are less lines and braces and stuff and i don't have to scroll down and up so much... that is why i am asking

Using this
PHP Code:
blabla this 
instead of
PHP Code:
if(bla bla )
{
    
this

will save me some visual space and time
That is your opinion and you can code however you want. I personally rather see if ( this ) then do this instead of asd ? func0() : asd2 ? func1() : asd3 ? func2() : func3(). This is a bit exaggerated but I'm just trying to make a point. Debugging this is a lot more annoying because it is not exactly clear when each function is being called unless you spend time evaluating it.
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-24-2016 , 14:06   Re: [HELP] Fast or Readable?
Reply With Quote #10

Quote:
Originally Posted by Depresie View Post
Yes, there is no performance difference but, it's easier for me to read if there are less lines and braces and stuff and i don't have to scroll down and up so much.
In my opinion, this would be a the typical response of an inexperienced coder. But in reality, as Bugsy said, you can do it however you want. If you want to do it so that it's not easily readable for others then that is technically fine.
__________________
fysiks is offline
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 09:32.


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