Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Industry coding standards
filburt1
Join Date: Feb 2002
Posts: 6,144

 

Maryland, US
Show Printable Version Email this Page Subscription
filburt1 filburt1 is offline 04-26-2003, 10:00 PM

Half of these are from NASA's Java style guide that I use at work(http://aaa.gsfc.nasa.gov/Files/JavaFinal.doc).

1. Use whitespace liberally for readability:
Wrong:
PHP Code:
if($somevar==aconstant){dothis();dothat();} 
Right:
PHP Code:
if ($somevar == aconstant)
{
    
dothis();
    
dothat();

2. Braces on newlines:
PHP Code:
if ($result) {
    
dowhatever();

Right:
PHP Code:
if ($result)
{
    
dowhatever();

(this might not look important but in big files it greatly helps)

3. Don't exceed 80 chars per line (for code printing and reading on low-res and effectively-low-res environments). No example because it'll break the layout here, but if a line exceeds 80 chars, break it up a bit before 80, and then continue it on the next line while indenting one tab (NASA suggests two tabs but it can make the code very messy).

4. Use a 4-space (not a tab character) indent.
Wrong (right from vB2...):
PHP Code:
if ($HTTP_POST_VARS['action']=="doupload") {

  if (
$HTTP_POST_FILES['avatarfile']) {
    
$avatarfile $HTTP_POST_FILES['avatarfile']['tmp_name'];
    
$avatarfile_name $HTTP_POST_FILES['avatarfile']['name'];
  }
  
copy("$avatarfile","../$avatarpath/$avatarfile_name");

  
$avatarpath.="/$avatarfile_name";

  echo 
"<p>avatar successfuly uploaded</p>";

  
$HTTP_POST_VARS['action']="insert";

Right:
PHP Code:
if ($HTTP_POST_VARS['action'] == "doupload")
{
    if (
$HTTP_POST_FILES['avatarfile'])
    {
        
$avatarfile $HTTP_POST_FILES['avatarfile']['tmp_name'];
        
$avatarfile_name $HTTP_POST_FILES['avatarfile']['name'];
    }
    
copy("$avatarfile","../$avatarpath/$avatarfile_name");
    
    
$avatarpath .= "/$avatarfile_name";
    echo 
"<p>avatar successfuly uploaded</p>";
    
$HTTP_POST_VARS['action'] = "insert";

5. NEVER use deprecated methods of coding. Examples:
1. $HTTP_POST_VARS
2. $somearray[somenonconstant]
3. mysql_db_query()

Fixed:
1. $_POST
2. $somearray['somenonconstant'] (a very common problem that you need to lose!)
3. mysql_query()


There are more and I don't mean to sound pushy, but every single thing I've said in this post is considered the professional industry standard and if you program for a profession then you'd be expected to follow these.
Reply With Quote
  #2  
Old 04-27-2003, 06:32 PM
grog6's Avatar
grog6 grog6 is offline
 
Join Date: Apr 2002
Location: France
Posts: 328
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thx for it Filburt, but we can't consider it as mistakes ... it's just better if you don't work alone, so it is clearer for everybody

I'll take care for it in the future
Reply With Quote
  #3  
Old 04-27-2003, 07:40 PM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

A very good read.
Reply With Quote
  #4  
Old 04-27-2003, 07:58 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Today at 03:32 PM grog6 said this in Post #2
Thx for it Filburt, but we can't consider it as mistakes ... it's just better if you don't work alone, so it is clearer for everybody

I'll take care for it in the future
It's still a good habit to use for when you look back on your code a few months later and think "what the hell was I doing right here?"
Reply With Quote
  #5  
Old 04-27-2003, 09:26 PM
colicab-d's Avatar
colicab-d colicab-d is offline
 
Join Date: Dec 2002
Location: Glasgow
Posts: 382
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

format of your code is a biggy... and fro some langiages can be a bloody joke.. ie truebasic , tho i have to admit ive seen a fair few php scripts that over look putting braces on new lines etc.

Its amazing how annoying something like that can be sometimes
Reply With Quote
  #6  
Old 04-28-2003, 12:43 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good tips there filburt

- miSt
Reply With Quote
  #7  
Old 04-28-2003, 03:20 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

everyone started coding in a crappy style i think, but it's improving.

vb3 will follow these standarts above
Reply With Quote
  #8  
Old 04-28-2003, 05:39 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well i found out all about indenting by accident in my text editor today. It does it all automatically so...

- miSt
Reply With Quote
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. The time now is 01:03 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04529 seconds
  • Memory Usage 2,284KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (7)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete