Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
Don't take vB's code as a model for perfect coding!
filburt1
Join Date: Feb 2002
Posts: 6,144

Maryland, US
by filburt1 filburt1 is offline 14 Mar 2003

Unlike rumors of vB3, vB2 has astetically horribly written code. Here are some things that you should do (and that vB doesn't always do):

1. When referencing a key in an array, always put the key in quotes. See http://www.php.net/manual/en/language.types.array.php for an explanation. For example, do this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Not this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

2. Whitespace is your friend. Use it. For example, this is painful to read:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

For the love of God, do this instead:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

For readability the two braces really should be on their own lines although many prefer to put the opening brace with the previous line. But do not do the same with the last brace as this can cause more trouble.

3. Indent or be smacked.
Bad:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Good:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If you write like the first example you'd be fired at your job. A side note: the typical editor uses four spaces or a tab character to indent. Try to keep this consistant! vB does not and can wreak havoc when trying to indent the standard four spaces because nothing will line up.


I'm sure many more examples are out there. Reply if you have any.
Views: 5265
Reply With Quote
Comments
  #2  
Old 15 Mar 2003, 01:26
Erwin's Avatar
Erwin Erwin is offline
 
Join Date: Jan 2002
Good advice from the turtle. Makes a difference especially when trying to debug errors.
Reply With Quote
  #3  
Old 15 Mar 2003, 09:16
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Real name: Chris Murphy, BSc
Yup...

Thanks for that

*Sues vB*

On a side note: I really wish I could change Erwin's spoiler message...

Satan
Reply With Quote
  #4  
Old 15 Mar 2003, 11:26
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Real name: Dean Clatworthy
Indeed. Good tips there burt !

- miSt
__________________
Dean Clatworthy - Web Developer/Designer
Reply With Quote
  #5  
Old 15 Mar 2003, 15:31
shovel's Avatar
shovel shovel is offline
 
Join Date: Mar 2002
Location: South Carolina, US
Real name: Anthony
I'm really hoping vB3 has followed the true professional PHP guidelines [like filbert has shown us]. If not, I don't know what I'd do. Lol.
Reply With Quote
  #6  
Old 15 Mar 2003, 16:06
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
having a look at the vb_test.php script on vB.com shows how the code is layed out in vB3.

http://www.vbulletin.com/forum/attac...achmentid=4326

I also posted a thread on vB3 syntax last year http://www.vbulletin.org/forum/showt...threadid=42946
__________________
Scott MacVicar
vBulletin Developer
Reply With Quote
  #7  
Old 15 Mar 2003, 17:36
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Today at 11:06 AM PPN said this in Post #6
having a look at the vb_test.php script on vB.com shows how the code is layed out in vB3.

http://www.vbulletin.com/forum/attac...achmentid=4326

I also posted a thread on vB3 syntax last year http://www.vbulletin.org/forum/showt...threadid=42946
Bad Request
Your browser sent a request that this server could not understand.


--------------------------------------------------------------------------------

Apache/1.3.27 Server at www.vbulletin.com Port 80
Although IIRC from reading the code I think you're right
Reply With Quote
  #8  
Old 16 Mar 2003, 01:49
shovel's Avatar
shovel shovel is offline
 
Join Date: Mar 2002
Location: South Carolina, US
Real name: Anthony
Today at 11:06 AM PPN said this in Post #6
having a look at the vb_test.php script on vB.com shows how the code is layed out in vB3.

http://www.vbulletin.com/forum/attac...achmentid=4326

I also posted a thread on vB3 syntax last year http://www.vbulletin.org/forum/showt...threadid=42946
Thanks PPN.
Reply With Quote
  #9  
Old 16 Mar 2003, 01:54
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Just looked at it again and it does look way better than vB2. Only problem is it's still using deprecated variables like $HTTP_POST_VARS (instead of $_POST or $_GET). Also I don't know why vB doesn't use the true and false keywords but instead uses 1 and 0 everywhere...
Reply With Quote
  #10  
Old 16 Mar 2003, 01:57
Freddie Bingham's Avatar
Freddie Bingham Freddie Bingham is offline
 
Join Date: Oct 2001
I don't see how you could have looked since you don't have the vB3 code but we only refer to $HTTP_POST_VARS when the server is running php < 4.1. You shouldn't base your assumptions on a test script that has to work on php 4.0.6 and greater.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

As for using TRUE/FALSE or 0/1 - we are using true/false more but just switched over so you will see both instances for now.

Last edited by freddie; 16 Mar 2003 at 02:00.
Reply With Quote
  #11  
Old 16 Mar 2003, 02:06
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Whoops, didn't see that bit.
Reply With Quote
  #12  
Old 16 Mar 2003, 10:44
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Real name: Dean Clatworthy
$_FILES = &$HTTP_POST_FILES;
Oh no ampersand when assigning variables. This is going to confuse me majorly as i still don't understand the concept

- miSt
__________________
Dean Clatworthy - Web Developer/Designer
Reply With Quote
  #13  
Old 16 Mar 2003, 13:07
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
ampersand means you are referncing the variables.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

basically you can change array and the values are reflected in $newarray.
__________________
Scott MacVicar
vBulletin Developer
Reply With Quote
  #14  
Old 16 Mar 2003, 13:09
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Real name: Dean Clatworthy
*Kinda understands*

- miSt
__________________
Dean Clatworthy - Web Developer/Designer
Reply With Quote
  #15  
Old 16 Mar 2003, 16:16
filburt1 filburt1 is offline
 
Join Date: Feb 2002
It's a pointer:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So any time you modify $a you modify $b.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

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


New To Site? Need Help?

All times are GMT. The time now is 10:50.

Layout Options | Width: Wide Color: