Ok, but how much indentation?VladSun wrote:Indentation is a must!
Code indentation... outdated?
Moderator: General Moderators
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Code indentation... outdated?
Re: Code indentation... outdated?
As much as it is required.allspiritseve wrote:Ok, but how much indentation?VladSun wrote:Indentation is a must!
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.
Last edited by VladSun on Tue Nov 18, 2008 9:36 am, edited 2 times in total.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Code indentation... outdated?
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>
Looking what I'm working in now, I'd say it's a common webpublishing-tool issue. But maybe people program that way I don't know.
Do I make sense?
edit:
It's called indent damn it!
Last edited by papa on Tue Nov 18, 2008 9:17 am, edited 1 time in total.
Re: Code indentation... outdated?
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
Last edited by VladSun on Tue Nov 18, 2008 9:36 am, edited 4 times in total.
There are 10 types of people in this world, those who understand binary and those who don't
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Code indentation... outdated?
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'd rather group my code in semantic blocks, using indentation sparingly for sections that really deserve being set off from the rest.
Re: Code indentation... outdated?
oops
#! TO BE REMOVED
#! TO BE REMOVED
Last edited by VladSun on Tue Nov 18, 2008 9:37 am, edited 3 times in total.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Code indentation... outdated?
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.
There are 10 types of people in this world, those who understand binary and those who don't
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Code indentation... outdated?
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.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Code indentation... outdated?
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.
Re: Code indentation... outdated?
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
);
Re: Code indentation... outdated?
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
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Code indentation... outdated?
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:
- xpgeek
- Forum Contributor
- Posts: 146
- Joined: Mon May 22, 2006 1:45 am
- Location: Kyiv, Ukraine
- Contact:
Re: Code indentation... outdated?
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 );
Re: Code indentation... outdated?
My way:
[sql]SELECT
web_language_context.name AS context_name,
web_language_item.name AS item_name,
web_translation.text AS item_text
FROM
web_language_item
INNER JOIN
web_language_context ON
web_language_item.fk_context_id = web_language_context.id
INNER JOIN
web_language ON web_language.id = ?
LEFT JOIN
web_translation ON
web_translation.fk_language_id = ?
AND
web_translation.fk_item_id = web_language_item.id
WHERE
web_language_item > 0
OR
web_language_item = -1
GROUP BY
web_language.id, web_language.name
ORDER BY
web_language.name DESC, web_language.id
LIMIT
0, 10[/sql]
[sql]SELECT
web_language_context.name AS context_name,
web_language_item.name AS item_name,
web_translation.text AS item_text
FROM
web_language_item
INNER JOIN
web_language_context ON
web_language_item.fk_context_id = web_language_context.id
INNER JOIN
web_language ON web_language.id = ?
LEFT JOIN
web_translation ON
web_translation.fk_language_id = ?
AND
web_translation.fk_item_id = web_language_item.id
WHERE
web_language_item > 0
OR
web_language_item = -1
GROUP BY
web_language.id, web_language.name
ORDER BY
web_language.name DESC, web_language.id
LIMIT
0, 10[/sql]
Last edited by VladSun on Thu Sep 09, 2010 4:36 pm, edited 1 time in total.
There are 10 types of people in this world, those who understand binary and those who don't
- xpgeek
- Forum Contributor
- Posts: 146
- Joined: Mon May 22, 2006 1:45 am
- Location: Kyiv, Ukraine
- Contact:
Re: Code indentation... outdated?
Looks good!VladSun wrote:My way: <skipped>
And it's my way:
[sql] SELECT web_language_context.name AS context_name, web_language_item.name AS item_name, web_translation.text AS item_textFROM web_language_itemINNER JOIN web_language_context ON web_language_item.fk_context_id = web_language_context.idINNER JOIN web_language ON web_language.id = ?LEFT JOIN web_translation ON web_translation.fk_language_id = ? AND web_translation.fk_item_id = web_language_item.id WHERE web_language_item > 0 OR web_language_item = -1GROUP BY web_language.id, web_language.nameORDER BY web_language.name DESC, web_language.idLIMIT 0, 10[/sql]
This way JOIN'S is more structured imho.
In WHERE i put AND, OR after expression, so it's very compact.
And looks nice.