
Mammouth is a small language that compiles into PHP - jamesbritt
http://btwael.github.io/mammouth/
======
martin_
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?

~~~
dmak
This is what I was thinking. CoffeeScript wasn't just syntactical sugar, it
was actually there to help instill best practices of JS.

~~~
lukeholder
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.

------
mostafah
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.

~~~
lukeholder
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.

~~~
AdrianRossouw
it's $5 for a vps these days.

why would you need shared hosting?

------
tmzt
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;

~~~
scragg
[https://github.com/btwael/mammouth/issues](https://github.com/btwael/mammouth/issues)

~~~
tmzt
Thanks, I didn't see a Github link on the page but I could have missed it.

Created:
[https://github.com/btwael/mammouth/issues/1](https://github.com/btwael/mammouth/issues/1)

------
AndyKelley
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.

~~~
jamesbritt
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.

------
desireco42
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.

~~~
Raticide
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.

~~~
desireco42
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.

------
scragg
Why not just leave the "{{ }}" out and assume the mammouth file is 100% PHP?

~~~
cheald
Probably because then you'd have to have a templating language implemented in
a templating language in order to render templates.

~~~
jacques_chester
Welcome to the PHP ecosystem.

------
aarondf
Very cool, but it looks like its just a different syntax for PHP. What's the
long term goal for this project?

------
stormbrew
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.

~~~
lukeholder
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?

------
emersonrsantos
I see a great potential in that as a learning tool for kids, reminds me of
basic and logo. Also,

------
ars
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.

~~~
randartie
Perhaps it's similar to Go where the default is to break, and you have to
explicitly say pass.

------
ars
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.

------
growt
This example seems just plain wrong:

    
    
      for($_i = 0; $contat > count($contacts); $contat++) { 
      $contat = $contacts[$_i];
      echo($contacts);
      }

~~~
krazymelvin
It's also unnecessary, you can just do this:

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

------
z92
Would have been great, had the compiler been written in PHP too.

------
tmpl0908
but why?

~~~
Killswitch
Why not?

~~~
retrogradeorbit
Because it will introduce another layer of bugs and corner cases on top of the
already existing ones in PHP.

~~~
lukeholder
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.

~~~
Gigablah
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.

~~~
lukeholder
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.

