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

[TUT] Code Styling & Good Programming Habits


Post New Thread Reply   
 
Thread Tools Display Modes
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 01-16-2010 , 13:01   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #41

Yes, I do, here's a sample:
PHP Code:
main() {
    new 
barbaz 29;

    for (new 
0bazi++) {
        
bar *= baz i;
    }

    new 
arr[32];

    
foo(barbazarrarr);
}

public 
foo(abc[], d[32]) {
    
assert((sizeof(c)-1) > 0);

    switch(
a) {
        case 
1: {
            
+= 10;
        }

        case 
2: {
            
+= 13;
        }

        default: {
            
-= 2;
        }
    }

    if (
0) {
        
abs(b) + a;
    } else {
        
-= a;
    }

    
c[0] = / (d[12] - d[10]);
    return 
d[31];

To make it simple: I use K&R convention, with one exception: function's starting bracket in the same line of the function signature.

Last edited by Seta00; 01-16-2010 at 13:04.
Seta00 is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 01-16-2010 , 13:18   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #42

I'm with Bugsy on this but you two won't reach nothing with the discussion because none of the styles can be proved to be better.
joaquimandrade is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-16-2010 , 13:22   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #43

if youre going to put the opening bracket on the same opening line why not put the closing bracket after the last line of code. consistency is what im getting at
__________________
Bugsy is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 01-16-2010 , 13:47   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #44

Quote:
Originally Posted by Bugsy View Post
if youre going to put the opening bracket on the same opening line why not put the closing bracket after the last line of code. consistency is what im getting at
Quote:
Originally Posted by Seta00 View Post
But, in the other hand, you can't predict when the code block will end, that's the reason to put the closing bracket alone in one line.
Readability before consistency.
Seta00 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-16-2010 , 14:02   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #45

lol not worth arguing with you. this is a matter of opinion.
__________________
Bugsy is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 01-16-2010 , 14:47   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #46

I know this discussion wont end, I'm just exposing my opinion over the tutorial. I think styling guidelines shouldn't be recommended, you just post links to all of them and let the programmer decide which one he will use.
Seta00 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-16-2010 , 16:14   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #47

Quote:
Originally Posted by Seta00 View Post
More code fitting in the page is for consistency, is way better to have functions that fit in one page, so you don't need to scroll up and down following the execution path.
lol

Quote:
Originally Posted by Seta00 View Post
I think styling guidelines shouldn't be recommended
People can decide if they like the recommendation and choose to use or not use it.
__________________
fysiks is offline
minimiller
Veteran Member
Join Date: Aug 2007
Location: United Kingdom
Old 01-16-2010 , 16:24   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #48

Quote:
Originally Posted by Seta00 View Post
Nice tut, only thing I disagree is with the new line before opening bracket.
If you're a programmer, you can easily recognize identifiers that imply a code block, and the new lines before every block allow for less code to fit in one page.
wtf pages!?!
u using ms word or some shit?
__________________
minimiller is offline
Send a message via MSN to minimiller
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-16-2010 , 16:26   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #49

Quote:
Originally Posted by minimiller View Post
wtf pages!?!
u using ms word or some shit?
Seriously... I don't think "number of lines you can see on a page" should be a deciding factor for the format of code.
__________________
Bugsy is offline
ehha
SourceMod Donor
Join Date: Apr 2006
Location: Sibiu
Old 01-16-2010 , 18:30   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #50

Quote:
Originally Posted by Bugsy View Post
PHP Code:
public Uglyid ) {

}

public 
Niceid )
{


Here's why I agree on this, if you wanna do a quick eye search on a code block, it's just* a vertical swoop & you're done.

*and it looks better
__________________
ehha 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 00:37.


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