Coder Social home page Coder Social logo

moody's Introduction

Moody PHP Preprocessor

What is Moody?

Moody is a small scripting language specially designed for preprocessing PHP sources. Moody itself also contains some modules used for optimizing PHP code, without the need to write any new code. It will just give you an optimized version of your PHP code. At the moment there are not too many automatic optimization modules, but they will be more in the future. :-)

How to write code in Moody?

Moody code is written in PHP comments. Look at these examples of Moody code:

    <?php
     #.myVar = 7
     #.if myVar > 8
      echo 'Hello ';
     #.endif
     echo 'World!;'
    ?>

When preprocessed using Moody, the following code would be generated:

     <?php
       echo 'World!';
     ?>

This example is somewhat useless, but let's say the variable would have a dynamic value (for example obtained through the programs' configuration) and the code in the if block would make a little bit more sense, you could remove unnecessary code from the compiled program. This will save you a check for a specific configuration value on each iteration and - more important in such examples - the RAM used up for simply having code loaded that will never be run anyway.

You can call any PHP function or static method (objects currently not supported) from Moody:

     <?php
      #.randomValue = #.rand 0, 1

      #.if randomValue == 1
        echo 'Do it!';
      #.else
        echo 'Better not do it!';
      #.endif
     ?>

Moody will parse PHP namespaces and PHP constants and even substitute read occurences in the generated code:

     <?php
       namespace MyNamespace {
         const namespacedConst = "abc";

         $someVar = namespacedConst;
       }
 
       namespace {
         const myConst = 8;

         #.moodyConst = 123

         $x = myConst;
         $y = MyNamespace\namespacedConst;
         $z = moodyConst;
       }
     ?>

This would generate the following code:

     <?php
       namespace MyNamespace {
         const namespacedConst = "abc";

         $someVar = "abc";
       }
  
       namespace {
         const myConst = 8;

         $x = 8;
         $y = "abc";
         $z = 123;
       }
     ?>

This also gives you a small performance improvement since the constant does not have to be resolved at script runtime anymore.

Contact

If you got questions about Moody or just want to learn more, feel free to contact me at [email protected]. :-)

moody's People

Contributors

pp3345 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.