SA-MP Forums Archive
What is more optimized? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What is more optimized? (/showthread.php?tid=606257)



What is more optimized? - DusanInfinity - 01.05.2016

If we have anything like this:

1st option:
Код:
if(blablabla) RemovePlayerFromVehicle(playerid), SendClientMessage(playerid, WHITE, "You dont have keys!");
2nd option:
Код:
if(blablabla) 
{
RemovePlayerFromVehicle(playerid);
SendClientMessage(playerid, WHITE, "You dont have keys!");
}
3rd option:
Код:
if( blablabla )  {
RemovePlayerFromVehicle( playerid );
SendClientMessage(playerid, WHITE, "You dont have keys!");
}
Which option is better?


Re: What is more optimized? - Nero_3D - 01.05.2016

I would say none, it is three times the same code just written differently


Re: What is more optimized? - kaisersouse - 01.05.2016

This isnt an optimization question, its a code readability one.

The middle, except with a tab starting each line between the { } brackets

Код:
if(blablabla) 
{
     RemovePlayerFromVehicle(playerid);
     SendClientMessage(playerid, WHITE, "You dont have keys!");
}



Re: What is more optimized? - Crayder - 01.05.2016

Ok if you want to get technical...

Number 1 is the most efficient here. Both the braces and the second ';' add "break"'s to the assembly.

However, both numbers 2 and 3 are more formal.

I address these in the Tiny Optimizations thread: https://sampforum.blast.hk/showthread.php?tid=606026

The speed difference that the breaks bring to the assembly are very negligible though. The major speed differences here are the functions themselves. You really don't need to worry about this, just do what fits your style best.


Re: What is more optimized? - Ritzy2K - 02.05.2016

I like the pretty printing one though.


Re: What is more optimized? - Abagail - 02.05.2016

You can also do this for further readability(in reference to option #1):
pawn Код:
if(blablabla)
      RemovePlayerFromVehicle(playerid), SendClientMessage(playerid, WHITE, "You dont have keys!");



Re: What is more optimized? - 036 - 02.05.2016

Quote:
Originally Posted by [ND]xXZeusXx.
Посмотреть сообщение
I like the pretty printing one though.
wtf go away


Re: What is more optimized? - introzen - 02.05.2016

I prefer option 3 with indentation.


Re: What is more optimized? - DusanInfinity - 02.05.2016

Thank you all