New language on top of PHP?
I'm a PHP developer. I like PHP! It is a really good language if you know how to use it, but I know it allows very bad design sometimes.
It reminds me of JavaScript which has good parts and bad parts. One particular project, CoffeeScript, tries to focus only on the good parts, forcing you to write good code.
I was thinking if something similar could be done with PHP... A new syntax that would be compiled only to good PHP code taking advatage of all the new and exciting stuff we can get with PHP 5.3.
So, getting ahead of some people, I'll ask: Why create a new language on top of PHP if you can just use Ruby or Python or something else?
- PHP is easy to deploy anywhere
- The language itself has a lot of good features and ideas
- There are lots of good libraries written in PHP
- ...
So, my real questions here are...
- Is this a stupid idea? Why would it be? Do you think CoffeeScript is stupid?
- How do someone starts to create a new language 开发者_运维技巧on top of another? I know nothing about this, but I would like to learn. Where to start?
The idea is definitely not stupid, especially if executed well.
I like coffeescript a lot, but it has it's approach has downsides as well. Debugging a coffeescript script still requires you read the generated Javascript code, which can be tedious, since you haven't written it actually yourself.
I've understood that Jeremy Ashkenas, the creator of coffeescript has started to work on coffeescript after reading "Create your own freaking awesome programming language" by Marc-André Cournoyer.
Good luck!
The reason CoffeScript is a good idea is that if developers want to run code in a client browser they have to use javascript; so the only way to program in a different language is to allow that language to be convertible to javascript.
I'm not sure the same really applies to server side programming. If you've got issues with PHP and want to use a new language there is no real advantage to having that language generate PHP.
On the other hand, a language that was very similar to PHP, but fixed some of the flaws would be a great idea.
Heh, great idea. My thoughts, some contradictory...
There are precedents for civilizing bad languages by putting syntax preprocessors in front of them.
- In the early days of Unix, Fortran was popular and about the only portable language because most machines had no C compiler. But the vanilla Fortran of the day didn't even have block structured if-then-else, just a goofy single-statement if or an if-goto. So, the Ratfor language was implemented as a preprocessor for Fortran-66.
- I believe there were (are?) Cobol preprocessors that presumably dealt with the verbosity and limitations of early Cobol dialects.
- To this day Unix-derived systems ship with a macro processor called m4.
- Several CSS preprocessors are available today, most notably Sass and LESS.
But...
- Just let it die, and the sooner the better
- The problem isn't really in the syntax.
- I don't see much of a JavaScript-PHP parallel. JavaScript is a great language. It's kind of the opposite of PHP.
- I'm not sure why you say that PHP is a great language. It's one of the worst. Every decent feature is a patch or repatch in a recent version.
- As you noted, there is a fixed-up version of PHP already: it's called Ruby and, as a language, it's near-perfect. There is another fixed-up version called Python. The world would be better off in the long run if we support the better systems.
It is here now. A new language which is to PHP what CoffeeScript is to Javascript. (I.e., awesome.)
SNOWSCRIPT
Snowscript code looks like this:
fn how_big_is_it(number)
if number < 100
<- "small"
else
<- "big"
PHP output looks like this:
function how_big_is_it($number) {
if ($number < 100) {
return "small";
} else {
return "big";
}
}
All it needs now, is you.
If it would be to PHP what something like sass is to CSS, I'd be interested. But what would exactly would you want to add? Or would you just want to weed out the bad?
And what would you consider to be the bad?
Writing a PHP syntax transformer would probably be a neat project.
However, don't forget that PHP's standard library is a huge mess. Cleaning that up, would be a far bigger task.
The more I am thinking about this, the more irrealistic it sounds. The reason is simple: There actually are such language proprocessors already. Two of them (though not using PHP as implementation, only as compilation target) can be found here. But simply nobody uses them.
Yes, if the compiler itself were written in PHP, probably more people would use it. But I really can't see a way how to get this popular enough to be worth the work.
Another big problem is, that people mostly are used to their awesome code-highlighting, code-completing, code-inspecting IDE. Without getting IDE support probably merely anybody will use it (and IDE support can only be obtained by having many people use it...)
Thoughts?
I can see writing compilers to JavaScript (because the web imposes it upon us), but this sounds like a waste of time.
Haxe already does this, although it's not specifically targeted at PHP (linked to the Wikipedia article instead of their website because I'm afraid I'm going to get exploited if I visit the real site...)
PHP is easy to deploy anywhere
...as are its vulnerabilities.
I know it allows very bad design sometimes.
That's a bit of an understatement, it doesn't even have a module system, has no encapsulation, and has tons of silly things such as dynamic name resolution.
PHP is slow enough as it is, do you really want something an order of a magnitude slower?
Java is much more easy to deploy anyways, and lets you drop down to the bytecode level if you want. Java also gives you access to moderately sane libraries.
This is something I have thought about already often. PHP just is messy at some points.
Actually, I already have a project PrePHP focusing on providing PHP 5.3 functionality to PHP 5.2. But it adds some minor language features, like func()[0]
. I haven't developed this project for some time and it definitely isn't "clean", but it shows, that what you want is possible and actually even not that complicated.
If you are serious about this, I am perfectly willing to collaborate with you.
Very interesting idea and if it come to life i think that i wan't to be involved in :)
For start You may check and read this position http://www.amazon.com/Masterminds-Programming-Conversations-Creators-Languages/dp/0596515170 (iam reading it now). It makes clear how really complicated is to maintain own language.
I agree that PHP definitely could do with some improvement, right now it allows for too much fooling around.
Some things I'd like to see
- Static Typing
- Required indentation
- Proper use of objects (using arrays as objects is just stupid)
Then again, maybe I should just drop PHP and start working with Ruby or Python.
I'm like 8 years too late, but I'll answer anyways for anyone else who stumbles upon this.
Hack is a language developed by Facebook to deal with some of the issues of PHP, since Facebook had a large PHP codebase. Hack adds some nice features on top of PHP such as gradual typing (what TypeScript has) and generics, among other features, and gets rid of some of the more dangerous PHP features. Hack was at one point a superset of PHP, but is no longer completely compatible after removing some of the worse PHP features.
This is slightly different from what you were asking, since at this point Hack has its own interpreter, written by Facebook, but this started out as "better language that compiles to PHP", so I thought it was worth mentioning here.
精彩评论