Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

General Discussions


You are currently viewing our General Discussions as a guest. Please register to participate.
Login



Reply
White space in code - what's "right"?
Old 02-13-2008, 03:06 PM White space in code - what's "right"?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
I know, there's a coding forum. There's also an ASP, PHP, and even database (also known as SQL) forum. I'm not interested in any particular programming language. And since this is a web site that attracts people with tech knowledge, I think we've all done a bit of coding.

So I'm curious what your own rules and best practices are for white space in your code?

A coworker told me a single blank line between blocks of code is a life saver, but two or more blank lines should never be used. He says it's bad form and glosses over bigger structural problems. Personally, I like to break up a big chunk of code into smaller related bits, and use a blank line or even 2 or 3 depending on just how related they are. I don't think it makes sense to break something out into a new method unless it's actually used in several places - functions are for shared functionality, not for organization.

I save the files with my tabs as spaces, so if someone opens a code file but their tab size is set to 8, they can still read my code.

I use 3 spaces in a tab. And I use "smart indenting" which I think since .NET came along, everybody else does. When you go into a control flow block (if, while, do, all that), that block should be indented.

So what are your rules?
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-13-2008, 10:25 PM Re: White space in code - what's "right"?
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
I can't stand code with spaces instead of tabs. That's the whole point to setting tab spacing ... leave the fact that something has been indented in the file, but leave it up to the client to do the indenting according to the end user's taste.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-14-2008, 01:54 AM Re: White space in code - what's "right"?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Me either. If their tab size is set too large, then nuts to 'em.

My rule is this: one line of blank space between any sub or function. Tabs for indents. And I'm good to go.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-14-2008, 04:39 AM Re: White space in code - what's "right"?
Mooofasa's Avatar
Defies a Status

Posts: 1,611
Name: Michael (mik) Land
Location: England
Trades: 0
I'm a comment whore with PHP (and was with VB).

As for white space, I use the following.
Code:
a (b()) {
  c (d()) {
    e ...
  }
  
  f (g()) {
    h ...
  }
}
__________________

Please login or register to view this content. Registration is FREE
- Tumblog with thoughts, quotes, links, videos, images and my creations.

Please login or register to view this content. Registration is FREE
- The best free web browser.

Please login or register to view this content. Registration is FREE
- Firefox is now Firefail.
Mooofasa is offline
Reply With Quote
View Public Profile Visit Mooofasa's homepage!
 
Old 02-15-2008, 01:47 PM Re: White space in code - what's "right"?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Wow, Moofster - do you do any LISP or F# coding? You look like you have set theory down.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-15-2008, 05:19 PM Re: White space in code - what's "right"?
Mattmaul1992's Avatar
Ultra Talker

Posts: 486
Name: Matt
Trades: -1
I use tabs and lots of blank lines.. I just really don't see how one blank line is going to screw up the program. I mean it makes it easier to read and doesn't affect the program so how could it be bad? I like to separate my programs into sections and each type of section is separated by a certain number of lines. If I don't do this I make big comments for each section like -
PHP Code:
//--------------------------------------+
// NEWS - Add Post
//--------------------------------------+ 
I think that's the best way to do it..
__________________
PHP Code:
$talkupation++; 

Please login or register to view this content. Registration is FREE
- Free IPB forum hosting (releasing today!!!), no ads, free modifications
Mattmaul1992 is offline
Reply With Quote
View Public Profile
 
Old 02-15-2008, 10:16 PM Re: White space in code - what's "right"?
joder's Avatar
Flipotron

Posts: 6,442
Name: James
Location: In the ocean.
Trades: 0
I use spaces for tabs and 4 space indent. 1 blank line between sections.
joder is offline
Reply With Quote
View Public Profile
 
Old 02-16-2008, 12:07 AM Re: White space in code - what's "right"?
serandfae's Avatar
Do the "Evil Nanner" !!!

Posts: 9,007
Name: Tim Daily
Location: Apex, NC, US, Sol 3
Trades: 0
I use tabs, and use one comment line between sections. Makes it a lot easier should I need to update or base something new from old. But that's if I'm feeling industrious.
__________________
SEO "experts" smell like Big Fish_|_
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

serandfae is offline
Reply With Quote
View Public Profile Visit serandfae's homepage!
 
Old 02-16-2008, 10:15 AM Re: White space in code - what's "right"?
cbwm's Avatar
Mr. Wonderful

Posts: 1,434
Name: Weboholic
Trades: 0
Isn't coding style, spacing included, client depedent? If they pay well, and are likely to bring you back:

// *********************************
// Function: someFunction
// Description: Does something complicated with the customer name
// Return Value: (String) Newly Modified Customer Name
// *********************************
function someFunction(
string sCustomerName, // The customer's name
int iOtherArgument, // Description of other Argument
int iYetAnotherArgument)// Description of this Argument
{
// Parse customer name into first and last
string sCustomerFirstName = left(sCustomerName, pos(sCustomerName," ");
..
..

// Some other comment
someOtherVar= someOtherFunction(sCustomerFirstName);

..
return someOtherVar;
}

// *********************************
// Function: someOtherFunction
// Description: Does something with its argument
// Return Value: (vartype) description of the return value
// *********************************
function someOtherFunction(
vartype vtDescriptiveVarName, // comment describing argument
vartype vtDescriptiveVarName2, // comment describing argument
{
// Comment describing code block
..
..

// Some other descriptive code blockcomment
someOtherVar= yetAnotherFunction(vtSomeVar);
..

return someOtherVar;

}


On the other hand, if the contract is low paying( or extremely high paying and the contractor is a pr*ck who just wants you in and out ASAP), something like this might be more appropriate:

function sF( string sCName, int iOA,int iYAA)
{
return sOF(left(sCN,pos(sCN," ")..);
}
function sOF(vartype vtNDVN,vartype vtNDVN2)
{
..;..;return yAF( vtNDVN);
}

Spacing and comments are really for the maintenance programmer, not the original author.
__________________

Please login or register to view this content. Registration is FREE
Free Directory Quality Relevant Content - No Backlinks required!

Last edited by cbwm; 02-16-2008 at 10:16 AM..
cbwm is offline
Reply With Quote
View Public Profile
 
Old 02-16-2008, 11:13 AM Re: White space in code - what's "right"?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I personally use spaces, as that when I use to access my files remotely, vim messes my files completely.
And I never bothered searching the command to adjust the tab/spaces value.


PHP Code:
$variable="test";
if(
true){
  
//...
}
else{
  
//...
}

switch(
$var){
  case 
'1':
    
//...
    
break;
  case 
'2':
  default:
    
//...
    
break;
}
class 
clSomething(){
  private 
$var;

  public function 
__construct($var){
    
//...
  
}
  
  private function 
_priv(){
    return 
false;
  }

__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-16-2008 at 11:14 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-17-2008, 03:04 PM Re: White space in code - what's "right"?
joder's Avatar
Flipotron

Posts: 6,442
Name: James
Location: In the ocean.
Trades: 0
Quote:
Originally Posted by tripy View Post
I personally use spaces, as that when I use to access my files remotely, vim messes my files completely.
And I never bothered searching the command to adjust the tab/spaces value.
This is what is in my .vimrc
Code:
set tabstop=4
set shiftwidth=4
set expandtab

set et
set sw=4
set smarttab
joder is offline
Reply With Quote
View Public Profile
 
Old 02-17-2008, 05:00 PM Re: White space in code - what's "right"?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Thank you James.
Now, I just have to replicate this through every instances of vim I could use...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to White space in code - what's "right"?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.95033 seconds with 12 queries