Page 1 of 5

Code indentation... outdated?

Posted: Mon Nov 17, 2008 11:22 pm
by allspiritseve
This could go for both front end and back end code, but... I figure theory is as good a place as any.

I tend to use indents sparingly in my code. However, it seems like the majority of code I see, whether php, html, or javascript, has an enormous amount of indents. Why is this? I assume the original intent was to increase readability, but if every line is indented, then I think that makes readability worse. Part of the problem, especially with html, may be code editors (dreamweaver, etc.) that do this automatically. I think it only really becomes useful when you have an IDE with code hiding features, and most of the indents disappear. Otherwise... I just can't stand every new nested item being indented. It also makes modifications more annoying because you have to reindent whenever you add or remove a nested item.
</rant>

Thoughts?

Re: Code indentation... outdated?

Posted: Mon Nov 17, 2008 11:49 pm
by Christopher
allspiritseve wrote:Thoughts?
Here is something for you to learn this month. ;)

Re: Code indentation... outdated?

Posted: Mon Nov 17, 2008 11:58 pm
by alex.barylski
FormattingiscriticialtothesuccessofaprojectwithoutitcodeisverydifficulttoreadIt'slikewrittingapcoupleparagrpahswithoutusingparagraphsorsentancesandsoonandsoforth. :P

As long as people are writing code formatting will play a critical role...the more clearly set in stone the rules are the better code I would say. Whether you follow a convention exactly or use a tool like Python. :P

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 1:00 am
by allspiritseve
arborint wrote:
allspiritseve wrote:Thoughts?
Here is something for you to learn this month. ;)
Care to explain?

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 1:03 am
by allspiritseve
PCSpectra wrote:As long as people are writing code formatting will play a critical role...the more clearly set in stone the rules are the better code I would say.
I feel like its a case of overformatting, though. It just seems so common.

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 1:34 am
by Christopher
allspiritseve wrote:Care to explain?
From the Python Manual:

"statement grouping is done by indentation instead of beginning and ending brackets"

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 1:48 am
by allspiritseve
arborint wrote:
allspiritseve wrote:Care to explain?
From the Python Manual:

"statement grouping is done by indentation instead of beginning and ending brackets"

Code: Select all

so
    indenting
        the
            hell
                out
                    of
                    your
                code
            is
        a
    python
thing?

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 2:03 am
by Christopher
Yep

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 3:05 am
by papa
I think it's more of a "I'm using a webpublishing tool" thing....

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 3:09 am
by Eran
Indentation is a small part of coding standards - a very important practice to have in my opinion. By caring about how code looks and not just how it works, you end up improving more than the number of spaces it has from the beginning of line - at least that has been my experience. This and of course the obvious - it being more readable, consistent and friendly to other developers.

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 3:18 am
by alex.barylski
I think many developers tend to forget that programming is one half art and one half science. Ugly hard to read code is depressing and difficult to stay motivated about.

Formatting and effective commentation will help ease the "ick" feeling. Personally I like very few comments...yet others love that feeling of a sea of green splattered through out their source text. :P

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 7:45 am
by inghamn
Code formatting, including indentation and frequent, well-written comments are an incredible timesaver. Formatting code is the most basic skill a developer should have. Right after teaching variables and loops, schools should teach good code formatting, and the benefits of formatting.

It saves time and brainpower when modifying or adding to existing code. And even if you're working on your own code, it's still existing code. I don't memorize what I wrote 6months or a year ago. But if I can glance at well formatted code, and understand it's structure in an instant, I can start making productive changes right away.

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 8:04 am
by xpgeek
I see a lot of code without formatting and it's painful.
So i have found for my self some autoformatting tools which helps a lot to understand unformatted code and make it clear.
First thing when i start refactoring users code i start from formatting a style.
If you will work with more then 2 developers you will find what one formatting style is very useful and save a lot of time, it's the same for opensource code.
Learn the ZF coding standart guides to make it clear for youself.

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 8:27 am
by papa
I also think it's vital to intend code etc, but I thought we were talking about over-intending?

Re: Code indentation... outdated?

Posted: Tue Nov 18, 2008 8:33 am
by VladSun
papa wrote:I also think it's vital to intend code etc, but I thought we were talking about over-intending?
Define "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