Page 3 of 5
Posted: Mon Apr 24, 2006 3:28 am
by matthijs
funny people are talking about tabs vs spaces, as I was fighting my text editor (htmlkit) yesterday due to the strange tab-space behavior. Auto-tabs, smart-tabs, auto-indent. Still don't understand it. Sometimes a hit on the tab will "scip" 4 spaces, the next time only one. That's why I prefer using 4 spaces. It's always the same. And I can remember reading the advice to use 4 spaces in a couple of places. But it sure is more work to hit the spacebar 4, 8, 12 times for each line of code ...
Posted: Mon Apr 24, 2006 3:36 am
by Benjamin
Code: Select all
<?php
}
}
}
}
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<? return 1;
}
Case in point.
Posted: Mon Apr 24, 2006 3:53 am
by Maugrim_The_Reaper
Short tags are the devil. Says so in the Bible.
Posted: Mon Apr 24, 2006 4:29 am
by AKA Panama Jack
matthijs wrote:funny people are talking about tabs vs spaces, as I was fighting my text editor (htmlkit) yesterday due to the strange tab-space behavior. Auto-tabs, smart-tabs, auto-indent. Still don't understand it. Sometimes a hit on the tab will "scip" 4 spaces, the next time only one. That's why I prefer using 4 spaces. It's always the same. And I can remember reading the advice to use 4 spaces in a couple of places. But it sure is more work to hit the spacebar 4, 8, 12 times for each line of code ...
If you used REAL tabs then you wouldn't have to worry about it.

Personally I wish all programming editors would completely remove all support for space tabs.
Posted: Mon Apr 24, 2006 7:04 am
by shiznatix
i use 4 spaces instead of a tab. i have good reasons too!
I have yet to find a editor that works well with the only using tabs. its inconsistant at best when trying to line up your code. and don't go off saying 'get a decent editor' because i am forced to use eclipse at work so I don't have a choice. The auto-tab, the tab-only-so-far-randomly feature is so frustrating because then you put in 2 tabs but open it in another editor and its like 'whoa everything all over the place!' when in my editor its pretty.
Spaces on the other hand. They are the same in every editor. they show the same amount of space in every editor. they don't go crazy with only going so far when you do a tab depending on whatever stupidity stuff there is going on.
also the
its too crowded. you can't really pick out whats going on there at first glance. I do:
its easy to see what it is ("if") and what you are checking. when you write a sentence do you write "ifthisisequaltothat" or do you write "if this is equal to that"? one is definatly easier to read than the other although you could read both just as well upon further investigation.
my cents thrown down in the pot.
Posted: Mon Apr 24, 2006 7:36 am
by Maugrim_The_Reaper
I have yet to find a editor that works well with the only using tabs. its inconsistant at best when trying to line up your code. and don't go off saying 'get a decent editor' because i am forced to use eclipse at work so I don't have a choice
Eclipse IS a decent editor...

