New language on top of PHP?

I am a PHP developer. I like PHP! This is a really good language if you know how to use it, but I know that it sometimes allows a very bad design .

It reminds me of JavaScript, which has good parts and bad parts. One specific project, CoffeeScript, tries to focus only on the good parts, forcing you to write good code.

I thought if something like this could be done with PHP ... A new syntax that will be compiled only for good PHP code that enjoys all the new and interesting things that we can get with PHP 5.3.

So, ahead of some people, I will 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 many good features and ideas.
  • There are many good libraries in PHP.
  • ...

So my real questions are here ...

  • Is this a stupid idea? Why? Do you think CoffeeScript is stupid?
  • How does someone start creating a new language on top of another? I don’t know anything about this, but I would like to know. Where to begin?
+49
programming-languages php language-design
Jan 15 2018-11-15T00:
source share
11 answers

The idea is certainly not stupid, especially if it is well executed.

I like coffeescript a lot, but it has an approach that also has flaws. Debugging a coffeescript script still requires you to read the generated Javascript code, which can be tedious since you didn't write it yourself.

I realized that Jeremy Ashkenas, creator of coffeescript, started working on coffeescript after reading “Create Your Own Horrible Programming Language” by Marc- André Cournoyer .

Good luck

+12
Jan 15 2018-11-15T00:
source share

The reason CoffeScript is a good idea: if developers want to run code in a client browser, they have to use javascript; therefore, the only way to program in another language is to allow the conversion of that language to javascript.

I'm not sure if the same goes for server side programming. If you have problems with PHP and want to use a new language, there is no real advantage to having this 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.

+9
Jan 15 2018-11-15T00:
source share

If PHP, something like sass for CSS, I would be interested. But what would you like to add? Or do you just want to feed the bad?

And what would you consider bad?

+3
Jan 15 2018-11-11T00:
source share

Hehe, great idea. My thoughts are some controversial ...

There are precedents for the civilization of bad languages, placing syntax preprocessors in front of them.

  • In the early days, Unix Fortran was popular and was the only portable language because most machines did not have a C compiler. But the vanilla fortran of the day did not even have a block structured with if-then-else, just a dumb single-task if or if-goto. So, Ratfor language was implemented as a preprocessor for Fortran-66.
  • I believe there were Cobol preprocessors (is there?) That supposedly dealt with the verbosity and limitations of the early Cobol dialects.
  • Until today, Unix-derived systems ship with the m4 macro processor.
  • Several CSS preprocessors are available today, most notably Sass and LESS .

But...

  • Just let him die, and the faster the better
  • The problem is not the syntax.
  • I do not see much JavaScript-PHP concurrency. JavaScript is a great language. This is similar to PHP.
  • I'm not sure why you say PHP is a great language. This is one of the worst. Every worthy feature is a fix or reboot in the latest version.
  • As you already noted, there is already an installed version of PHP: it is called Ruby and, as a language, it is almost perfect. There is another fixed version called Python . The world will be better in the long run if we maintain better systems.
+3
Jan 16 '11 at 20:09
source share

Writing a PHP syntax transformer is likely to be a neat project.

However, remember that the standard PHP library is a huge mess. Cleaning this facility would be a much more important task.

+2
Jan 15 '11 at 3:30 p.m.
source share

The more I think about it, the more unrealistic it sounds. The reason is simple: in fact, they are such language processors. Two of them (although they do not use PHP as an implementation, only as a compilation goal) can be found here . But just nobody uses them.

Yes, if the compiler itself was written in PHP, perhaps more people will use it. But I really can't figure out how to get this popularity in order to be a decent job.

Another big problem is that people are mainly used for their wonderful code highlighting, completion code, IDE code verification. Without IDE support, perhaps only someone will use it (and IDE support can only be obtained because many people use it ...)

Thoughts?

+2
Jan 20 2018-11-18T00:
source share

Here now. A new language , which is PHP, is CoffeeScript for Javascript. (Ie, awesome.)

SNOWSCRIPT

Snowscript code is as follows:




fn how_big_is_it(number) if number < 100 <- "small" else <- "big" 

PHP output is as follows:




 function how_big_is_it($number) { if ($number < 100) { return "small"; } else { return "big"; } } 

Now he needs to.

+2
Sep 30 '13 at 13:01
source share

I already thought a lot about this. PHP is just messy at some points.

In fact, I already have a PrePHP project dedicated to providing PHP 5.3 with PHP 5.2 functionality. But it adds some minor language features, such as func()[0] . I have not developed this project for some time, and it is definitely not “clean”, but it shows that what you want is possible and even not so complicated.

If you are serious about this, I completely agree to cooperate with you.

+1
Jan 15 2018-11-15T00:
source share

I see how to write compilers in JavaScript (because the network puts it on us), but it sounds like a waste of time.

haXe is already doing this, although it is not specifically aimed at PHP (related to the Wikipedia article, not to their site, I am afraid that I will be operated if I am on this site ...)

PHP is easy to deploy anywhere

... like its vulnerabilities.

I know this sometimes allows a very bad design.

This is a bit of an understatement, it doesn't even have a modular system, there is no encapsulation, and it has a lot of dumb things, such as dynamic name resolution .

PHP is pretty slow as it is, do you really want something an order of magnitude smaller?

Java is much easier to deploy anyway and allows you to go to the bytecode level if you want. Java also gives you access to moderately reasonable libraries.

+1
Jan 25 2018-11-11T00:
source share

A very interesting idea, and if it comes to its senses, I think that I will not participate in :)

To get started, you can check and read this position http://www.amazon.com/Masterminds-Programming-Conversations-Creators-Languages/dp/0596515170 (read now). It makes it clear how difficult it is to maintain your own language.

0
Jan 15 2018-11-15T00:
source share

I agree that PHP can definitely make some improvements, right now it allows too much cheating.

Some things I would like to see

  • Static printing
  • Indentation Required
  • Proper use of objects (using arrays as objects is just plain silly)

And again, maybe I should just give up PHP and start working with Ruby or Python.

0
Jan 15 2018-11-11T00:
source share



All Articles