Raised This Month: $ Target: $400
 0% 

wtf does this mean?


Post New Thread Reply   
 
Thread Tools Display Modes
nergal
Veteran Member
Join Date: Apr 2012
Old 03-18-2014 , 17:49   Re: wtf does this mean?
Reply With Quote #21

Quote:
Originally Posted by rhelgeby View Post
I would avoid nesting them, use if-statements in this case (or perhaps a switch-statement). Code readability is more important than saving some lines.
but but but but my laziness implores me to just nest 'em so that i don't have to hit TAB a million times.
__________________
nergal is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 03-18-2014 , 18:44   Re: wtf does this mean?
Reply With Quote #22

Quote:
Originally Posted by rhelgeby View Post
I would avoid nesting them, use if-statements in this case (or perhaps a switch-statement). Code readability is more important than saving some lines.
Switch
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 03-19-2014 , 01:30   Re: wtf does this mean?
Reply With Quote #23

Lazy programmers may be haunted by their own code when someone ask for a new feature that apparently isn't that easy to implement - due to code that's hard to read or understand.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
nergal
Veteran Member
Join Date: Apr 2012
Old 03-19-2014 , 06:04   Re: wtf does this mean?
Reply With Quote #24

Quote:
Originally Posted by rhelgeby View Post
Lazy programmers may be haunted by their own code when someone ask for a new feature that apparently isn't that easy to implement - due to code that's hard to read or understand.
What if I format it to be readable?

PHP Code:
public MenuHandler_SetLulz(Handle:menuMenuAction:actionclientparam2

    
decl String:menuitem[64]; 
    new 
int
    
GetMenuItem(menuparam2menuitemsizeof(menuitem)); 
    if (
action == MenuAction_Select
        { 
                
param2++; 
                
int = (param2 == 1) ? :
                       ((
param2 == 2) ? 
                       ((
param2 == 3) ? 
                       
0));

                
PrintNumber(clientint); 
    } 
    else if (
action == MenuAction_End
        { 
        
CloseHandle(menu); 
    } 

__________________

Last edited by nergal; 03-19-2014 at 06:20.
nergal is offline
hamza47sohail
Senior Member
Join Date: Jan 2014
Old 03-19-2014 , 12:59   Re: wtf does this mean?
Reply With Quote #25

Quote:
Originally Posted by nergal View Post
What if I format it to be readable?

PHP Code:
public MenuHandler_SetLulz(Handle:menuMenuAction:actionclientparam2

    
decl String:menuitem[64]; 
    new 
int
    
GetMenuItem(menuparam2menuitemsizeof(menuitem)); 
    if (
action == MenuAction_Select
        { 
                
param2++; 
                
int = (param2 == 1) ? :
                       ((
param2 == 2) ? 
                       ((
param2 == 3) ? 
                       
0));

                
PrintNumber(clientint); 
    } 
    else if (
action == MenuAction_End
        { 
        
CloseHandle(menu); 
    } 

"Procrastination is just like masturbating sure it feels good. But in the end you are only fu*king yourself." - SourceBans.

Last edited by hamza47sohail; 03-19-2014 at 13:00.
hamza47sohail is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-19-2014 , 13:13   Re: wtf does this mean?
Reply With Quote #26

Which is easier to read? Which is easier to update?

PHP Code:
                   int = (param2 == 1) ? :
                       ((
param2 == 2) ? 
                       ((
param2 == 3) ? 
                       
0)); 
or
PHP Code:
                   switch(param2) {
                       case 
1int 1;
                       case 
2int 2;
                       case 
3int 3;
                       default: 
int 0;
                   } 
(the obvious answer is one of these, but the above two are there for arguments sake)
PHP Code:
                   int = (param2 >= && param2 <= 3) ? param2 0
PHP Code:
                   switch(param2) {
                       case 
123int param2;
                       default: 
int 0;
                   } 
Now, if you want multiple statements per case, you end up having to put in more { } pairs, which afact is a quirk of Pawn as its the only language I've seen that needs them. Probably has to do with not using break in case statements in Pawn.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-19-2014 at 13:18.
Powerlord 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 11:38.


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