. Slow and a little frayed around the edges, but it's a solid IDE.
I use Eclipse with the PHP-Eclipse plugin (the January CVS version on Eclipse 3.1 - not the Zend proposed plugin). I haven't noticed any major issues with using tabs. One tab should be about 4 spaces on most text editors - it's not always, some will vary all the way up to 10 spaces (close to how Firefox displays html indentation with tabs in its source view). Many editors on *nix allow tab size setting via their preferences.
Like I said, I'm not bothered either way since it's just one of those things. Whether you use tabs or not, they're treatment is often inconsistent in editors rendering arguments like this a bit defunct. There's no absolute right or wrong.
Posted: Mon Apr 24, 2006 10:51 am
by tasteslikepurple
having a bazlillion if statements where only one is needed really gets on my nerves.
Code: Select all
if (is_numeric ($a)
{
if ($a > 3)
{
if ($a < 6)
{
echo '$a is less than 6 and greater than 3';
}
}
}
when this can be done instead
Code: Select all
if (is_numeric ($a) && $a > 3 && $a < 6)
{
echo '$a is less than 6 and greater than 3';
}
having said that though, this (and I have seen something similar) is a little unneccessary. Clever, true, but very difficult to read.
Code: Select all
if (is_object ($object) || (is_string ($object) && class_exists ($object) && ($object = new $object())))
(it checks to see if $object is an object, if not, if it's a string it will instantiate a new object of type $object (if it exists)).
Posted: Mon Apr 24, 2006 1:11 pm
by AKA Panama Jack
shiznatix wrote:i use 4 spaces instead of a tab. i have good reasons too!
I have yet to find a editor that works well with the only using tabs. its inconsistant at best when trying to line up your code. and don't go off saying 'get a decent editor' because i am forced to use eclipse at work so I don't have a choice. The auto-tab, the tab-only-so-far-randomly feature is so frustrating because then you put in 2 tabs but open it in another editor and its like 'whoa everything all over the place!' when in my editor its pretty.
Spaces on the other hand. They are the same in every editor. they show the same amount of space in every editor. they don't go crazy with only going so far when you do a tab depending on whatever stupidity stuff there is going on.
Let me put it this way...
I have tested and used just about every single editor out there from free to shareware to commercial and have yet to find a single one that has had a problem displaying program code that used all tabs for indentation. NONE of then have displayed improperly.
If you were having line up problems they were probably caused by the use of either a font with odd sized spaces or you were using a different number of spaces than is taken up by a tab. In most editors, using a standard non-proportional font, 4 spaces equals exactly the same distance as a tab. I know, I have experimented with this in a wide range of editors.
If you are using a proportional font in your editor then NOTHING is going to line up if you mix 4 space indentions and tab indentions.
Or if you are using a non-proportional font but mixing 1, 2, 3 or 5 spaces for indentations with tab indentation then things will not line up either.
If you always use tab indentations and only real tab indentation. REAL tab indentation then you will not have to worry about things not lining up properly in any editor.
Posted: Mon Apr 24, 2006 1:16 pm
by R4000
Not true mate....
I have seen it too many times, its caused because some editors use 4 spaces for tab, and some use 5 spaces, some use 6 ect.
and things become messed up quite fast, i'd rather f&r every tab for 4 spaces, than sit with messed up code. Hell, if i care about disk space i wouldn't use any whitespace, so dont give me the 'size' issue stuff

Posted: Mon Apr 24, 2006 1:18 pm
by feyd
I think it'd be best if we got back on topic boys.
Posted: Mon Apr 24, 2006 1:22 pm
by R4000
feyd wrote:I think it'd be best if we got back on topic boys.
Good idea
The thing that winds me up the most is:
Code: Select all
$n = 0;
while( $n < 10 ){
// do something.
$n++;
}
Just use a for loop for gods sake xD
Posted: Mon Apr 24, 2006 1:43 pm
by Christopher
R4000 wrote:The thing that winds me up the most is:
Code: Select all
$n = 0;
while( $n < 10 ){
// do something.
$n++;
}
Just use a for loop for gods sake xD
Given the opinions I have heard, you might just as well be complaining about any of the following:
1. Using $n instead of $i?
2. Using $n instead of a meaningful name?
3. Not having a space between the "while" and "("?
4. Having a space between the "(" and "$n"?
5. Using a while rather than a for loop?
6. Having a space between the "10" and ")"?
7. Not having a space between the ")" and "{"?
8. Not putting the opening "{" on its own line?
9. Having a vague comment?
10. Not indenting the code block?
11. Using "$n++" rather than "++$n"?
All equally important in someones book.
- Grasshopper ... when can you find the eleven tiny pebbles in this code ... you will be ready.
Posted: Mon Apr 24, 2006 1:56 pm
by timvw
I don't care about edit habits... As long as they are used in a consistent fashion...
For some reason i've seen the following more than i could imagine:
Code: Select all
if (blah == NULL) {
delete blah;
}
Posted: Mon Apr 24, 2006 6:01 pm
by RobertGonzalez
feyd wrote:I think it'd be best if we got back on topic boys.
Dude, I want a piece of this...
I would agree with quite a few of the pet peeves posted so far:
1. I can't stand uncommented code (unless the code speaks for itself)
2. I can't stand inefficient code (using forty lines to do what could be done by a PHP built-in function)
3. I can't stand inconsistent variable/function/object naming conventions
4. I can't stand incorrect uses of include/require
5. I can't stand laziness in development (short tags, etc)
6. I can't stand markup that is in CAPITAL letters
7. I can't stand non-compliant markup
However, there are a few things that I do that I know would irk a few of you...
1. I use excessive white space (it just seems cleaner to me, don't know why)
2. I comment the heck out of my code if it is necessary
3. I use a lot of includes (did anyone mention this as a pet peeve?)
Anyhow, that is my $0.02. This is a killer thread.
PS
Maugrim, I trackbacked your blog article in my company blog. I thought it was great.
Posted: Mon Apr 24, 2006 6:29 pm
by Buddha443556
Any one mention the use of $_REQUEST? Maybe it's just me but it seems lazy. $_POST, $_GET and $_COOKIE seem just a little more informative to me.