Jump to content

Html Vs Php Comments


son

Recommended Posts

I have a really awful question, but am really interested to learn best practice:Worked on a website where some includes have 'pure' HTML and some have PHP to generate page content. The codes of HTML bits show, the PHP bits do not show. Is it common practise to echo those, so if someone looks in source file he/she is not confused that all is well documented apart from all in middle bit? Would really like to have code up to scratch as such...Son

Link to comment
Share on other sites

I'd say:Use HTML <!-- comments --> for HTML-related commenting, and // PHP /* */ Comments for php-related commenting.It doesn't matter if php comments do not show up in client side source code, as any developer having to work with the php source will get the files from the server and therefore get the comments in plain.Just my thoughts

Link to comment
Share on other sites

I'm with justsomeguy on this one. There's no reason to render comments out in the HTML other than to bump up the size of the file that the user has to download (and the server has to serve). The only time you need to read the comments is when you're editing the code and you'll be looking at the PHP when you do that.I haven't done PHP in a while, but in ASP.NET, I might comment my code like so:

<body><%--Something really special might happen here...--%></body>

The file that gets served to the browser looks like this:

<body></body>

Link to comment
Share on other sites

Totally. Comments are for developers, not end-users. The less you can send, the better.But that doesn't mean you shouldn't comment, especially if you're on a team or have the slightest suspicion someone else might need to edit your code eventually. Even you after a month might forget what you're up to.Have you read about self-commenting code? It's a good habit to develop, and can cut down on regular comments a lot.

Link to comment
Share on other sites

I actually have removed comments from both HTML and PHP pages after the page or script has been placed into production. I also 'compress' the css files once the Theme has been proven. I guess it goes back to the days when size mattered. Now, with 2 Gigs of RAM commonly available, it is less critical, but 'back in the day' when RAM was a scarce commodity, it made a huge difference to be supplying comments in Production code. Old habit, I guess.Of course, the comments stay in the Development copy.

Link to comment
Share on other sites

Thanks for sharing your experience. Really appreciate it and got the point that I will leave HTML and PHP comments as they are without worrying too much about the inconsistency of some not showing in source code. It's true the comments are for programmer, not for the general public;-)Son

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...