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

Odd SourcePawn "feature"?


Post New Thread Reply   
 
Thread Tools Display Modes
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 03-13-2012 , 12:38   Re: Odd SourcePawn "feature"?
Reply With Quote #11

I just read through that coding style and I've worked my way through all of those bad habits - I still need to work on 2 or so areas of style, but I went through the no brackets around single statement if junk... I'm back to using brackets on all
__________________
View my Plugins | Donate
TnTSCS is offline
Thrawn2
Veteran Member
Join Date: Apr 2009
Old 03-13-2012 , 14:13   Re: Odd SourcePawn "feature"?
Reply With Quote #12

i don't really see how
PHP Code:
    if (gaben)
    {
        
hello
    

has a better readability than
PHP Code:
    if (gaben) {
        
hello
    

i would argue the other way around tbh. and it's usually the first thing i 'fix' about code i get my hands on.
would really like an explanation why it's better so i have a motivation to get rid of this ocd.

completely agree on all the other stuff.
__________________
einmal mit profis arbeiten. einmal.

Last edited by Thrawn2; 03-13-2012 at 14:13.
Thrawn2 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-13-2012 , 15:16   Re: Odd SourcePawn "feature"?
Reply With Quote #13

Quote:
Originally Posted by Thrawn2 View Post
i would argue the other way around tbh. and it's usually the first thing i 'fix' about code i get my hands on.
would really like an explanation why it's better so i have a motivation to get rid of this ocd.

completely agree on all the other stuff.
PHP Code:
if (gaben1
 
|| gaben2
 
|| gaben3
 
|| gaben4) {
    
gaben5

PHP Code:
if (gaben1
 
|| gaben2
 
|| gaben3
 
|| gaben4)
{
    
gaben5

__________________

Last edited by asherkin; 03-13-2012 at 15:16.
asherkin is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 03-13-2012 , 15:27   Re: Odd SourcePawn "feature"?
Reply With Quote #14

Quote:
Originally Posted by Lord Canistra View Post
Nah, real beginners always write brackets since they don't know those aren't always required.
This is true. I started out with PHP, and I didn't know that the brackets weren't always required. Then I found out that they're not required, tried it out a little bit, and didn't like it. So I always use brackets.

But I do put the opening brace on the same line as the if (mainly because that's how the PHP people do it [check out the examples section]).
__________________
Dr. McKay is offline
napalm00
Veteran Member
Join Date: Jun 2011
Location: Italy, sadly
Old 03-13-2012 , 15:30   Re: Odd SourcePawn "feature"?
Reply With Quote #15

The "all-in-one-line" structure
PHP Code:
if(gaben) { 
was mainly used in the past from the "oldschool" programmers, back in the days when they had screens/text editors with only a few rows, so as you can see writing the open bracket on the same line would help saving some space.
Nowadays we have giant screens and text editors with plenty of lines, so that structure is not used that often anymore.
__________________

Last edited by napalm00; 03-13-2012 at 15:34.
napalm00 is offline
Dreamy
SourceMod Donor
Join Date: Mar 2012
Old 03-13-2012 , 18:04   Re: Odd SourcePawn "feature"?
Reply With Quote #16

any experienced coder would say that:
PHP Code:
if (b)
    
1
is way better than
PHP Code:
if (b)
{
    
1;

since you save 2 lines for >no< readability costs! while writing those brackets (+other habits like those) easily add up in a big program to 50-100 extra lines.

while:
PHP Code:
if (b) {
    
1;

is just an ugly exuse between both. (dunno why, but i see this phenomenon only in java code)

Well in the end brackets dont have ANY impact on the execution time of the program.
So its just a matter of taste afterall...

Last edited by Dreamy; 03-13-2012 at 18:09.
Dreamy is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 03-13-2012 , 18:06   Re: Odd SourcePawn "feature"?
Reply With Quote #17

Quote:
Originally Posted by Dreamy View Post
any experienced coder would say that:
PHP Code:
if (b)
    
1
is way better than
PHP Code:
if (b)
{
    
1;

since you save 2 lines for >no< readability costs! while writing those brackets (+other habits like those) easily add up in a big program to 50-100 extra lines.

while:
PHP Code:
if (b) {
    
1;

is just an ugly exuse between both. (dunno why, but i see this phenomenon only in java code)
Until you happen to need to add another line in your if statement. Who cares how many lines it takes? The compiled program is the same either way.

And "ugly" is a subjective term.
__________________
Dr. McKay is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-13-2012 , 18:09   Re: Odd SourcePawn "feature"?
Reply With Quote #18

Quote:
Originally Posted by Dreamy View Post
any experienced coder would say
Hi. No.
__________________
asherkin is offline
Dreamy
SourceMod Donor
Join Date: Mar 2012
Old 03-13-2012 , 18:29   Re: Odd SourcePawn "feature"?
Reply With Quote #19

PHP Code:
if (Condition)
   if (
otherCondition)
      
callSomething();
   else
      if (
yetAnotherCondition)
         
callSomethingElse(); 
PHP Code:
if (Condition)
{
   if (
otherCondition)
   {
      
callSomething();
   }
   else
   {
      if (
yetAnotherCondition)
      {
          
callSomethingElse();
      }
   }

PHP Code:
if (Condition) {
   if (
otherCondition) {
      
callSomething();
   }
   else {
      if (
yetAnotherCondition) {
          
callSomethingElse();
      }
   }

which one did you read the fastest? Be honest!
And for asherkin: rephrase -> MOST experienced coders would say...

Last edited by Dreamy; 03-13-2012 at 18:42.
Dreamy is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-13-2012 , 18:47   Re: Odd SourcePawn "feature"?
Reply With Quote #20

Quote:
Originally Posted by Dreamy View Post
which one did you read the fastest? Be honest!
The middle one, seriously, since I could just glance over it and see what was conditions.
EDIT: While the examples were all single line condition -> single line block, you need to look at multi-line examples for the real benefit. See my previous post.

Personally, I prefer the last one however.
__________________

Last edited by asherkin; 03-13-2012 at 18:48.
asherkin 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 20:32.


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