Page 4 of 5

Posted: Mon Apr 24, 2006 8:08 pm
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:

Posted: Mon Apr 24, 2006 8:49 pm
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.

Posted: Mon Apr 24, 2006 9:03 pm
by John Cartwright
I problably hate nested queries the most :evil:

Posted: Mon Apr 24, 2006 9:24 pm
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:

Posted: Mon Apr 24, 2006 9:59 pm
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?

Posted: Tue Apr 25, 2006 1:56 am
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.

Posted: Tue Apr 25, 2006 3:23 am
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.

Posted: Tue Apr 25, 2006 3:37 am
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. ;)

Posted: Tue Apr 25, 2006 3:45 am
by feyd
ok, we've had enough on the tabs versus spaces issue, moving on. Remember kids, this isn't a debate.

Posted: Tue Apr 25, 2006 6:26 am
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.

Posted: Tue Apr 25, 2006 11:01 am
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.';
?>

Posted: Tue Apr 25, 2006 12:37 pm
by Maugrim_The_Reaper
Hmm... that is something you'd get that sudden urge to correct alright.

Posted: Tue Apr 25, 2006 1:12 pm
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*

Posted: Wed Apr 26, 2006 8:42 am
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.

Posted: Wed Apr 26, 2006 11:34 am
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!).