46 comments

[ 3.6 ms ] story [ 96.0 ms ] thread
Not sure where to report this, but there doesn't seem to be a way to use 5.3 functions with 'use' variables.

Example:

    $shared = 3;

    function ($a) use (&$shared) {

      echo "In function before assignment: shared: " . 
$shared;

      $shared = 5;

      echo "In function after assignment: shared: " . $shared;

    }

    echo "After function: shared: " . $shared;
Why not just leave the "{{ }}" out and assume the mammouth file is 100% PHP?
Probably because then you'd have to have a templating language implemented in a templating language in order to render templates.
At the very least it'd make more sense to invert the expectation. {{<html>}} instead of {{php}}html{{php}}.

The way around php has it is both annoying, since most php is not mere template anymore, and error-prone, thanks to the potential problems from trailing whitespace.

> thanks to the potential problems from trailing whitespace.

You are supposed to leave out the closing ?> in the PHP file - then you don't have that problem.

Inverting doesn't really make any sense:

    <P><?=$message?></P>
The HTML is primary, the PHP is used to output whatever is needed.
I'm aware you're supposed to leave out the closing ?>, but a lot of people don't. In fact, the example on the front page of this project doesn't leave out the trailing }}, either, incidentally.

As for your little snippet, inverting does make sense:

    <?php
      // ... 1000 lines of php
              ...?><p><?=$message?></p><?...
      // ... 1000 lines of php
    ?>
But tacky little examples aside, there's nothing stopping <?= tags from working just as they always have once you've escaped into html.
Very cool, but it looks like its just a different syntax for PHP. What's the long term goal for this project?
I don't see the benefit of this, it basically seems to strip out semicolons, dollar symbols and a different function syntax.. I suspect it's very limited (for example I see no object support, let alone traits, generators, etc) and could further complicate deployment. Can you summarise the benefits and strategic goals of the project?
This is what I was thinking. CoffeeScript wasn't just syntactical sugar, it was actually there to help instill best practices of JS.
Also, they missed out on fixing possibly the second* silliest part of PHP: horrible inner functions.

* Edit: I just remembered PHP's "barewords".

Well I suppose this is very early days for the project, and syntax improvements have not been added as yet, but I see this as a worth-wild exercise if it does have some influence over php in the future like coffeescript did to the javascript world.

I think you judging it on a premature release. Maybe he is looking for your suggestions before going down the improvement path.

Assuming it continues to develop, I could see the appeal. When you consider how widely available PHP is and how one of the biggest complaints is the inconsistency in the design of the language, it makes sense to take advantage of a cleaner way to interact with the ecosystem.
but why?
Why not?
Because it will introduce another layer of bugs and corner cases on top of the already existing ones in PHP.
Or it could make the php bugs and corner cases impossible to access, and produce far more reliable PHP code.

Edit: As child post asked: That is the purpose on making something like this or coffeescript. We may all know the edge cases and bugs and know how to write pure php that gets around this, but why should we? Shouldn't our tools serve us and not the other way around? Something like mammoth might actually bring me productivity and enjoyment - which I think in the end is what drives developers.

But, as with Coffeescript/JS, wouldn't the better alternative be to learn those bugs and edge cases and code it up properly in the original language to begin with?
snarky response: why use an programming language to manipulate memory and just code in assembly?
I don't know about productivity, if you look at the side-by-side comparisons, the savings are generally one or two lines at most.

There's nothing in there that actually helps with the idiosyncrasies of PHP -- for example, returning a sane default when accessing nonexistent array elements.

Also, PHP 5.4 already has the JS-style array notation.

And I really have to wonder about the enforced breaks in their implementation of switch/case, because there are times when you do want to fall through to the next case.

Its too early to judge that it makes no improvements, because it does not claim to yet! It currently is only slightly reducing the weight of the code - it doesn't even support classes yet!

I am sure if it matured, you would start to identify way in which it could improve PHP by hiding PHP gotchyas, and doing all the boilerplate to get around them.

