2009-12-06

New XO game

In my university I had to create another XO game (previous was Yatzee), but this time using PROLOG. I used GNU prolog (gprolog), so if you'll want to test it you will have to obtain this package from your Linux repository.

Game controls are very simple:

 Main:

start_game. - start game in 10x10 field.
Goal is to have 5 figures in line.
put( X, Y ). - put your figure into X:Y

Additional:

start_game( X, Y, Z ). - start game in (X-1)x(X-1) field.
Goal is Y. Forecast depth is Z.
end_game. - end game.
put_for_pc( X, Y ). - put figure for pc into X:Y.
print_table. - print game table into console.
halt. - turn program off.

You can find my source code here. Remember, I am not responsible for anything that might happen with that program. It should work fine, but I do not take ANY responsibility for it. It is there for educational purposes only!

2009-10-23

UPL way

As it usually happens, UPL project is already taking much more time than I thought :) I already have written several drafts, containing basic syntax information and have some final ideas about how programming would look like using UPL.

First of all, my initial idea was to create two versions of UPL: one for stand alone programming and another - for programming inside my own OS. At this point I am not so sure that it was such a good idea. Without first testing an implemented language it would be a crazy thing to start implementing a stand alone version at once. Instead, I decided to create a program that would translate UPL code to PHP and use it for web development.

Why PHP, you might ask. Well, first of all, it is a language that I know rather well :) UPL is expected to be rather dynamic, so PHP becomes handy here as it is interpreted. Quite a lot of ideas of PHP will remain in UPL, so conversion (translation) is expected not to be very difficult. All in all, this is one of the easiest ways to test a new language.

Now, let me talk a little about the UPL way of programming. First of all, this will not be another OOP language, though it will have objects. Instead, it will inherit some features from PBP and procedural programming with modules. I decided to call this type of programming - Utility Based Programming.

Main three terms in UPL are: utility, object and interface.

  • Interface is understood nearly the same way it is understood in OOP languages. The only difference is that interfaces are applied to objects instead of classes that do not exist in UPL.
  • Objects are created from scratch, by being generated inside utilities or by copying another object. This idea of creating objects without classes came from PBP languages.
  • Utilities are collections of procedures (called methods) that are just like static methods in OOP languages. Utilities may also have static properties. Main difference between utilities and classes is that objects may not be created from them.
UPL is called an UBPL (Utility Based Programming Language) because the main thing in it is utility, not an object. In OOP, programmers are usually trying to encapsulate all the methods and data in objects (created using classes), while in UBP, control rests in utilities. Why is that so? Read on...

*** A little bit of OOP criticism

First of all, consider that you are using some framework that provides XString objects in OOP. Framework is not a magical thing and its creators were not able to predict all the situations XString could be used for, so you might have to extend its functionality. At this point, OOP provides inheritance mechanism that should solve this problem, but what if XString changes in later framework versions? You would have to rewrite the whole inheritance tree and don't say that XString wouldn't change... Meet the reality :) Everything changes and this is a weak point of OOP as OOP developers are expected to write a perfect code which is impossible. And that is not the only problem of inheritance... It encourages polymorphism, complex code behavior and makes code hardly readable for new developer assigned to some OOP project.

Another situation with same XString... What if there is a method somewhere that requires String (without X) as argument? It is probably created by another manufacturer who didn't know anything about XString. XString and String classes are not related by a mechanism of inheritance and implement the same thing in different ways, so you would have to write some wrapper to solve this problem. If XString hasn't been written wisely, it might become a huge problem because of encapsulation (note that encapsulation is encouraged in OOP)...

***

Now, lets go back to UPL. First of all, there is no inheritance, because there are no classes. Dedication is a much better solution than inheritance, because only user (in case of inheritance it would be called a child) would depend on its supplier (parent), but user's interface itself could remain the same for its own users. Also, by using dedication, you will always see, what is done in some particular utility - there are no derived methods or properties.

