Re: Code indentation... outdated?
Posted: Tue Nov 18, 2008 8:50 am
Ok, but how much indentation?VladSun wrote:Indentation is a must!
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Ok, but how much indentation?VladSun wrote:Indentation is a must!
As much as it is required.allspiritseve wrote:Ok, but how much indentation?VladSun wrote:Indentation is a must!
Well, I don't know if I can give a good example but if we take an html table for example. You create table1 and want to add a table within that. I would not make a new row and indent from bla. I would make a new row and start from left again, probably commenting the table though.VladSun wrote:Define "over-intending"papa wrote:I also think it's vital to intend code etc, but I thought we were talking about over-intending?
Indentation is a must!
Another thing that bothers me, is that I rarely see well formated (with indentation) SQL codes. Even by pro-programmers
Code: Select all
<table>
<tr>
<td>bla></td>
</tr>
</table>
Code: Select all
<table>
<tr>
<td>
<!-- table2 -->
<table>
<tr>
<td>bla2</td>
</tr>
</table>
<!-- //table2 -->
</td>
</tr>
</table>
A HTML table should be used only (I know it will be a flamepapa wrote:Well, I don't know if I can give a good example but if we take an html table for example.VladSun wrote:Define "over-intending"papa wrote:I also think it's vital to intend code etc, but I thought we were talking about over-intending?
Indentation is a must!
Another thing that bothers me, is that I rarely see well formated (with indentation) SQL codes. Even by pro-programmers
Why not? Correct me if I'm wrong, the indentation is supposed to increase readability... And yet usability studies recommend straight left margins of text (think form labels) in order to be read clearly.VladSun wrote:But it has nothing to do with the identation itself as a coding style.
I mean: with or without it, if you have 1000+ (e.g.) nested statements it will be awful... Agree?allspiritseve wrote:Why not? Correct me if I'm wrong, the indentation is supposed to increase readabilityVladSun wrote:But it has nothing to do with the identation itself as a coding style.
Agree.VladSun wrote:I mean: with or without it, if you have 1000+ (e.g.) nested statements it will be awful... Agree?allspiritseve wrote:Why not? Correct me if I'm wrong, the indentation is supposed to increase readabilityVladSun wrote:But it has nothing to do with the identation itself as a coding style.
Precisely.Usually, if there is too much of it (which means - too much of nested statements!) then it's a wrong software design (e.g. a function/method extraction missed). But it has nothing to do with the indentation itself as a coding style.
Code: Select all
<?php
$q = sprintf(
"
SELECT
`fields`
FROM
`a`
LEFT JOIN
`b`
ON
`a`.`1` = `b`.`1`
AND
(
1 = 1
or
2 = %d
)
",
(int)$val
);
Don't know where I was going. Shouldn't drink at work.VladSun wrote: A HTML table should be used only (I know it will be a flame) to represent a tabular data, so in order to have so much of indentation, the data you are trying to present should be with very deep hierarchy. Now give me an example of such data
I probably wouldn't go quite that far, I'd probably keep each clause on a line, instead of two lines, but: notice how there is a clear line running down all the clauses? That's very readable, and at a scan you can find the appropriate clause. The problem I see is when it's a big half-circle, readability is sacrificed.jshpro2 wrote:I even indent my SQL, like this:
I am doing it too, but not in so details. You are greate fun of indentation!jshpro2 wrote:I even indent my SQL, like this:Code: Select all
<?php $q = sprintf( " SELECT `fields` FROM `a` LEFT JOIN `b` ON `a`.`1` = `b`.`1` AND ( 1 = 1 or 2 = %d ) ", (int)$val );
Looks good!VladSun wrote:My way: <skipped>