I was recently thinking about this: (1) PHP is a horrible, horrible, horrible language, but (2) many people use it anyway. It means it does some things right (at least for the given set of people), but it also does so many things wrong. Switching to Perl, Ruby or Python is apparently not seen as a good choice by the PHP users, because those languages miss… something. (Perhaps a simplicity for a total newbie, e.g. not having to think about libraries, etc.)
In my opinion, the good solution would be to make a new language “PHP done correctly”. (Of course it would have different name, for copyright reasons.) It should have all the advantages of PHP, without the stupid design choices. If done correctly, it has a potential to gain millions of users (current PHP users). Some thoughts about the language:
visually similar to PHP. We are trying to steal their user-base, right? So I would keep the “<? … ?>” syntax for inserting code into HTML page, and a dollar prefix for “$variableNames”. The goal is to make a PHP user look at the “Hello World” examples or the new language and think “Oh, it’s just like PHP”, because learning a new programming language is an inconvenience. (By the way, using dollars for variables is a good way to avoid naming conflicts with keywords.)
there should be a web tool where you can copy-paste your code and it will highlight all errors. Syntax errors, wrong function names, etc.
the first version should support the most important things PHP supports now. For me it would be displaying a text and connecting to a database.
it should support namespaces and classes, done correctly. These may be different from PHP, because noobs (most of the PHP userbase) don’t understand them anyway, so it is a good opportunity to improve the language design. At this point we don’t have to be backwards compatible.
it needs to be distributed with a lot of tutorials. Many beginners want to google their solutions. So the product website should include an example discussion forum, an example database editor, etc. All these examples as simple as possible.
variable declaration optional (sorry, most people want it like this), but include a command that changes it (like “use strict” in Perl).
For a few months in 2004 I did a brief stint as a PHP developer. It’s on a few older versions of my CV, which has been thoroughly crawled by recruitment agents. Since then I have regularly received speculative emails from recruiters trying to fill PHP developer positions, sometimes as many as 20 a week.
They all pay a lot less than I could earn elsewhere, so I ignore them, but there is definitely massive industry demand for low-mid level PHP developers, at least in the UK. I suspect this might be something to do with how PHP requires a whole bunch of orbital skills before you can really be effective with it, and if you have those skills, you can probably do something more useful with them than code in PHP.
For example I feel pretty sure that it is a wrong choice to give a very long name “htmlspecialchars” to a function that should be used very often by people who mix their code with page design (most of PHP users). Abbreviating that to “html” would be an improvement.
Inconsistent function naming, such as “isset” but “is_null”; “strlen”, “strpos” but “str_repeat”, “str_strip” also does not provide an advantage. For the new language I would use one of those choices (but silently support the other one as a synonym, for former PHP users).
Is that the only function that starts with “html”?
There are two functions starting with html: “htmlentities” and “htmlspecialchars”. They do almost the same thing.
Is “html” a common variable name?
Variables in PHP must start with $, so it could be only “$html”. There is no possible conflict.
By the way, I think this language design choice is good… well, I would hate to see it in my favourite language, but for a typical PHP user it is probably good that something prevents possible conflicts between variables and other things (functions, keywords, class names).
Some things in PHP can be defended as “better for beginners”, especially for people who actually never want to learn programming beyond using the google-copy-paste pattern. But some things are just pure stupidity, and those should be fixed. And I don’t expect that the authors of PHP will ever fix them; they just seem to make more stupid choices in every new version.
There is Python Server Pages which uses <% ... %> to delimit Python code, but is otherwise very similar to PHP. Using this gives you all of the Python language & standard lib so it satisfies most of the requirements.
However, it should be noted that the PHP nature of mixing logic and templates is (mostly) an antipattern.
A language where whitespace is syntactically significant, used in HTML tags?
<% if condition: %><% action1 %><% action2 %>
How do I know whether action2 is also part of the if block or not; and how do I write the other version?
However, it should be noted that the PHP nature of mixing logic and templates is (mostly) an antipattern.
Yes, but beginners want it, because it has the smallest overhead for trivial projects. Later, when they learn more, they can separate the logic and templates. Here is a code that leads to antipatterns, but is nice to have—if you fix it, it will look much more difficult.
I’ve never used psp, but the documentation page seems to indicate what happens with indentation. It looks like it would be parsed as:
<p>
if condition:
....<b>
action1
</b>
action2
</p>
I have no idea how to get either “proper” behaviour, and I’m not in a position to experiment, but I’m sure it’s possible (that would be a fairly large omission).
Yes, but beginners want it, because it has the smallest overhead for trivial projects. Later, when they learn more, they can separate the logic and templates.
Yes, I agree that it is good for beginners; I was merely mentioning that point.
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.
There are few reasons, e.g. thesequestions. But as an incomplete summary, it means your templates are language independent and it enforces a style of coding and application design that is easier to test and maintain.
(This isn’t to say that logicful templates are never appropriate: for quick hacks and prototyping they are perfect!)
There seems to be a PHP Singularity. (Yeah.)
I was recently thinking about this: (1) PHP is a horrible, horrible, horrible language, but (2) many people use it anyway. It means it does some things right (at least for the given set of people), but it also does so many things wrong. Switching to Perl, Ruby or Python is apparently not seen as a good choice by the PHP users, because those languages miss… something. (Perhaps a simplicity for a total newbie, e.g. not having to think about libraries, etc.)
In my opinion, the good solution would be to make a new language “PHP done correctly”. (Of course it would have different name, for copyright reasons.) It should have all the advantages of PHP, without the stupid design choices. If done correctly, it has a potential to gain millions of users (current PHP users). Some thoughts about the language:
visually similar to PHP. We are trying to steal their user-base, right? So I would keep the “<? … ?>” syntax for inserting code into HTML page, and a dollar prefix for “$variableNames”. The goal is to make a PHP user look at the “Hello World” examples or the new language and think “Oh, it’s just like PHP”, because learning a new programming language is an inconvenience. (By the way, using dollars for variables is a good way to avoid naming conflicts with keywords.)
there should be a web tool where you can copy-paste your code and it will highlight all errors. Syntax errors, wrong function names, etc.
the first version should support the most important things PHP supports now. For me it would be displaying a text and connecting to a database.
it should support namespaces and classes, done correctly. These may be different from PHP, because noobs (most of the PHP userbase) don’t understand them anyway, so it is a good opportunity to improve the language design. At this point we don’t have to be backwards compatible.
it needs to be distributed with a lot of tutorials. Many beginners want to google their solutions. So the product website should include an example discussion forum, an example database editor, etc. All these examples as simple as possible.
variable declaration optional (sorry, most people want it like this), but include a command that changes it (like “use strict” in Perl).
For a few months in 2004 I did a brief stint as a PHP developer. It’s on a few older versions of my CV, which has been thoroughly crawled by recruitment agents. Since then I have regularly received speculative emails from recruiters trying to fill PHP developer positions, sometimes as many as 20 a week.
They all pay a lot less than I could earn elsewhere, so I ignore them, but there is definitely massive industry demand for low-mid level PHP developers, at least in the UK. I suspect this might be something to do with how PHP requires a whole bunch of orbital skills before you can really be effective with it, and if you have those skills, you can probably do something more useful with them than code in PHP.
Outside view: I would suspect that many of the advantages of PHP stem from design choices that seem stupid to you.
This needs to be examined feature by feature.
For example I feel pretty sure that it is a wrong choice to give a very long name “htmlspecialchars” to a function that should be used very often by people who mix their code with page design (most of PHP users). Abbreviating that to “html” would be an improvement.
Inconsistent function naming, such as “isset” but “is_null”; “strlen”, “strpos” but “str_repeat”, “str_strip” also does not provide an advantage. For the new language I would use one of those choices (but silently support the other one as a synonym, for former PHP users).
Is that the only function that starts with “html”? Is “html” a common variable name?
I agree that this is a stupid design choice.
There are two functions starting with html: “htmlentities” and “htmlspecialchars”. They do almost the same thing.
Variables in PHP must start with $, so it could be only “$html”. There is no possible conflict.
By the way, I think this language design choice is good… well, I would hate to see it in my favourite language, but for a typical PHP user it is probably good that something prevents possible conflicts between variables and other things (functions, keywords, class names).
Some things in PHP can be defended as “better for beginners”, especially for people who actually never want to learn programming beyond using the google-copy-paste pattern. But some things are just pure stupidity, and those should be fixed. And I don’t expect that the authors of PHP will ever fix them; they just seem to make more stupid choices in every new version.
There is Python Server Pages which uses
<% ... %>
to delimit Python code, but is otherwise very similar to PHP. Using this gives you all of the Python language & standard lib so it satisfies most of the requirements.However, it should be noted that the PHP nature of mixing logic and templates is (mostly) an antipattern.
A language where whitespace is syntactically significant, used in HTML tags?
How do I know whether action2 is also part of the if block or not; and how do I write the other version?
Yes, but beginners want it, because it has the smallest overhead for trivial projects. Later, when they learn more, they can separate the logic and templates. Here is a code that leads to antipatterns, but is nice to have—if you fix it, it will look much more difficult.
I’ve never used psp, but the documentation page seems to indicate what happens with indentation. It looks like it would be parsed as:
I have no idea how to get either “proper” behaviour, and I’m not in a position to experiment, but I’m sure it’s possible (that would be a fairly large omission).
Yes, I agree that it is good for beginners; I was merely mentioning that point.
Why is it an antipattern?
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.
There are few reasons, e.g. these questions. But as an incomplete summary, it means your templates are language independent and it enforces a style of coding and application design that is easier to test and maintain.
(This isn’t to say that logicful templates are never appropriate: for quick hacks and prototyping they are perfect!)