When talking about objects, you can always change their behavior by adding new methods and replacing the old ones. You may be sure that objects will do what they are expected to do by using interfaces.

What about the XString vs String situation? In UPL object should be used to define complex type instances only. Those can be structures of existent simple types, database connections, network connections, I/O types and so on... Connection details and similar things should be encapsulated but object itself should return and ask for as simple data as it is possible: strings, integers, arrays, booleans... Objects should not be supplied to other objects. All control sort of work should be done using utilities. In this way even if there were two different String objects, it would be very easy to convert to one from another. More than that, using such simple objects would encourage different programmers to use same interfaces causing much less problems...

Note that in OOP there is usually a problem with class constructors, because they are not able to return a value in case of failure. In UPL there is no such problem because objects may be returned by utility methods. If something fails, simply return false instead of an object or throw an exception.

UPL is better than OOP in a lot more different ways and I will not try to cover them in this article. Instead, I will talk about this later in UPL manual.

Several more important things to know about UPL:
  • Dynamic typing - there are no static types, type conversions are not necessary;
  • Dynamic code - code may be stored in variables and manipulated as if it was data;
  • Strict coding standard - programmer must write code in a strict way in order to be able to compile;
  • Minimalistic syntax - there are as little syntax rules as possible, easy to learn.
More information about UPL will be available later in this blog.

2009-09-28

Yatzee game

In the beginning of this year I was developing 0X game on JavaScript and called it Jazee.

It is possible to configure this script to any size of the board and any winning length of figures. In this case board is of size 10x10 and winning condition is 5 in a row.

Artificial Intelligence always thinks two steps into the future and is quite clever despite the fact that there are still some stupid bugs left in the code. I am planning to fix them in the near future (if only I have time).

Try this game here: http://asm.alive.lt/jazee.html

Please, do not use this game in any of your own websites without my permission.

2009-09-25

CMS Documentator gets a name

CMS Documentator has been uploaded to code.google.com project under the GPL3 licence and it is now officially called "PDocs".

SVN read-only repository:
http://pdocs.googlecode.com/svn/trunk/

Have fun!

2009-09-23

CMS Documentator alpha

CMS Documentator alpha version is finally finished. This version still has many bugs, unimplemented functions and very poor interface desing, but this project is planned to be continued by a friend of mine - Albertas Jurgelevicius. At some point it might become a very useful tool.

Source code is not yet available, but it will be uploaded to code.google.com under GPL licence very soon. I will post further information here in this blog.

2009-07-30

CMS Documentator progress

CMS Documentator is already able to collect information from a list of projects. All the information is saved in a list of files and no DB is used. I do not use any database in order to be able to commit my documentation files.

Next step is going to be Display class. This class will be used to extract saved data from files. After this step, only front end will be left.

I hope to finish this project in a few days.

2009-07-17

CMS Documentator

Up to this moment I was using PHPDocumentator for documenting my project, but I have realized that it has bugs in it. Sometimes some tags or some lines of comments are ignored and I have already had problematic situations because of this.

To avoid problems in documenting source code, I have decided to create my own documentator. It will be something like a simplified PHPDocumentator version that will not use a single line of code of any other open source project. It is quite possible that I will publish it later in this blog as an open source project.

At the moment about half code is already written and I expect to finish this project in a week (or sooner) as there is nothing difficult there. Here are the tags that will be supported:

@author
@version
@p - PHPDocumentator didn't have this (it is a short for param)
@ap - PHPDocumentator didn't have this (it will be used for a special type of parameters)
@param
@return
@var

All in all, comments will be written much like in PHPDocumentator in order not to reinvent standards and to make portability possible.

2009-07-05

Summertime

The paper about programming paradigms was finished some time ago already, but I am still not sure where and whether at all I will publish it. Perhaps it is not worth publishing all the work, just the results, because it was written in Lithuanian language and I am not in the mood translating it.

At the moment I am migrating from Windows to Linux Kubuntu Jaunty and I am planning to do all my work using it this summer. I am using Dell Inspiron 6400 and the only huge problem that arose is wireless that does not work in Ad-Hoc mode. I didn't succeed in installing ndiswrapper, so I decided to use b43 driver and I guess it has some issues yet.

