Code indentation... outdated?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Code indentation... outdated?

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Code indentation... outdated?

Post by Christopher »

allspiritseve wrote:Thoughts?
Here is something for you to learn this month. ;)
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Code indentation... outdated?

Post 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
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Code indentation... outdated?

Post by allspiritseve »

arborint wrote:
allspiritseve wrote:Thoughts?
Here is something for you to learn this month. ;)
Care to explain?
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Code indentation... outdated?

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Code indentation... outdated?

Post by Christopher »

allspiritseve wrote:Care to explain?
From the Python Manual:

"statement grouping is done by indentation instead of beginning and ending brackets"
(#10850)
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: Code indentation... outdated?

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Code indentation... outdated?

Post by Christopher »

Yep
(#10850)
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Code indentation... outdated?

Post by papa »

I think it's more of a "I'm using a webpublishing tool" thing....
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Code indentation... outdated?

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Code indentation... outdated?

Post 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
User avatar
inghamn
Forum Contributor
Posts: 174
Joined: Mon Apr 16, 2007 10:33 am
Location: Bloomington, IN, USA

Re: Code indentation... outdated?

Post 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.
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Re: Code indentation... outdated?

Post 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.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Code indentation... outdated?

Post by papa »

I also think it's vital to intend code etc, but I thought we were talking about over-intending?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Code indentation... outdated?

Post 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
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply