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

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

 

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

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:
PHP Code:
$myarray['mykey'] = "whatever"
Not this:
PHP Code:
$myarray[mykey] = "whatever"
2. Whitespace is your friend. Use it. For example, this is painful to read:
PHP Code:
if($a==b&&$c xor ($d+1)){foo();bar()}; 
For the love of God, do this instead:
PHP Code:
if ($a == $b and $c xor ($d 1)
{
    
foo();
    
bar();

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:
PHP Code:
while (true)
{
if (
$something)
{
for (
$i 0$i $x$i++
{
dosomething();
}
}

Good:
PHP Code:
while (true)
{
    if (
$something)
    {
        for (
$i 0$i $x$i++)
        {
            
dosomething();
        }
    }

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.
Reply With Quote
  #22  
Old 03-16-2003, 08:03 PM
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
Location: Glasgow, Scotland
Posts: 1,199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Core PHP 2nd Edition by Leon Atkison

Anything that claims you can learn a language in 24 hours lies.

Mastering MySQL 4 by Ian Gilfillan is what i've been using to read up on the new mysql 4 features and is a good reference for functions.
Reply With Quote
  #23  
Old 03-16-2003, 08:16 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Today at 04:03 PM PPN said this in Post #21
Core PHP 2nd Edition by Leon Atkison

Anything that claims you can learn a language in 24 hours lies.

Mastering MySQL 4 by Ian Gilfillan is what i've been using to read up on the new mysql 4 features and is a good reference for functions.
Are both of these books good for novices that are just learning PHP?
Reply With Quote
  #24  
Old 03-17-2003, 12:23 AM
Scott MacVicar Scott MacVicar is offline
 
Join Date: Oct 2001
Location: Glasgow, Scotland
Posts: 1,199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Core PHP is excellent for novices, its the book i used to learn PHP and I still use it from time to time to check out some of the wierd functions. Though its probably a bit out of date function wise now.
Reply With Quote
  #25  
Old 03-17-2003, 12:28 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What would you recommend getting now, especially with the coding for vb3 being so different?
Reply With Quote
  #26  
Old 03-17-2003, 02:30 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hehe you can only learn if you read the book for 24 hours - it will take me a month with my schedule

- miSt
Reply With Quote
  #27  
Old 03-17-2003, 02:31 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

www.ineasysteps.com - Boofo i bought my first book from there. It was excellent and informative but very basic... I know the basics now
Reply With Quote
  #28  
Old 03-19-2003, 10:58 PM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Mastering MySQL 4 by Ian Gilfillan is what i've been using to read up on the new mysql 4 features and is a good reference for functions
Im going to pick that book up tomorrow, ive been putting it off...

Ive never learned from a book personlly, ive always done it the hard way, but i am picking up a book on php soon to help with some projects
Reply With Quote
  #29  
Old 03-19-2003, 11:09 PM
Rose's Avatar
Rose Rose is offline
 
Join Date: Nov 2001
Location: K-Town, Germany
Posts: 619
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've been putting off getting a book and putting it off. But by golly I'm getting one by the end of the month!!!
Reply With Quote
  #30  
Old 03-23-2003, 04:39 PM
N9ne N9ne is offline
 
Join Date: Feb 2002
Posts: 1,495
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I hate the InEasySteps books, they're no where near in depth enough, www.wrox.com >> get Beginning PHP 4, I have it, superbly in depth and informative with excellent examples...

I sound like a salesman, don't i?



I do?





I've succeeded then
Reply With Quote
  #31  
Old 03-31-2003, 11:56 AM
PennylessZ28 PennylessZ28 is offline
 
Join Date: Mar 2002
Location: North America
Posts: 737
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Books never helped me, I need to visualize. I have found that having someone hold a gun to your head, is a good way to qucikly figure out how things work.

I second www.wrox.com
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:52 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.04736 seconds
  • Memory Usage 2,311KB
  • Queries Executed 25 (?)
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
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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_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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete