This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

[TUT] Code Styling & Good Programming Habits


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Spunky
Senior Member
Join Date: May 2008
Location: Orlando, Fl.
Old 02-23-2009 , 02:17   Re: [TUT] Code Styling
Reply With Quote #1

Switching about every two weeks can throw you off though. I program in C++ for two weeks, then switch to Pawn for two weeks, then switch back. It's not easy because I usually forget like half of what I learned about AMXX (since that's the only thing I would ever use such a painfully simple language like Pawn for) the last time around when I finally come back, even down to basic stuff. x_x
Spunky is offline
Send a message via AIM to Spunky
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 09-14-2009 , 10:43   Re: [TUT] Code Styling
Reply With Quote #2

I finally got around to writing a plugin that uses this style. You can see it here:
http://forums.alliedmods.net/showthread.php?t=102839

I also added it to the conclusion.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 01-06-2010 , 01:52   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #3

Thanks!
GordonFreeman (RU) is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 01-15-2010 , 10:06   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #4

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.
Seta00 is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 01-15-2010 , 15:22   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #5

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.
Your reasoning is just unbelievable. If you wanted to have all the code in one line you could, but that's not you want. You want the code to look decent, readable and not ugly and that's why you line break. As simple as that.

Hawk, this is a sticky thread and a lot of people read this, so better to fix.
PHP Code:
#define MyNewIsUserAlive( %1 ) is_user_alive( %1 ) 
SnoW is offline
Send a message via MSN to SnoW
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 01-16-2010 , 00:59   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #6

Quote:
Originally Posted by SnoW View Post
Your reasoning is just unbelievable. If you wanted to have all the code in one line you could, but that's not you want. You want the code to look decent, readable and not ugly and that's why you line break. As simple as that.

Hawk, this is a sticky thread and a lot of people read this, so better to fix.
PHP Code:
#define MyNewIsUserAlive( %1 ) is_user_alive( %1 ) 
Fixed, thanks.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 01-16-2010 , 12:27   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #7

Quote:
Originally Posted by SnoW View Post
Your reasoning is just unbelievable. If you wanted to have all the code in one line you could, but that's not you want. You want the code to look decent, readable and not ugly and that's why you line break. As simple as that.
You didn't understand what I mean, I don't want 1-line code.

Quote:
Originally Posted by Bugsy View Post
Readability is far more important than line count. If you are worried about fitting more code on one page, reduce your font size . Furthermore, code looks ugly when there's not a new-line before an opening bracket. Yes, I can look at any code and still know what is going on but it is a hell of a lot easier to read with proper line-breaks, spacing, and indentation.
Having the opening bracket in the same line of the "code block starter" statement doesn't interfer with readability. Think of you reading some code, when you see an "if" or a "do" or a "while" or anything that imply a code block, you already know that there's a code block coming, and indentation makes that more explicit. 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. 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.
Seta00 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-16-2010 , 12:50   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #8

Quote:
Originally Posted by Seta00 View Post
You didn't understand what I mean, I don't want 1-line code.

Having the opening bracket in the same line of the "code block starter" statement doesn't interfer with readability. Think of you reading some code, when you see an "if" or a "do" or a "while" or anything that imply a code block, you already know that there's a code block coming, and indentation makes that more explicit. 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. 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.
You can explain it to me any way you want, I personally think putting the opening bracket on a new line looks much nicer. Do you put an opening bracket on the same line as a for loop and a switch too?

PHP Code:
for ( new i++ ) {

switch ( 
Val ) { 
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-15-2010 , 21:55   Re: [TUT] Code Styling & Good Programming Habits
Reply With Quote #9

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.
Readability is far more important than line count. If you are worried about fitting more code on one page, reduce your font size . Furthermore, code looks ugly when there's not a new-line before an opening bracket. Yes, I can look at any code and still know what is going on but it is a hell of a lot easier to read with proper line-breaks, spacing, and indentation.


PHP Code:
public Uglyid ) {

}

public 
Niceid )
{


__________________
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 #10

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 20:42.


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