Coding habits that drive you nutts...
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Man, I totally forgot that one. And the one about relying on register_globals being on, not validating user input, using insanely large arrays that don't need to be that big and repeating SQL queries that could easily be read into a single global array for use anywhere throughout the script. Whooowee, now my brain is working... 
This has probably been mentioned.. but I didn't read the other 4 pages (im a bad forumer
)
something like this:
And then the question, whats wrong with it? 
Recently, this has also been annoying me.
I like descriptive variables. I used to be guilty of doing this however.
something like this:
Code: Select all
if($this){
if($that){
if($morethis){
if($morethat)
{
// do something here
}}}}}Recently, this has also been annoying me.
Code: Select all
$t1 = 'this value';
$t2 = 'that';
$t3 = 'that'
$t3_1 = 'that'Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I use spaces instead of tabs. I'm not the only one.
It is not messy, not inconsistent, not sloppy, and not lazy.
Why did I end up going down that path?
This presumes you are on windows..
Open a webview of a file in CVS/SVN.
Copy some text to your clipboard.
Open a Putty session to a linux machine (thats where I do my coding), use nano to edit a new version of that file (bounty.php), and paste into it.
Now do a diff. If bounty.php has tabs in it, you will get a diff that lists every single line in the file.
Thats broken. Considering that when I started coding, I was doing that over a hundred times a day, I quickly realized that people using tabs are forcing work onto others. Read the link at the beginning of my post on how you can have your tab-fanatic-fantasies fulfilled without crippling the work of others.
I just thought I'd join in on the arrogant personal preference commentary, since I (among other computer professionals) think tabs are stupid.
As a side note, I am absolutely amazed that we're doing a tabs-vs-spaces thread, with little moderation, considering that its one of the top twenty flame wars on the net in history. Whats next, vi versus emacs? Windows v. linux?
It is not messy, not inconsistent, not sloppy, and not lazy.
Why did I end up going down that path?
This presumes you are on windows..
Open a webview of a file in CVS/SVN.
Copy some text to your clipboard.
Open a Putty session to a linux machine (thats where I do my coding), use nano to edit a new version of that file (bounty.php), and paste into it.
Now do a diff. If bounty.php has tabs in it, you will get a diff that lists every single line in the file.
Thats broken. Considering that when I started coding, I was doing that over a hundred times a day, I quickly realized that people using tabs are forcing work onto others. Read the link at the beginning of my post on how you can have your tab-fanatic-fantasies fulfilled without crippling the work of others.
I just thought I'd join in on the arrogant personal preference commentary, since I (among other computer professionals) think tabs are stupid.
As a side note, I am absolutely amazed that we're doing a tabs-vs-spaces thread, with little moderation, considering that its one of the top twenty flame wars on the net in history. Whats next, vi versus emacs? Windows v. linux?
I have always used tabs. But lately (not even just this topic, ive actually read other stuff I think on the PEAR website) ive been convinced that I should start using spaces.
My reasons for wanting to use tabs:
One tap indent (as opposed to pressing space 2 or 4 times)
Easier to delete code (less times hitting backspace)
My editor automatically tabs (could probably be configured to space instead)
I'm the only one reading/writing my code (could change in the future)
I only code on windows (could change in the future)
My reasons for leaning towards using spaces:
The page Roja just referenced
Apparently the website (again, i believe PEAR) states that 4 spaces is the "standard"
Edit: This board now converts my tabs to 8 spaces, instead of 4. Making my code look really drawn out.
My reasons for wanting to use tabs:
One tap indent (as opposed to pressing space 2 or 4 times)
Easier to delete code (less times hitting backspace)
My editor automatically tabs (could probably be configured to space instead)
I'm the only one reading/writing my code (could change in the future)
I only code on windows (could change in the future)
My reasons for leaning towards using spaces:
The page Roja just referenced
Apparently the website (again, i believe PEAR) states that 4 spaces is the "standard"
Edit: This board now converts my tabs to 8 spaces, instead of 4. Making my code look really drawn out.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
For the love of god, why would someone do that? Especially as a Newbie when you would want variable names to be descriptive. I worked with some code lately where the author put every variable into an array and assigned it a random index. ie $a['323'] would be a username. Jesus.scottayy wrote:Code: Select all
$t1 = 'this value'; $t2 = 'that'; $t3 = 'that' $t3_1 = 'that'
And tabs suck. I don't even want to hear any arguments for tabs. Spaces are the bomb.com.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
ThanksEverah wrote:PS Maugrim, I trackbacked your blog article in my company blog. I thought it was great.
I also use quite a few includes. Personally I see nothing wrong with that. I keep one class to one file - so if I end up using 40 classes, well, that's 40+ includes. Many are also sinfully (in some views) using those *_once() functions. The impact of so many includes is not a huge issue to peformance. I can run several of my apps though XDebug and it show it as being minor - hardly worth noting.
I dislike seeing $_REQUEST - I just wind up changing it to $_GET and $_POST. If it is actually used as an OR check for GET/POST then I rip it apart and separate the two into distinct uses. Makes the code more understandable...and it's usually a step in the right direction for security.
Tabs vs Spaces is only a flamewar because people ignore the practical need for tabs or spaces to individual developers and get too emotionally wrapped up in a stupid tiff over formatting preferences which effect them on a personal level. I rarely use nano or pico when coding (unless applying a quick fix or patch to an online app) therefore using spaces has absolutely no advantages for me, and I dare say many others. Does that make using tabs stupid? No, it makes them a common sense preference...for us...not for everyone. So long as tabs don't impact diffs in the normal course of development for me I see little reason to change. Amen to editors who allow you to switch between both regimes.Roja wrote:Thats broken. Considering that when I started coding, I was doing that over a hundred times a day, I quickly realized that people using tabs are forcing work onto others. Read the link at the beginning of my post on how you can have your tab-fanatic-fantasies fulfilled without crippling the work of others.
I wouldn't copy directly from that webview anyway. I'd copy first to an editor, fix the inconsistent indentation, add extra spacing, small caps the HTML, then mess up the diff in ssh.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Another annoyance i thought of; use of functions with early PHP4 argument order where PHP 4.2+ changed these long ago. Came across this in a few libraries. Twice I've seen alternate argument orders separated by a PHP version check - despite the fact that function arguments in the wrong place often count as parsing errors (i.e. a conditional statement does absolutely nothing to decide between a valid or invalid variant for the current PHP version) unless allowed for in the PHP C code.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
How about completely inconsistent use of single and double quotes? Has anyone mentioned that yet? I know it is not a major issue, but sometimes it gets on my nerves...
Code: Select all
<?php
$this_var = "Oooh, I am a string!";
$this_other_var = 'Me too, Me too!';
$this_array['foo'] = "Man this is foo barred";
$this_array["bar"] = 'This is barred too.';
?>- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Awwwwwww ... but it is so irresistibly important !!!feyd wrote:ok, we've had enough on the tabs versus spaces issue, moving on. Remember kids, this isn't a debate.
I indent 6.5 picas. I find that less than 6.1 picas is completly unreadable and anything over 7.3 picas to be waaaaaay too much whitespace. I tend to do most of my coding in Adobe Illustrator because its the only programming editor that gives me the formatting control I need (plus b-splines rock!).
(#10850)