User Control Panel
Advertisements

HELP US, HELP YOU!

Indenting your Code

 
Post new topic   Reply to topic    Bot Depot Forum Index -> General Programming Questions
View unanswered posts
Author Message
Cer
Upgraded Agent
Upgraded Agent


Joined: 03 Feb 2004
Posts: 3776
Location: Michigan
Reputation: 146.9
votes: 4

PostPosted: Fri Jun 03, 2005 11:08 pm    Post subject: Reply with quote

In HTML specifically, many sites I view the source of sometimes tend to be the same: the coder indents things using spaces and not tabs.

First of all: using spaces instead of tabs DOESN'T make your file size's smaller. In fact it does the opposite. One space = one byte. One TAB = one byte. They're equal. However, nobody who does tabs with spaces stops at one space. They usually use 3 or 5 spaces. Now, 3 spaces = 3 bytes as opposed to 1 tab = 1 byte.

So using spaces instead of tabs makes your source's white spaces become 3 times as large. Or if you use 5 spaces instead of a tab, 5 times as large.

Advantages/Disadvantages to Spaces
+ Sure it makes your source smaller, but who cares?
- It makes your file size larger than with tabs.
+ You can indent to more levels without getting horizontal scrollbar.
- Hard to make changes (i.e. to move one far-indented block of text a level closer, you have to hit delete many times for all the spaces as opposed to just a couple for tabs)

Advantages/Disadvantages to Tabs
+ Makes your file size smaller
- Makes your source longer to read but who cares?
+ Easy to make changes (see above)
- Can only indent so many levels before horizontal scrollbar shows up

There's more obvious pros and cons on either side, but using tabs rather than spaces is more efficient (this is mostly referring to HTML, since programming languages lose all their excess space on compilation anyway).

_________________
Current Site (2008) http://www.cuvou.com/
Back to top
malefactor
Member
Member


Joined: 27 Jan 2005
Posts: 109
Location: Lewiston, ME
Reputation: 17.7Reputation: 17.7

PostPosted: Sat Jun 04, 2005 12:24 am    Post subject: Reply with quote

QUOTE(Cer @ Jun 3 2005, 03:08 PM)
Advantages/Disadvantages to Spaces
- Hard to make changes (i.e. to move one far-indented block of text a level closer, you have to hit delete many times for all the spaces as opposed to just a couple for tabs)

Advantages/Disadvantages to Tabs
+ Easy to make changes (see above)
- Can only indent so many levels before horizontal scrollbar shows up


many programs allow you to tab with spaces, ie. when you hit tab it inserts 5 spaces (or however many you have it set too..)
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Sat Jun 04, 2005 12:12 pm    Post subject: Reply with quote

It's still not good. I hate going through someone else's code, trying to debug, when they have used one or two spaces, instead of tabs:

Code:
<br /><table><br />  <tr><br />    <td><br />    </td><br />   </tr><br /></table><br />


It gets annoying when deleting half of it, or something. This is just so much easier:

Code:
<br /><table><br />   <tr><br />  <td><br />  </td><br />   </tr><br /></table><br />


invision may ruin this example, but meh.

_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Sat Jun 04, 2005 1:01 pm    Post subject: Reply with quote

Quote:
So using spaces instead of tabs makes your source's white spaces become 3 times as large. Or if you use 5 spaces instead of a tab, 5 times as large.

That's a very quick conclusion. I could also state, if you don't intend your file size will become X times smaller! Wow! Let's all not use intending at all!

It doens't matter WHAT you use, as long as it is readable. Many [good] editors automatically convert spaces to tabs or vice versa automatically or with some option. There are also some good editors out there which have the option to select a block of code and click "intend" or "unintend" and it does the work for you.. No backspaces!

Even more so, tabs don't work on IPB, unfortunatly. Ever tried it? I think darkmonkey is refering to that. Spaces so fine, tabs don't, a horrible pain the *annoying*. Luckaly theres always the search & replace (or auto-intend option) in editors.

In the end it doesn't matter whether you use spaces or tabs.. As long as the code is readable and maintainable. Likewise it doesn't matter whether you use if(!..) or just unless(...). It both does the same thing.

Plus, personally, if I post something, I convert it to spaces. Why? Because spaces have a fixed length, whereas tabs depend highly on the font/font size used. In my code I always use tabs because I'm too lazy for spaces.
Back to top
mattaustin
Sentinel
Sentinel


Joined: 19 Jul 2004
Posts: 556
Location: Los Angeles, CA
Reputation: 50.7
votes: 1

PostPosted: Mon Jun 06, 2005 4:20 pm    Post subject: Reply with quote

A tab in NOT usually one character...it actually depends on what your tab spacing is set to in the editor your using. For example in the Perl editor i use i ran a simple test:

Code:
print length("       ");
by pressing tab between the quotes.... it printed 7 so that would be 7 bits added to the code..when i could have indented with 3 and had the same effect.
_________________
[ matt ]
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Mon Jun 06, 2005 4:21 pm    Post subject: Reply with quote

I assume you meant "7 bytess added to the code"?
But yes, it entirely depends on your editor.
Back to top
malefactor
Member
Member


Joined: 27 Jan 2005
Posts: 109
Location: Lewiston, ME
Reputation: 17.7Reputation: 17.7

PostPosted: Mon Jun 06, 2005 4:25 pm    Post subject: Reply with quote

for my own site I write html in paragraph form. Its so much easier to find something in particular that way. It may not be as readable to someone else, but I know what each paragraph represents.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> General Programming Questions All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group