Page 3 of 5

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 2:36 pm
by thinsoldier
allspiritseve wrote:

Code: Select all

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

Code: Select all

so
indenting
  the
    hell
      out
        of
          your
        code
      is
    a
  python
thing?
I use actual TABS for indentation and set my text editors to display tabs as only 2 or 3 spaces.
5 or 8 space tabs is complete overkill and makes some things impossible to read.
2 is good.

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 4:07 pm
by allspiritseve
thinsoldier wrote:I use actual TABS for indentation and set my text editors to display tabs as only 2 or 3 spaces.
5 or 8 space tabs is complete overkill and makes some things impossible to read.
2 is good.
No matter the number of spaces you use, I still find a semi-circle margin like that very hard to read. It also still means if I edit something 8 tabs in, I have to hit the tab button 8 times before I can type.

Also-- your editor may only use 2 or 3 spaces, but what about when somebody uses view source? Or when you're away from your computer and need to edit a file, and the only thing available is cpanel's crappy editor?

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 4:28 pm
by VladSun
allspiritseve wrote:(1) No matter the number of spaces you use, I still find a semi-circle margin like that very hard to read. (2)It also still means if I edit something 8 tabs in, I have to hit the tab button 8 times before I can type.

(3) Also-- your editor may only use 2 or 3 spaces, but what about when somebody uses view source? (4) Or when you're away from your computer and need to edit a file, and the only thing available is cpanel's crappy editor?
(1) Every indented code block is called a statement - it has its own meaning. So one can understand what the "outter" statement does without even looking at the inner statement. In fact, many editors have even "statement collapse" feature ... guess why ;)

(2) Editors (I don't mean notepad!) will grant you a "free" tab indentation without pressing the tab key more than once.

(3) That's why I vote for using Tabs instead of spaces.

(4) And what if you have only 6x3 chars screen, or a WAP interface to cpanel, or Notepad only availabale, but Unix style new lines, or ...

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 4:48 pm
by allspiritseve
VladSun wrote:(4) And what if you have only 6x3 chars screen, or a WAP interface to cpanel, or Notepad only availabale, but Unix style new lines, or ...
The above use-cases I listed are ones I've often come upon... can't say the same for yours. Nice try.

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 4:50 pm
by josh
allspiritseve wrote:No matter the number of spaces you use, I still find a semi-circle margin like that very hard to read. It also still means if I edit something 8 tabs in, I have to hit the tab button 8 times before I can type.
Not if you use an IDE made in the last 10 years! :D

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 4:57 pm
by allspiritseve
jshpro2 wrote:Not if you use an IDE made in the last 10 years! :D
I'm using eclipse... obviously in some cases it auto-indents, but in others I still have to hit tab quite a number of times.

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 4:58 pm
by VladSun
allspiritseve wrote:
VladSun wrote:(4) And what if you have only 6x3 chars screen, or a WAP interface to cpanel, or Notepad only availabale, but Unix style new lines, or ...
The above use-cases I listed are ones I've often come upon... can't say the same for yours. Nice try.
Believe or not I haven't seen the famous cpanel interface. But I have edited Unix format files with Notepad.
Anyway, I've just wanted to say that your 4th argument is not specific to indentation, but to editing in general ;)

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 5:01 pm
by VladSun
allspiritseve wrote:
jshpro2 wrote:Not if you use an IDE made in the last 10 years! :D
I'm using eclipse... obviously in some cases it auto-indents, but in others I still have to hit tab quite a number of times.
I can hardly imagine how this could happen, but it would be because of the same reason if you say that editing with vi (or vim) is a nasty job to do.

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 5:16 pm
by allspiritseve
VladSun wrote:Believe or not I haven't seen the famous cpanel interface. But I have edited Unix format files with Notepad.
Anyway, I've just wanted to say that your 4th argument is not specific to indentation, but to editing in general ;)
Well, sure, but my main point is that excessive code intentation isn't very readable, and I appreciate readable code whether its in a full-blown IDE, notepad, vim, cpanel's editor, or firefox's view source.

Along those same lines, I think you mentioned earlier that each statement has meaning, encapsulating the code it contains. If that's the case, some of that code might be better off inside another method. I think many times there isn't really a meaning though, and every single nested item is indented a tab. That seems ridiculous and excessive to me, and I'd rather see a block of text that had a functional meaning all on the same level of indentation. There are better ways to organize code semantically than tabs, I guess.

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 5:26 pm
by VladSun
Willing to give us an example of your semantical code organization?

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 5:41 pm
by allspiritseve
VladSun wrote:Willing to give us an example of your semantical code organization?
I don't have a specific example for you, but in general extracting methods on the back end, and grouping in blocks for the front end (header, nav, main content, footer, etc.) are common practices for me.

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 6:45 pm
by Christopher
I think I agree with allspiritseve when it comes to HTML and other Domain Specific Languages. I think is what the OP was referring to. I can think of several area, tables for example, where full intention may be considered less readable.

However, I think indenting of program code is not really an open question anymore. There is very little variation since K&R days. It has become part of the orginazation of code expected by all programmers.

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 6:48 pm
by josh
I consider tables are an exception to the rule, just like ternary operators. In fact if you have multiple lines of code in a <td> I go ahead and give the start and end td tags their own lines and indent the code block inside

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 8:05 pm
by VladSun
As I already mentioned, I think, there are no more deeply nested HTML tables nowadays - CSS and HTML have made a big progress since the days everything had to be put in tables in order to get a page layout. Even with pure XML, which I believe has the deepest hierarchy, every one uses well formatted tab indentation.
So... indentation is a must :)

PS: I would only agree with what jshpro mentioned - ternary operators (but not the nested ones!) are exceptions. But in fact, they return a value, so ... they are not really statements...

Re: Code indentation... outdated?

Posted: Fri Nov 21, 2008 8:19 pm
by VladSun
Well, it's a bit off topic but it's close, so I'll ask it:
Why, even professional ones, IT guys use one letter table names aliases in their SQL queries. And it's worse - the more complicated a SQL query is, the more people tend to use aliases. It's like using a one-letter-named variables in programming language, but it seems that while nearly nobody do this in his source code, a lot will do it in SQL...
I really can't understand it :(