Monday, July 27, 2009

GoodLooking Demo

Two days ago (technically yesterday early morning, but the two sort of blended together as I didn't sleep in a (successful) attempt to get my sleeping pattern back to something a bit more normal) I wrote about GoodLooking INT02. Today I decided to take a minute and write a demo.

Previously I provided links to the template and the live example. Now, instead, I provide a link to the demo. From there you can have a look at the running example, force it to do a reload and from there you can see the source of the template, of the sample application, of the code connecting the two and of the compiled template.
All of these are actually viewable without looking at the source thanks to two pre-tags around them and an htmlentities that was executed on them. It is important to note that even thought the compiled template is viewable this was, it was not made to be good to the eye - it is very ugly, generated php. Here's the link.

Sunday, July 26, 2009

GoodLooking INT02

I did some work on GoodLooking, my templating engine, again. And I finished a number of goals I had set for myself, and as such I finished the next version, INT02. Note that INT02 is not a release yet, not even an alpha release - INT stands for internal, which is the term I coined for the versions before the releases come along.

GoodLooking is a templating engine, which means it helps you to keep your php code seperated from your html. You'll have one file where you do your php programming and one which is the template. Then you need a couple of lines to tell GoodLooking which file to use, and what variables it should use, which can be in a third file, but can also reside in the same file as the programming logic.

Say you have a script that gets the user's first name, last name and birthday out of the database and put them into the variables $firstName, $lastName and $dateOfBirth. Now we write the following code to use LookingGood:
$lookingGood = new LookingGood('template.tmpl');

$lookingGood->registerVar('firstName', $firstName);
$lookingGood->registerVar('lastName', $lastName);
$lookingGood->registerVar('birthday', $dateOfBirth);
Note that instead of calling registerVar three times, we could also have called registerMultipleVars once:
$lookingGood->registerMultipleVars(array('firstName' => $firstName, 'lastName' => $lastName, 'birthday' => $dateOfBirth));
In either case we could have the following Template (in the file template.tmpl):
<:- this page is a sample page, and this text is a comment (disappears from result) -:>
<head><title>Hello <: firstName :></title></head>
<p>Hello <: firstName; ' '; $lastName :>, my database tells me your birthday is at <: birthday :>.</p>
<: if (firstName == 'Jasper') :>
<p>Have a nice day, Jasper.</p>
<:end if:>
This could lead to a page named "Hello Jasper!", with the following:

Hello Jasper Horn, my database tells me your birthday is at 11/04.
Have a good day, Jasper.
Or if you're your not me, but John Doe, you would get a page named "Hello John!", that looks like this:
Hello John Doe, my database tells me your birthday is at 31/03.
Well, those are simple examples, but it does really show what the engine is about. So.. INT02, what's new?

All of it worked, but it was slow. A few hundredths of a second does not appear to be too much, but in reality it is, if you are getting a number of views on your website per second and it's running on a host that's doing other things as well. A more complicated site than the ones I tested may really bog down a server if the work has to be done each and every time.
So, now it only does once, until you change the template, and then it does it once again. That one time it saves a file, which is basically a very messy php representation of your website, which means it is fast to go from there to your full website. And the messiness doesn't matter, because you are not going to see this code at all. For that matter, you are not going to notice the fact it is being compiled this way at all, as all you do is as I wrote above in the example, the engine fixes the rest for you silently.

A working sample is seen on my site. This is the template (view source to see it decently), and I simply put some constants into the engine, and here you see the result in real time.
INT02 does not have much functionality asides the mentioned yet and it has a funny perk, if you had a compile, it will show how long that took in the source, and it will always show how long the interpreting (from the compiled template to the result take) in the the source in html comments.
I won't make GoodLooking available just yet, simply because it is really advisable not to use it in its current state. However, if you really are interested despite that, let me know (for example, you could write a comment here). The next planned version is INT03, which will have one extra feature, after that there's INT04 in which I make a lot of changes and tie quite a few loose ends together. Then, when I feel I am satisfied with that, I will make an alpha version, which will be available.
Alright, thanks for your time (I can imagine, that was quite a read) and see you again some other time!

Tag Cleansing

Not so long ago, I had posts with tons of tags each, and no two of them shared a tag (alright, that's exaggerated, but still, it's partly true and that's bad enough).
No more!
I just cleaned up my tags. I am now using tags as they should be used, so readers can find related posts.

Anyway, I have an important post that is going to bury this one again, so I am not going to spend too much time on this one. Just be sure to read my important (=next) post!

Saturday, July 25, 2009


I just received a brilliant error from php:

Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /home/a5400048/public_html/Compiler.php on line 551.

I truly wasn't expecting a paamayim nekudotayim either. Further inspection showed it actually just meant "COLON". Php....

What I had done was typed "$class::const", while I actually just meant "class::const". It's that they told me where to look, because that error message is as descriptive as "Error: don't feel like continueing on some statement."

Wednesday, July 1, 2009

Land of Manuals: Factories

Alrighty, I just thought I would pop in and do another installment of the Land of Manuals. Let's start off with a quick recap of what we talked about.
This series takes place in a strange world known as "The Land of Manuals". In his land there are four types of people:
  • Workers: they do whatever a manual tells them, no more no less
  • The Rich: they are rich and they are stupid; autonymous, but stupid. They have their own factories
  • The Rebels: they are rich, but they are smart. They intend to do wrong without breaking the laws, which are enforced strictly but very literally
  • The Writers: they write manuals
I said the series would focus on the Writers, but before we can, we need to get a picture of what this land is like, so I will start with one of the main concepts in the Land of Manuals: Factories. Factories are the de facto standard places to find workers, whereas most other places where you can find Workers are at least somewhat comparable to a Factory.

A good place to start writing about Factories is the service door. Now, in this world one would expect a rather boring door used only by employees. However, in the Land of manuals, it is much more than that. It is where wandering souls (oh, I didn't tell you about those, did I... well just don't worry they aren't really important anyway) are picked up from the street and become Workers. When there's work to be done and the factory has not yet reached its Worker limit, they pick up more wandering souls from the streets and get them to be Workers, when there's more workers than work, they will thrown out the same way they came.

But who does that you ask? Well the management. Let's see who we could use for a management. Writers? No. Rich? No. Rebels? No way. Workers? Check!
So it's workers again, 'ey? Well, yes the Land of Manuals isn't all that complicated, you just don't have many choices beyond the Workers here.

How your management works is decided by two major factors. How it works exactly is a topic for a later time, right now I will just list these factors. First off there is the structure of your factory. In general lines most factories are the same, but take a look at for example the inside of the management's office, and you will find way more changes. Nowadays only a few types of factories are widely used, but in the past many more have been used. This was actually the reason for creating uniform management manuals. The uniform part basically means that you will need a different version of management manual Y if you are using a different factory, but once you are running UMM Y, it appears everything works just the same as all other factories that use UMM Y. There are only a few widely used UMMs.
The main reason for using management manuals, and a management that is, is that it makes things a lot easier for Writers. If every time a Writer wanted to write a manual he or she would have to spend a considerable amount of time writing about getting Wandering Souls from the streets and making them workers, there would be very few manuals, so instead we leave such things to the management.

Once a worker is inside, he or she gets a shirt on which signifies what language he or she will be speaking. Say you need a manual written in English to be done which needs ten guys working on it, (they actually have different languages, but for now ours will do for examples) your management will make sure that they get you ten workers that speak English. However, two of them may also speak German, while three speak French and six of them speak Dutch as well as English; the shirts are just to make things a little easier, they will now know in what language they ought to communicate.

Workers work in teams. The composition a manual needs (one they need at least and one they would like to have, usually) is written on the manual and is there for the management to read. They will find the workers to form such a team and assign them to one of the many, many rooms that are in the factory, where they are left to do their job.
There is often a lot communication between teams or between a team and the management. For example, if a team needs access to a certain book that's in the factory's (yeah, factories have their own libraries, its a strange world), they will tell so to the management and the management will put a library team on it. Note that this all goes according to the manuals, though. The manual those that need the book are using will need to say "ask the management for that book" rather than "pick up that book". And the management's manual will say that if one asks for a book correctly they should put a library team on it - and it also tells them the composition of such a library team.

That's basically all I wanted to tell you about factories for now. There's a few more general concepts to discuss, but from there we will be able to take the perspective of the writers, which is what this series is all about.