Designing a HTML page can be complicated, especially if client requires complicated things, animations and other effects, pixel precision, and compatibility with older browsers. Also the page may contain non-trivial JavaScript code. Mix it up with PHP code (or Java code), and you get something very complicated. If you do some change in design, it may break the code. If you do some change in code, it may break the design. In a larger team you can have one person who is HTML expert but not a programmer (or a very bad programmer), and a coder who is not a HTML expert. If you make them both edit the same page, it is unpleasant for both of them.
Unfortunately, things like this are done very often. I often see it in Java web development. In theory, you have all the tools you need, so you don’t have to put any Java code in the JSP files. (There are special tags for “if then else” and “for each”, which is all you need in most templates.) But most people do it anyway, just because they can and it’s the fastest way to write it, but then it is horrible to maintain.
You get clean design by separating different aspects of the work. If one file is reading from the database, second file processes the data, and third file formats the data in nice HTML, that’s good. If lines 1-46, 67-78, 89-123, 150-176, 189-235 format the data in HTML, the lines 46-65, 124-128 read from database, and the lines 66, 79-88, 129-149 process the data, that’s bad, because it’s difficult to read. And if something is difficult to read, many problems follow automatically; it’s difficult to find bugs, it’s difficult to make changes.
Even if I write a simple PHP file, I always put code in the first part and design in the second part, clearly separated. With a larger project, it must be two different files.
Designing a HTML page can be complicated, especially if client requires complicated things, animations and other effects, pixel precision, and compatibility with older browsers. Also the page may contain non-trivial JavaScript code. Mix it up with PHP code (or Java code), and you get something very complicated. If you do some change in design, it may break the code. If you do some change in code, it may break the design. In a larger team you can have one person who is HTML expert but not a programmer (or a very bad programmer), and a coder who is not a HTML expert. If you make them both edit the same page, it is unpleasant for both of them.
Unfortunately, things like this are done very often. I often see it in Java web development. In theory, you have all the tools you need, so you don’t have to put any Java code in the JSP files. (There are special tags for “if then else” and “for each”, which is all you need in most templates.) But most people do it anyway, just because they can and it’s the fastest way to write it, but then it is horrible to maintain.
You get clean design by separating different aspects of the work. If one file is reading from the database, second file processes the data, and third file formats the data in nice HTML, that’s good. If lines 1-46, 67-78, 89-123, 150-176, 189-235 format the data in HTML, the lines 46-65, 124-128 read from database, and the lines 66, 79-88, 129-149 process the data, that’s bad, because it’s difficult to read. And if something is difficult to read, many problems follow automatically; it’s difficult to find bugs, it’s difficult to make changes.
Even if I write a simple PHP file, I always put code in the first part and design in the second part, clearly separated. With a larger project, it must be two different files.