I think it was about time someone does this. Not sure what will come out of this, but coffeescript was radical for js, maybe this can also have that influence on php.
I agree. I had considered making something like this before, but didn't know where to start. I think things like this are a boon for the php community.
But in the browser you're forced to use JS. On your server you can run anything you want, so I see no point to this.
I think you are missing the point of this. Similar happened when coffeescript was created, people didn't understand what is use-case. This is not to say this will do the same thing as cs.
How come you guys compare with it CoffeScript? Compiling to JS makes sense because that’s how the code should be distributed. That’s what browsers understand. But why should a new language come to compile to PHP? Why not build a first-class language?

CoffeeScript took off because that was the best way to write client-side code with a cleaner language/syntax. But for server-side, if someone wants a better language/syntax, there are a lot of options to choose from and you don’t have to continue with PHP if you don’t like it.

PHP is still the only option on many, many shared hosting services. Less common over time, but imagine the amount of legacy code that requires PHP libraries or frameworks. If newcomers wanted to ease their development with a more concise language, that holds the same opportunities and difficulties anyone chosing CoffeeScript, Scala, etc. in development has made.
I agree at first glance you could see how it would seem to be a waste of time, but I think you underestimate how big of a foothold PHP has for building websites and applications. There are A LOT of php developers.

Ease of deployment with PHP, and the run anywhere on any shred hosting service really is a game changer for people learning how to code on the web.

I think this project has the ability to build a language that could hide allot of the things developers do not enjoy about PHP while still keeping the huge platform already existing for cheap hosting and integrating with existing code bases.

it's $5 for a vps these days.

why would you need shared hosting?

Previous replies had great points, but I also imagine it would be useful for developers who are extending existing PHP codebases. I have to write Drupal and Wordpress plugins/themes pretty often and I get frustrated at simple things like starting variables with dollar signs when I have to switch into PHP mode. Not sure if I would use this, but it is interesting.
I see a great potential in that as a learning tool for kids, reminds me of basic and logo. Also,
I feel like the biggest problem with this, aside from questions of how much it actually improves things, is that it's written in js. It's a bit of a smell issue that you need to install a whole other runtime environment to use it. It suggests a lack of faith in the engine of the language itself, and that's not a good thing.
I don't see it that way. This is a good example of using a tool that is proven to do what it does well (coffeescript) and also assists adoption by allowing someone to play with it easily in the browser. You dont need a whole other runtime to run the outputted PHP either, its a developer tool - are you saying if all of your developer tools are not written in the same language your programming in that is a slight to your work? I use jetbrain's rubymine to write rails apps, should I think it is a smell that my ide is not written in ruby?
Unfortunately there isnt good PEG tooling in php, pegjs is incredibly easy to use so i can see why they went with it
Why would you compile to PHP when you could compile to native machine code, or run directly in a VM? This isn't the browser where we have a constrained environment.
I think the idea is you can target PHP so as to write code that is compatible with a particular Web development ecosystem while avoiding PHP syntax.

For example, if I had Wordpress site running and needed to write a plugin or an extension I'd rather do it in something other than PHP.

I've not used Mammouth so I don't know if plays out nicer than just plain PHP, but I like the idea.

If you already have a project that uses php and can't migrate it all to a more favorable language. You can use some language that compiles to php and just include this compile into your build step.
Would have been great, had the compiler been written in PHP too.
very cool - gj

comparatively how feature complete is it to snowscript?

if you wanted to use this in say laravel4 blade templates, how do we make sure we dont lose the speed of the "im using previously genereated opcodes" cacher (is that thing even always on or is it part of Zend idk), i dont want a speed hit there.

How are you supposed to do multiple values in a switch if there is no break command?

And why is it that some of the case values in the documentation are followed by "then", and some are not? It seemed random.

Perhaps it's similar to Go where the default is to break, and you have to explicitly say pass.
It says that and compiles to &&.

What if you want to do:

    checkValue($val) or die('bad input');
It's a very nice way to write code since it's very clear.
This example seems just plain wrong:

  for($_i = 0; $contat > count($contacts); $contat++) { 
  $contat = $contacts[$_i];
  echo($contacts);
  }
It's also unnecessary, you can just do this:

    foreach ($contacts as $contact)
        echo $contact;