My main plans for this summer are CMS development and UPL project. I will publish information about them in this blog from time to time.

2009-06-08

Programming paradigms

As I have stated in my earlyer posts, I am writting a paper about different programming paradigms. I already have a full list of those paradigms discussed in it:

  • Procedural
  • Functional
  • Logic
  • Object-oriented
  • Prototype-based
  • Aspect-oriented
  • Concurrent
  • Agent-based.
The paper will be finished in a week, but it is currently being written in Lithuanian language. If everything goes well, I have plans to translate it to English and publish it here, but can't promise anything.

One of the most interesting things for me was searching for an alternative to OOP. During my research I have found many drawbacks of OOP that forces me to think "why the hell do we still use it?". I believe that OOP itself is a harmful paradigm. This is a problem and it has to be realized, discussed and fixed just as "GOTO" crisis had been resolved in the past.

2009-05-23

CMS is alive!!!

I must admit that I had absolutely no time to post news here lately, but I will try to change this situation now.

The CMS system I was talking about in this blog is finnaly in action. To be precise, the first website built on it has been lauched last month. Here is the link: http://www.om.ef.vu.lt.

Despite the fact that my framework is still under alpha development stage, it seems that it works perfectly. It only has basic functionality at the moment, but it is already capable of making website development many times faster.

2009-04-09

Reasons why Opera sucks

First of all, I would like to state that a term "sucks" sometimes can be applied to almost any program or system, so if you like Opera, don't feel abused. In this small article I will describe problems I have faced personaly.

Lots of people say that Opera is able to generate the view of a website almost in the same way as IE does. My experience tells me that this is far from the truth. I don't have much time to dig deep into the issue, but I will give you some interesting examples...

As you might already know from my blog, I am developing my CMS system (framework). To give my arguments a bit more weight, I must state that I write a valid (I use validators) XHTML 1.0 strict code. Firefox 3.0.8, IE7, IE8 display everything perfectly. Output in these browsers is nearly identical, but OP 9.64 has failed for many times already.

1) Floating right and DOM:

I was trying to float a div element right. It seemed to work fine until I tried to change the image of img tag, that lied inside that container. I could not change anything until I removed the floating style.

2) Bottom and right styles:

In order to create a fullscreen container with scrollbars (overflow: auto;), I defined the positions of container edges without using the height parameter. This worked fine in all browsers until I tried to resize the window of OP. Those containers did not resize at all until a page was refreshed...

3) Fixed position:

There was a need to create a context menu in my CMS, so I used a fixed position div container for that purpose. Once again everything seemed fine until I changed block display value to none. Opera didn't refresh the page and the result was rather shocking... I could actualy reach elements under the virtually invisible block, I could even select text with a mouse underneath, but all untouched parts of the div container remained unactive but visible... Even more, text selection has gone crazy after this experiment. I could select text in multiple places of the document at the same time. That would have been fun, but the sad part is that it was not that easy to deselect it afterwards...

I used to face many more bugs in Opera, mostly with JS, DOM and mostly related to refresh problems. I really hope that those bugs will be actualy fixed in the near future. At the moment I do not see Opera as a serious browser as it needs lots of work...

2009-03-29

PHP session bug

After a long time trying to fix a mystique bug in my CMS engine, I finally found myself trying to avoid another bug, related to my PHP (5.2.5) session. I would like to share my experience here.

What I was trying to do was to check whether a variable in session was present (using PHP is_set() function) or not. The reason why I was doing this was that this session variable was used for caching. If it was an empty array, it meant that empty information unit was cached and, on the other hand, non present array element should have meant that information had not yet been cached, and that should have triggered the caching mechanizm.

What actualy happened was some kind of a random bug. Sometimes (randomly), after clearing the session in my Firefox browser (3.0.8) or IE (7) the session still contained its array hierarchy. All array elements were cleared to empty arrays, but remained in memory. From the CMS point of view that meant that caching was already completed and there was no need to run one. And that's where the PHP bug is.

