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

The perfect if else statement doesn’t exis..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 11-25-2023 , 10:06   The perfect if else statement doesn’t exis..
Reply With Quote #1



This thread should be locked and pinned @ Tutorials
__________________
Jhob94 is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 12-01-2023 , 13:08   Re: The perfect if else statement doesn’t exis..
Reply With Quote #2

while (is_user_alive(id)) hit(id, id1)
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-02-2023 , 14:01   Re: The perfect if else statement doesn’t exis..
Reply With Quote #3

Perfect
PHP Code:
if ( something 
{
}
else
{

Not perfect
PHP Code:
if ( something ) {
}
else {

__________________
Bugsy is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 12-02-2023 , 14:17   Re: The perfect if else statement doesn’t exis..
Reply With Quote #4

Quote:
Originally Posted by Bugsy View Post
Perfect
PHP Code:
if ( something 
{
}
else
{

Not perfect
PHP Code:
if ( something ) {
}
else {

Your first statement, without spaces. Personally I find it harder to read and takes more time to type it. On a big plugin it will make the difference if you are running against time.
__________________
Jhob94 is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 12-02-2023 , 14:28   Re: The perfect if else statement doesn’t exis..
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
Perfect
PHP Code:
if ( something 
{
}
else
{

Not perfect
PHP Code:
if ( something ) {
}
else {

Agreed. But for some reason when I write in php or javascript I always do the second way... my brain changes the style when I write in any other language that is not PAWN.

Quote:
Originally Posted by Jhob94 View Post
Your first statement, without spaces. Personally I find it harder to read and takes more time to type it. On a big plugin it will make the difference if you are running against time.
Everybody has their own style but the goal is always trying to make your code as easy to read as possible. That is a good practice even for you to debug and find possible issues with the code, specially if it is or will be an open source in the future.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 12-02-2023 at 14:31.
EFFx is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 12-02-2023 , 17:15   Re: The perfect if else statement doesn’t exis..
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
Perfect
PHP Code:
if ( something 
{
}
else
{

Not perfect
PHP Code:
if ( something ) {
}
else {

+++ Minus the spaces inside the condition 😁
__________________
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
WATCH_D0GS UNITED
Senior Member
Join Date: Jan 2023
Old 12-02-2023 , 19:52   Re: The perfect if else statement doesn’t exis..
Reply With Quote #7

This entire thread has been disproved with a single line of code:

? :
WATCH_D0GS UNITED is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-02-2023 , 23:40   Re: The perfect if else statement doesn’t exis..
Reply With Quote #8

Quote:
Originally Posted by Jhob94 View Post
Your first statement, without spaces. Personally I find it harder to read and takes more time to type it. On a big plugin it will make the difference if you are running against time.
Yeah, I started padding with spaces years ago, I find it cleaner but everyone has their own preference.

It's harder to read and more time to type when you have the opening bracket on its own line, or the spaces? I hate looking at code that is all compacted together -- the spaces make it easier for me to read, and the time difference is negligible once you're used to it.

Quote:
Originally Posted by WATCH_D0GS UNITED View Post
This entire thread has been disproved with a single line of code:

? :
Yes and no. Ternary conditions should only be used when appropriate, not as a replacement for all if-else conditions. The goal/intent of using them should not be to reduce the number of lines of code.
__________________
Bugsy is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 12-03-2023 , 08:07   Re: The perfect if else statement doesn’t exis..
Reply With Quote #9

PHP Code:
    if(..)
        
//..
    
else
        
//.. 
at first I thought that simplifying the code would "improve" it in some way, but the truth is that it doesn't. is the same. so now I simply try to respect coerence by making the code more readable; can you imagine making a zp in a single line, what happens if it generates an error. good luck finding it.
__________________
mlibre is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 12-03-2023 , 08:33   Re: The perfect if else statement doesn’t exis..
Reply With Quote #10

Quote:
Originally Posted by mlibre View Post
PHP Code:
    if(..)
        
//..
    
else
        
//.. 
at first I thought that simplifying the code would "improve" it in some way, but the truth is that it doesn't. is the same. so now I simply try to respect coerence by making the code more readable; can you imagine making a zp in a single line, what happens if it generates an error. good luck finding it.
It’s all about organization. I usually make private functions to reduce the amount of code, specially when it’s duplicated code. A lot of code, even if readable will make it harder. As long as you organize well the code and give proper names to stuff it becomes easy.
__________________
Jhob94 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 10:52.


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