Yii Framework Forum: Do you care about indentation? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Do you care about indentation? Rate Topic: -----

Poll: Do you care about indentation? (24 member(s) have cast votes)

Do you care about indentation in ...

  1. PHP and JavaScript source code (9 votes [37.50%] - View)

    Percentage of vote: 37.50%

  2. + HTML source code of view files (14 votes [58.33%] - View)

    Percentage of vote: 58.33%

  3. + Final HTML output (1 votes [4.17%] - View)

    Percentage of vote: 4.17%

Vote Guests cannot vote

#1 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,057
  • Joined: 16-February 11
  • Location:Japan

Posted 02 May 2012 - 11:22 AM

A bad indentation is a torture.
I could hardly understand why so many people could post their code with badly broken indentation in the forum. :(

But at the same time, it has been very long since I gave up the useless effort to output the final HTML with "correct" indentation. :P

So I'd like to know what you think about indentation.
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,341
  • Joined: 12-October 09
  • Location:Croatia

Posted 02 May 2012 - 11:26 AM

NOTE: moved to proper section (General PHP Topics instead of General Discussion for Yii 1.1.x)
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 02 May 2012 - 05:11 PM

I vote for the 3, PHP, JS, HTML and final output.

Why is it difficult for you? Of course, sometimes it doesn't work as expected, but I've finally set my IDE to spaces and automatically convert any tab in my sources and switch it to 4 spaces.

I use Komodo Edit (the free version) for Mac OS X and it works fine. Of course, in some older projects, it was very far from my goals...
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,057
  • Joined: 16-February 11
  • Location:Japan

Posted 03 May 2012 - 12:23 AM

Um, maybe I was not clear enough. ::)

Yes, we can write views, partial views or widgets so that they will produce a piece of HTML output that has a clean indentation. Some tools have clever functions to help us do it.

But once you have implanted a partial view or a widget in a view, and put the content view into the layout view, it's impossible to maintain a clean indentation in the HTML output as a whole.

I once had a chance to read a code trying to produce a well indented HTML output as a whole.
In it, the HTML fragment codes had lengthy leading spaces so that they could fit well into the main code. And some utility subroutines had a parameter named 'indent_depth' in order to change the leading spaces. And what you've got after all is a set of source codes that are very hard to read and maintain.
0

#5 User is offline   SapporoGuy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 25-December 10
  • Location:Sappor Beer Refinery

Posted 03 May 2012 - 01:46 AM

For code, yes, I'm very anal retentive. For what it looks like in view source of a browser ... I gave up.
0

#6 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 03 May 2012 - 07:13 AM

Voted for #2. It'll just leave me with the feeling of having written clean and reproducable code. As for the finalö output: I gave up on that a long time ago. If I generate (X)HTML via XSL/T, I tend to strip unimportant whitespaces alltogether. Pages compress a bit better that way.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#7 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 03 May 2012 - 08:51 AM

I voted 2.

Because I want to be able to compress the output to the browser.

Human readability is not really a concern to me, performance is.

However, when debugging, readable page source is a godsend.
So I want to toggle it.
"Less noise - more signal"
0

#8 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 03 May 2012 - 08:55 AM

View Postjacmoe, on 03 May 2012 - 08:51 AM, said:

However, when debugging, readable page source is a godsend.

There's Firebug for that B)
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#9 User is offline   Junior - df9 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 416
  • Joined: 24-May 09
  • Location:Brazil

Posted 03 May 2012 - 10:52 AM

Voted 2...imho, final output is important only to machines (like .exe code in compiled languages)

To developers, just give a good source code

Also, totally agree with JacMoe and Da:Sourcerer whitespaces in final output are bytes do download and Firebug does its job very fine

;)
______________________________________
Junior
df9.com.br
Linux Registered User #364954
GNU/Linux: together we're ready!
0

#10 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 03 May 2012 - 11:34 AM

gzip FTW :)
0

#11 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 03 May 2012 - 01:29 PM

The performance of deflate/gzip/bzip2 depends on the input ;)
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#12 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 03 May 2012 - 02:47 PM

View PostDa:Sourcerer, on 03 May 2012 - 01:29 PM, said:

The performance of deflate/gzip/bzip2 depends on the input ;)

Well I said gzip because I voted for max indentation, so that gives lots of useless spaces for the browser's interpretation.

