Code indentation... outdated?
Moderator: General Moderators
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Code indentation... outdated?
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?
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?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Code indentation... outdated?
(#10850)
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Code indentation... outdated?
FormattingiscriticialtothesuccessofaprojectwithoutitcodeisverydifficulttoreadIt'slikewrittingapcoupleparagrpahswithoutusingparagraphsorsentancesandsoonandsoforth. 
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.
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.
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Code indentation... outdated?
Care to explain?
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Code indentation... outdated?
I feel like its a case of overformatting, though. It just seems so common.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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Code indentation... outdated?
From the Python Manual:allspiritseve wrote:Care to explain?
"statement grouping is done by indentation instead of beginning and ending brackets"
(#10850)
- allspiritseve
- DevNet Resident
- Posts: 1174
- Joined: Thu Mar 06, 2008 8:23 am
- Location: Ann Arbor, MI (USA)
Re: Code indentation... outdated?
arborint wrote:From the Python Manual:allspiritseve wrote:Care to explain?
"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?- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Code indentation... outdated?
I think it's more of a "I'm using a webpublishing tool" thing....
Re: Code indentation... outdated?
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?
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.
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.
- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: Code indentation... outdated?
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.
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.
- xpgeek
- Forum Contributor
- Posts: 146
- Joined: Mon May 22, 2006 1:45 am
- Location: Kyiv, Ukraine
- Contact:
Re: Code indentation... outdated?
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.
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?
I also think it's vital to intend code etc, but I thought we were talking about over-intending?
Re: Code indentation... outdated?
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
There are 10 types of people in this world, those who understand binary and those who don't