On Wed, 2007-01-24 at 18:23 -0600, Richard Lynch wrote: 
> On Wed, January 24, 2007 7:41 am, Roman Neuhauser wrote:
> > # [EMAIL PROTECTED] / 2007-01-24 13:57:03 +0200:
> >> and also in these days I'm looking for 19 inch (or more) wide LCD
> >> sceerns to able to fit longer lines in my screen...
> >
> > Number of reading errors people make grows with line length,
> > this has been known for as long as I remember.  You're increasing the
> > probability of bugs in the code, and get tired sooner because
> > following
> > long lines requires more energy.
> 
> I believe those results are specific to what is being read.
> 
> Surely it's easier to read:
> 
> SELECT blah, blah, blah, blah, blah, blah, blah, blah, blah
> 
> if it's all on one line, no matter how many fields there are, while
> trying to read the code as a whole.
> 
> Sure, it can be "hard" to find/read the individual field names, on the
> rare occasion that you need to do that...

Dear Mr Lynch, normally I highly respect your commentary on the list,
but today I think you've been-a-smoking the crackpipe a tad too much.

There is no way in hell one long line of SQL is easier to read than
formatted SQL that clearly delineates the clause structure.

SELECT A.field1 AS afield1, A.field2 AS afield2, B.field1 AS bfield1,
B.field2 AS bfield2, C.field1 AS cfield1, C.field2 AS cfield2, D.field1
AS dfield1, D.field2 AS dfield2 FROM tableA as A LEFT JOIN tableB AS B
ON B.fee = A.foo LEFT JOIN tableC AS C ON C.fii = B.fee LEFT JOIN tableD
AS D ON D.fuu = C.fii WHERE A.foo = 'someValue' ORDER BY afield1 ASC,
cfield2 ASC

The above line "should" be on one line, but my email client might
autowrap it. Either way, the following is formatted and is much clearer.

SELECT
    A.field1 AS afield1,
    A.field2 AS afield2,
    B.field1 AS bfield1,
    B.field2 AS bfield2,
    C.field1 AS cfield1,
    C.field2 AS cfield2,
    D.field1 AS dfield1,
    D.field2 AS dfield2
FROM
    tableA as A
        LEFT JOIN tableB AS B ON
            B.fee = A.foo
        LEFT JOIN tableC AS C ON
            C.fii = B.fee
        LEFT JOIN tableD AS D ON
            D.fuu = C.fii
WHERE
    A.foo = 'someValue'
ORDER BY
    afield1 ASC,
    cfield2 ASC


While the above is contrived, most of us know such examples happen quite
often in the wild. Not only is it easier to read, but the task of adding
or removing selected fields is trivial.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to