Why P*?

Many different programming languages are used for web development. This article's target is to show the difference between P* and other languages widely used for this purpose.

Contents:

Designers VS Geeks

Essentially, what web development is all about, is to generate HTML-markup dynamically based on data stored somewhere and on user input.

A web page can be divided into two parts: The code part, which takes care of database and user input, and the HTML-part which takes care of the design.

Sometimes a single person might do both the coding and the HTML, and this person will be comfortable with having these two mixed. However for larger and more complicated web pages, we need proper geeks to do the coding and artistic people to do the design.

Since designers don't understand much programming, they tend to mess up complicated code written by the geeks. This problem forces us to separate the HTML from the program code, and this is solved by only having very simple code (loops, conditions and variables) in between the HTML code which the designers can understand without much effort. Database handling and user input processing is kept by itself out of reach of the designers, and variables are prepared here for the designers to use later.

This technique is called templating, and different languages have different ways of handling this.

What template engine should I use?

On Wikipedia, there's a list of almost a hundred template engines for many different languages. This indicates that there's a real need for templating out there. It also tells us that the languages themselves do not implement templating natively; the template engine is usually an external module.

Languages used for web development typically don't have any special functionality to handle this important part of web design, the developers are left on their own to sort it out. Java, Perl and C# are well known general purpose languages who also are used to generate dynamic HTML-markup.

The widely used language PHP also has to be mentioned. It differs from the other languages in the way that it almost exclusively is used for web design while having no in-language support for anything related to web design apart from the ability to be interleaved in HTML code. PHP provides nothing more than a huge, messy pile of built-in functions which there is no exact count for. Some estimates say around 4500 functions.

The lack of in-language template handling is the reason why P* was created in the first place, P* has native support for templating, it is part of the language's syntax. The text you're reading now is placed inside a P* template block, separated from the program code.

Read more about P* templates in the reference manual

Also, take a look at the source code of this page on Github.

Human Languages and Computer Languages

Different programming languages are basically different ways for us to talk to computers, telling them what to do. Human languages are different methods for humans to talk to each other. Human- and computer languages do of course differ in many ways.

One notable difference is that human languages are much more dynamic than computer languages. It's probably a fact that no human being knows all the words of any language, which are usually tens of thousands in numbers. Humans know the words they need in their daily lives.

A physician probably knows more words in medicine than an average person. When a physician could have used a single word to describe a condition, an average person might have needed to use many words to do the same. The physician's language is therefore efficient to use when talking about medicine.

The same applies to programming languages. You typically want the programming language you use to have special words to help you speed up your coding and make your programs easier to read and maintain. A language used for web development should provide words and tools specialized for the task you're solving.

P* tries to make it easy to talk web design to your computer by providing special syntax for SQL-queries and HTML-templates, doing the dirty work behind the scenes.

Read more about the P* SQL syntax in the reference manual

Source Code Organizing

When you start a new project you need to organize your code somewhere, that is the different files containing the program code. For application projects, some tools used are CMake, Autotools and Visual Studio.

In a web project, the files are usually placed inside the root of the web server. The web server finds them there and calls an appropriate compiler to execute the code.

Some implementations have more complicated solutions, like JSP (Java Server Pages). Here, you often need to precompile classes and put them in special directories for the Java engine to find. The configuration of a JSP environment is somehow complicated, whith lot's of new terminology to learn besides the actual language.

P* cannot be precompiled, and you just use the #INCLUDE-pragma to load other files. Everything is compiled automatically at first run or when the files are modified. This makes development very easy.

It is also easy to learn P* if you already know other languages like Java, C, C++, PHP or Perl. To configure a web server to execute P* is very easy, as P* does not require any configuration itself.

P* programs can usually be run both inside the web server and outside of it using the command line version. This is useful to check for syntax errors while writing your code. You can also fake user input by setting CGI environment variables.

Is P* fast?

If speed is your only concern, you should write your web page in C and compile it as a web server module. However, speed is not only about making a program run fast, it's also about writing fast. The focus of P* is on the latter.

P* internals are written in C++ which is a bit slower than it's daddy, C. Only critical sections are optimized, like text output to the web server. P* also caches programs internally so that the scripts only are parsed once.

Arithmetics, like plus and minus, is slower in P* than in other lanugages. However, you will only notice this if you make a loop run a billion times, in which P* will be a couple of seconds slower than PHP and Perl.

The P* engine is not based on anything else out there, it's completely written from scratch. The only thing P* has in common with other languages is the C-like syntax.

What to do next?

Here's a few reasons why you should consider using P*:

Go ahead and read some more on the documention pages.