gzip (any?) compression algorithm should be effective because we're talking about HTML (text) files.

My home page with very good HTML/CSS separation weighs 18,534 bytes for the HTML alone (230 lines). It's gzipped to 5,256 bytes. With no indentation at all, the same HTML weighs 14,682 bytes. When gzipped, it's 5,039 bytes.

See my point? 200 bytes are imho worth the indentation. And I'm not even using mod_deflate because I don't have it on my shared host.

Now, according to my experience, sometimes proper HTML output indentation is necessary because a closing tag is possible to miss, and browser interpretations can vary, especially prior to HTML5 (which introduces optional closing tags by design). And Safari inspector (the one I use most for HTML) show only beautified/indented and even closed-tag HTML code, so it's not the exact copy of the source. I think I remember FF has the same behavior… but maybe I'm wrong.
0

#13 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 03 May 2012 - 03:47 PM

View Postbennouna, on 03 May 2012 - 02:47 PM, said:

Now, according to my experience, sometimes proper HTML output indentation is necessary because a closing tag is possible to miss, and browser interpretations can vary, especially prior to HTML5 (which introduces optional closing tags by design). And Safari inspector (the one I use most for HTML) show only beautified/indented and even closed-tag HTML code, so it's not the exact copy of the source. I think I remember FF has the same behavior… but maybe I'm wrong.


Output has really nothing to do with the source code - HTML and PHP.
Indentation matters for that.

What gets sent to the browser, however, is none of our concern.

I usually compress the heck out of my CSS too..
"Less noise - more signal"
0

#14 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 03 May 2012 - 03:52 PM

View Postbennouna, on 03 May 2012 - 02:47 PM, said:

gzip (any?) compression algorithm should be effective because we're talking about HTML (text) files.

Yes, indeed. But in my experience, (X)HTML with all unnecessary whitespaces (that includes CRs, LFs and tabs) stripped tends to compress even better. It's all about getting the last bit out of it B)
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#15 User is offline   Tropi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 73
  • Joined: 30-November 11

Posted 03 May 2012 - 05:51 PM

Imo with gzip on its not worth the stripping. 200 Bytes more just for white spaces even seems quite high to me. Even with a huge amount of visitors like wikipedia or youtube don't bother with this.
Also if you consequently stip white spaces you will have to have 2 different view files one for editing and one (stripped) for publishing. Imho its not worth it for HTML.

I do care about indentation, but usually auto format works pretty well, so it's not a big issue for me.
0

#16 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 04 May 2012 - 12:46 AM

Hm, read again how I generate my output. Stripping them is basicaly a free operation by specifying
<xsl:output method="html" indent="no"/>

programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#17 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,057
  • Joined: 16-February 11
  • Location:Japan

Posted 04 May 2012 - 06:08 PM

View Postbennouna, on 03 May 2012 - 02:47 PM, said:

Now, according to my experience, sometimes proper HTML output indentation is necessary because a closing tag is possible to miss, and browser interpretations can vary, especially prior to HTML5 (which introduces optional closing tags by design). And Safari inspector (the one I use most for HTML) show only beautified/indented and even closed-tag HTML code, so it's not the exact copy of the source. I think I remember FF has the same behavior… but maybe I'm wrong.


Yes, we sometimes have to examine the raw html output to debug. The raw html can have errors like missing opening/closing tags or overlapping tags. But those errors will be covered up by the browsers' parser, and we will see only the corrected DOM tree.

So I admit that cleanly formatted raw html output has some advantage. But it is very small and not worth the effort. We can use our favorite editor to check the matching of tags, and it doesn't matter how beautiful the html is indented when we do that kind of debugging.
0

#18 User is offline   mahan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 15-February 12
  • Location:Philippines

Posted 08 May 2012 - 04:30 AM

for me indenting php and javascript codes is a must first. why it because these are the codes the produces the html code in your views(this is usually my case). And lastly indent the html code in your views.. its really a torture to see a unindented code hahaha

anyways why indent the html output code? hahaha is there any good man can perfectly indent a html code after it is produced by server-side code to the client-side?
if there is... then TEACH ME!! ^___^
0

#19 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 08 May 2012 - 05:32 AM

Well, you could pass it through tidy, which can repair broken HTML and take care about indentation at the same time. However, I found tidy's output rarely statisfying <_<
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users