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

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

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... :lol:
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

This has probably been mentioned.. but I didn't read the other 4 pages (im a bad forumer :()

something like this:

Code: Select all

if($this){
if($that){
if($morethis){
if($morethat)
{
    // do something here
}}}}}
And then the question, whats wrong with it? :(

Recently, this has also been annoying me.

Code: Select all

$t1 = 'this value';
$t2 = 'that';
$t3 = 'that'
$t3_1 = 'that'
I like descriptive variables. I used to be guilty of doing this however.
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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I problably hate nested queries the most :evil:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

scottayy wrote:I used to be guilty of doing this however.
Weren't we all? I used to be the worst violator of the things I hate most. That is partly to blame for why I hate those things. And partly to blame for why I try not to do them anymore. :wink:
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

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. :P

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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

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

Post by Benjamin »

scottayy wrote:

Code: Select all

$t1 = 'this value';
$t2 = 'that';
$t3 = 'that'
$t3_1 = 'that'
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.

And tabs suck. I don't even want to hear any arguments for tabs. Spaces are the bomb.com.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Everah wrote:PS Maugrim, I trackbacked your blog article in my company blog. I thought it was great.
Thanks :). I should have proofread it though! But yes, it covers the 12 practices/attitudes I find most irksome when I read code and more specifically review it with the intention of reporting bugs, fixes and misc issues. The security reporting annoyance is so amazingly common. Company I work for was using a modified version of ADOdb for months after a PostgreSQL exploit I reported remained unfixed (among other things). Simply, ADOdb until recently did not properly escape strings in pg. ADOdb is a good example of annoying code for all that it's a brilliant DB abstraction library...

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.
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.
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. :)

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

Post by feyd »

ok, we've had enough on the tabs versus spaces issue, moving on. Remember kids, this isn't a debate.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

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

Post by RobertGonzalez »

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.';
?>
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Hmm... that is something you'd get that sudden urge to correct alright.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Maugrim_The_Reaper wrote:Hmm... that is something you'd get that sudden urge to correct alright.
yeah! whenever I see such inconsistency in any code - mine or others I have to correct it...

*wonders whether this problem is related to psychology and not programming practice*
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Not to revive the tabs vs. spaces thing, but I indent 5 spaces. (No, no, no: I'm talking about the amount of indent.) I know 4 is standard, but I just can't get by with 4 spaces.
1. I use excessive white space (it just seems cleaner to me, don't know why)
Me too, I love lots of white space.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

feyd wrote:ok, we've had enough on the tabs versus spaces issue, moving on. Remember kids, this isn't a debate.
Awwwwwww ... but it is so irresistibly important !!!

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