AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Off-Topic (https://forums.alliedmods.net/forumdisplay.php?f=15)
-   -   The perfect if else statement doesn’t exis.. (https://forums.alliedmods.net/showthread.php?t=344657)

Jhob94 11-25-2023 10:06

The perfect if else statement doesn’t exis..
 
https://i.ibb.co/K7x5tGD/5-E8-AA285-...324-F0-A21.jpg

This thread should be locked and pinned @ Tutorials :lol:

georgik57 12-01-2023 13:08

Re: The perfect if else statement doesn’t exis..
 
while (is_user_alive(id)) hit(id, id1)

Bugsy 12-02-2023 14:01

Re: The perfect if else statement doesn’t exis..
 
Perfect
PHP Code:

if ( something 
{
}
else
{


Not perfect
PHP Code:

if ( something ) {
}
else {



Jhob94 12-02-2023 14:17

Re: The perfect if else statement doesn’t exis..
 
Quote:

Originally Posted by Bugsy (Post 2813853)
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.

EFFx 12-02-2023 14:28

Re: The perfect if else statement doesn’t exis..
 
Quote:

Originally Posted by Bugsy (Post 2813853)
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 (Post 2813854)
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.

georgik57 12-02-2023 17:15

Re: The perfect if else statement doesn’t exis..
 
Quote:

Originally Posted by Bugsy (Post 2813853)
Perfect
PHP Code:

if ( something 
{
}
else
{


Not perfect
PHP Code:

if ( something ) {
}
else {



+++ Minus the spaces inside the condition 😁

WATCH_D0GS UNITED 12-02-2023 19:52

Re: The perfect if else statement doesn’t exis..
 
This entire thread has been disproved with a single line of code:

:twisted: ? :twisted: : :twisted:

Bugsy 12-02-2023 23:40

Re: The perfect if else statement doesn’t exis..
 
Quote:

Originally Posted by Jhob94 (Post 2813854)
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 (Post 2813873)
This entire thread has been disproved with a single line of code:

:twisted: ? :twisted: : :twisted:

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.

mlibre 12-03-2023 08:07

Re: The perfect if else statement doesn’t exis..
 
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.

Jhob94 12-03-2023 08:33

Re: The perfect if else statement doesn’t exis..
 
Quote:

Originally Posted by mlibre (Post 2813902)
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.


All times are GMT -4. The time now is 09:52.

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