Coding habits that drive you nutts...

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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 ...
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

<?php
}

}

}
}
}
?>
</td>
</tr>

	</table>
  </td>
  </tr>
</table>
<?   return 1;
}
Case in point.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Code: Select all

<?   return 1;
Short tags are the devil. Says so in the Bible.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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

Code: Select all

if($var==$you)
its too crowded. you can't really pick out whats going on there at first glance. I do:

Code: Select all

if ($var == $you)
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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
User avatar
tasteslikepurple
Forum Commoner
Posts: 46
Joined: Thu Jan 26, 2006 3:38 am
Location: Bath, UK

Post 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)).
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I think it'd be best if we got back on topic boys.
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
Last edited by Christopher on Mon Apr 24, 2006 2:43 pm, edited 1 time in total.
(#10850)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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;
}
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post 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.
Post Reply