I realized I have to write down a convention specification about HTML, JavaScript and PHP coding for me and my team.
In web development, just like in C++, I'm definitely a fan of indentation and comments.
Nonetheless, often in my work I encounter HTML+JavaScript+PHP code which suddenly brings up the headache.
I'm trying to make my code readable, but what seems to be better to me (to indent & comment) seems not to fascinate my teammates, so I was wondering if there is a best or at least shared good practice when writing "hybrid" documents just like today's web pages, which day by day become more and more complex.
I'm aware of the fact that probably it is in the nature of today's web pages' code to be a little bit intricated, but I wonder if a good convention concerning these aspects already exists.
Best Answer
Some general rules I follow:
General
JavaScript
bind
call, however putting it in it's own function will increase the flexibility of your code.setTimeout(function(){ /* Do something */ }, 1000);
instead ofsetTimeout('doSomething', 1000);
var
.HTML
<br />
's in there to add space, adjust margins and CSS rules.hide
,clear
,error
, etc.<head>
. Worry about optimizing (moving stuff around) when it presents a problem.PHP
includes
to your advantage.Perform if checks on preconceived fail-secure values.