First of all, lets take a look to some other PHP bugs, related with session I found on the web that might be interesting to PHP programmers:

The second article describes an unset function bug that looks rather similar to my situation.

At first, it looks like clearing Firefox session (session id actually) should force PHP to generate a new session for me, but I guess that it tries to optimize something and leaves the hierarchy in memory, while it is quite likely that I will use the same one during the new connection.

What I am afraid of is that there is a little possibility that when some other user connects to the same system on the Web, such bug, as described above, might cause even security issues.

Tip: NEVER COUNT ON THE EXISTENCE OF AN ARRAY ELEMENT IN SESSION FACT!

To sum up, I can say that I really like PHP language and I truly hope that PHP6 will not contain these problems in the future.

2009-03-17

U programming language is still here

In the past I have published a message here, in this blog, about UPL (Universal Programming Language). To keep things going, I have decided to write a term paper on this issue in my university (Vilnius University). It shall be called "A better programming language" (yes, as simple as that). This paper will mainly discuss both good and bad sides of existant programming languages, trying to collect a list of features that a better PL of the future should have in it.

Yesterday (assuming that 0:33 is already the other day), I was talking to the lecturer who is a supervisor of this upcomming paper, and he didn't support this idea fully. He agreed that it is a good idea to analyse existing programming languages and paradigms, trying to find their hard points and weaknesses, but the idea of creating my own programming language was said to be unnecessary. To be honest, I really hope that I will be able to change my lecturer's mind, because I am going to write this language standards one way or another.

At the moment I am studying OOP (Object Oriented Programming), PBP (Prototype Based Programming) and FP (Functional Programming) paradigms. My idea is to make a careful mixture of those paradigms.

The progress is not as big as it should be, because I still got lots of work with my web page projects (there are already two of them simultaneously at this moment). CMS nearly has its main functionality built already and at the moment its interface is being developed. Anyway, I hope to finish this work on the beginning of April and UPL will then arise!

2009-03-07

CMS interface is comming soon

Finally, the last method, needed for the CMS engine, is written. The last class exceeded 4000 lines and is still not tested properly, but in a few days it will be tested and fixed if needed.

Interface development is promising to be an easy task and I really hope for that as CMS basic functionality must be available at the end of March already. This is a deadline of one great website that will be built on CMS framework.

Smarty 3 is not yet available, so I will not waste my time updating the template engine.

My nearest tasks will be:

  • Small login page fixes
  • Main CMS page layout and working login page
  • Multilanguage website creation tools (most of this functionality already exists, but it is still not possible to add a new language)
  • Interface for editing language constants
  • Element class testing

2009-02-15

CMS progress information

Some time passed since my last post. Lots of things have been updated in CMS and probably the most interesting one is code obfuscating tool. I have participated in designing and testing it, but it has been programmed by a good friend of mine - Albertas Jurgelevicius (you may find a link to his blog on a sidebar). This tool is able to obfuscate PHP, JS and even CSS code.

In my last post I have mentioned migrating to a new Smarty template engine version, but I decided later on that it wouldn't be wise as new Smarty 3 will appear soon. CMS is still under construction, so there is no reason to rush.

Now I am finally planning to start coding in a bit higher programming layer (using a huge library of CMS classes) and as a result an already working CMS interface is expected to come into action in about a week.

2009-01-06

CMS project continues

CMS project is finally continued! I finally have time for it. As it was a long time since I typed my last line of code there, first of all I will have to spend some time just for remembering the way it works.

My nearest tasks:

  • Migrate to SVN 1.5.5
  • Update Smarty template engine
  • Fix several DB bugs
  • Remember how custom caching works
  • Update custom caching
  • Remember how login mechanism works
  • Think of new tasks...
I will inform you about the progress of this project in this blog.

2009-01-05

"bitBrave" failed and published

This summary is not available. Please click here to view the post.