Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > Programming Articles

Reply
 
Thread Tools
[TIP] Indent Table Elements
mashby's Avatar
mashby
Join Date: Jan 2002
Posts: 736

Married, no kids yet, born in Louisiana and I'm hooked on the television show "24."

Nashville, TN - USA
Show Printable Version Email this Page Subscription
mashby mashby is offline 09-09-2002, 10:00 PM

Table problems are one of the most common problems that people run into when editing their templates. Forget to close a tag and your entire site can become crippled. To help fix this problem before it starts, I recommend that you indent each element when using tables. By simply adding a tab, or a few spaces to your code, you can make it easier to see if there's a problem with your code.

Compare the following two code samples and you'll see what I mean:

Code:
<!-- without indents -->
<table><tr>
<td>hello world</td></tr>
</table>
<!-- /without indents -->
Code:
<!-- with indents -->
<table>
	<tr>
		<td>hello world</td>
	</tr>
</table>
<!-- /with indents -->
Which is easier to read? When I try and help someone with their code, one of the first things I do is reformat their code with indents. If there's a problem with a missing tag, you can be sure that I can find it in a jiffy with this method.

You'd be surprised at what a difference something as simple as this can make.
Reply With Quote
  #2  
Old 09-12-2002, 07:18 AM
Bad Bunny's Avatar
Bad Bunny Bad Bunny is offline
 
Join Date: Apr 2002
Posts: 555
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Another good point. I work with an editor that formats code (if I want it to) very similarly.
Reply With Quote
  #3  
Old 09-12-2002, 08:06 AM
Tony G's Avatar
Tony G Tony G is offline
 
Join Date: Nov 2001
Location: Melbourne, Australia
Posts: 8,357
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes thats how it's set in most template mods and the default templates. Much easier.
Reply With Quote
  #4  
Old 09-24-2002, 04:46 PM
imported_plattopus imported_plattopus is offline
 
Join Date: Jun 2002
Location: Melbourne, Australia
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Indenting by using a TAB space is usually a bad idea, because the TAB character is interpreted differently on different platforms (which means you can have nice neat code on Windows, but try to edit it in Unix and you'll wonder what the hell happened).

vB uses TAB spaces everywhere, but as a general rule I stick to the '2 space' convention. That is, 2 non-breaking spaces for each indented line of code.

I've also set up my text editor to do the same. It makes for very nice, clean code.
Reply With Quote
  #5  
Old 09-25-2002, 12:07 AM
Tony G's Avatar
Tony G Tony G is offline
 
Join Date: Nov 2001
Location: Melbourne, Australia
Posts: 8,357
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just space as much as the other ones are, so I don't use TAB or anything.
Reply With Quote
  #6  
Old 09-28-2002, 04:09 PM
imported_plattopus imported_plattopus is offline
 
Join Date: Jun 2002
Location: Melbourne, Australia
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The 'other spaces' are tab spaces.
Reply With Quote
  #7  
Old 09-28-2002, 04:10 PM
imported_plattopus imported_plattopus is offline
 
Join Date: Jun 2002
Location: Melbourne, Australia
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Note: A TAB space is an actual character, so when I use that word I am referring to the character itself, not what happens when you press the TAB key (although in almost all cases they are the same).
Reply With Quote
  #8  
Old 09-29-2002, 12:33 AM
Tony G's Avatar
Tony G Tony G is offline
 
Join Date: Nov 2001
Location: Melbourne, Australia
Posts: 8,357
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by plattopus
The 'other spaces' are tab spaces.
Ahh, I had no idea they were. Well it's good to use them then for some clean code.

BTW can't try it in here because of the other input spaces.
Reply With Quote
  #9  
Old 09-29-2002, 02:08 PM
imported_plattopus imported_plattopus is offline
 
Join Date: Jun 2002
Location: Melbourne, Australia
Posts: 77
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's not good to use them, because as I explained before you can't rely on their readability across all platforms. You can even change the size of TAB spaces to your liking in various programs, so you can pretty much be sure that your code will look different for everyone if you use TAB spaces instead of non-breaking spaces.
Reply With Quote
  #10  
Old 09-30-2002, 10:46 PM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I never indent table elements, because ive known about the issues as i use both windows and linux, and i can read my code very well without them anyway.
Reply With Quote
Reply

Thread Tools

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 02:49 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.04969 seconds
  • Memory Usage 2,277KB
  • 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
  • (2)bbcode_code
  • (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
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)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