-
I was working the other day on a new JavaScript game for the games section. Like the majority of the developers (like the statistics show) I’m using FireFox for developing. But as the game reached the testing faze it was time to see if it was working properly in Internet Explorer.
To test in Internet Explorer is a real pleasure, basically you see an error and then you hope that you’ll find the source.
Of course there was an error, one full of meaning as usual:
Unknown runtime error??? WTF??? If he does not know how should I?
The piece of code that was generating the error was:
1canvas.innerHTML = '';
Where canvas was a variable which was storing an document.getElementById(‘canvas’), and the id canvas was from:
1<table border="0" cellspacing="0" cellpadding="0"> 2<tbody id="canvas"></tbody> 3</table>
Looks wrong? well is not because at that point I was testing other games which are using the same thing with no trouble, even in IE.
I’ve tried it in IE 6, of course with the same result.
It looks like this error appears on elements like table, tbody, p and others.
To finally fix the issue I used instead of a tbody, a div tag in which I’m adding the elements and the issue was gone.
What is interesting is that this issue does not always appear for a specific tag!
Thank you Microsoft for this meaningful error messages that are so full of logic!
-
In PHP 5 a new concept was introduced, type hinting. This feature allows validation of a parameter for a certain type.
This validation type is very popular in object orientated languages and I believe it represents a plus for the PHP object model and even more for his dynamic nature it self.
In PHP 5.1 validation for the array data type was added.
Let’s take a small example:
1class a { } 2 3class b { } 4 5function testa (a $a) { 6 echo "Bla bla\n"; 7} 8 9testa(new a()); 10 11testa(new b());
The result is:
1Bla bla 2 3Fatal error: Argument 1 passed to testa() must be an instance of a, called in ...
Cool, ha?
The type in which we can validate can be a class, an abstract class or even an interface which is inherited by other classes, like:
1interface inherited { } 2 3class a implements inherited { } 4 5class b implements inherited { } 6 7function testa (inherited $a) { 8 echo "Bla bla\n"; 9} 10 11testa(new a()); 12 13testa(new b());
And the above example will not raise any errors.
Unfortunately there is no way to validate primary (or scalar) data types. When PHP 5.3 was being released there have been some discussions on the subject, but it seems that it was too late, and the patch did not make it to the final version.
Yesterday, while I was doing my morning reading at a cup of coffee, what do I see on Ilia Alshanetsky blog: Scalar Type Hints are Here! Well, is a little exaggerated, there are not exactly here but there really close. Basically there are in the SVN trunk and will be available in the next stable version!
Of course that even in the current version of type hinting is not exactly mandatory to use it in PHP, is more of an issue of fine tune.
Basically we could already validate to a certain primary data type, but still:
1function testint($var) { 2 if(!is_int($var)) { 3 trigger_error("Type must be Integer", E_USER_ERROR); 4 } 5 ....... 6}
is not exactly as elegant as:
1function testint(int $var) { 2 ...... 3}
-
Packt Publishing has published a new book on the RAD PHP framework CodeIgniter version 1.7. The book CodeIgniter 1.7 Professional Development written by Adam Griffiths, has the slogan “become CodeIgniter experts with professional tools, techniques and extended libraries”.
Just from the slogan you can see a slightly different tone then the book CodeIgniter 1.7 from Packt Publishing, which in my opinion has the purpose of showing what the CodeIgniter framework can do.
This book has the purpose of showing how can you develop professional applications, or at least until proven otherwise, stay tuned to find out!
An argument for the slogan is the target audience like is defined in the “Who this book is written for” section, which contains the phrase:
Basic knowledge of CodeIgniter will be helpful.
A dangerous phrase in my opinion, because it can scare off a beginner, even though in the book it looks like all the steps are described starting from server installation.
If from the first book I was expecting a general presentation of the framework, now I’m curios to see if the examples are more ample and more concrete.
From the sample chapter it looks like there is a lot of code. As long as it is logical I thing it’s a good thing, a lot of times is easier to understand code, which you will after all write and you can take as an example, then theory.
But more about this book after I’ll get to read it.
To be continued…
-
PHP for desktop, is it worth it?
PHP is described on Wikipedia as:
PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages.
Taking this into consideration, apps divide in 3 category: web, command line and desktop.
For the Web, PHP is the most popular open-source (and not only) programming language.
PHP CLI
PHP CLI (Command Line Interface) I find it very interesting, even though is not used at it’s full potential. A lot of developers prefer shell scripting or Perl with no real reason. I’ve been playing around with this tool and I liked the result.
Important frameworks like: Zend, Symfony or Cake PHP are using PHP CLI to generate projects, models, CRUD or other features that can be easily used with a command line.
In the Windows environment the command line is not exactly popular, but in Linux is almost imperative. After all what’s the point of using shell scripting when you can use a powerful language with a lot of features like PHP?
But CLI is not limited just to the command line, it is usually used for cronjobs, pipes, socket-servers etc.
PHP-GTK
When it comes to PHP and desktop usually people thing about PHP-GTK. What do I thing about the project? Is not dead, like it says on the official website, but is not exactly alive. The reason? Gtk is not exactly simple. If you come from the Linux environment probably is not that difficult, but if you usually work on the web is not exactly html… Nevertheless there is a community that keep this project alive.
Nevertheless, it allows developers to build desktop apps in PHP, compatible with a wide variety of operating systems.
But there is an issue, the resulting apps are not exactly compiled code, they must run using a PHP virtual machine. Here is the issue, how do you distribute the app? If you have a small app of only few lines of code, to distribute it with a virtual machine is a little complicated… Also the code is visible, of course there are methods to solve this issue, but there aren’t exactly simple.
This is probabily the most popular PHP platform for desktop, if you can say that about this environment.
The documentation is pretty big, it was taken from the C++ version. Is not as well polished like the PHP manual for instance, but I believe is sufficient.
Winbinder
Compared to PHP-GTK it has an disadvantage, it only works on MS Widows operating system. The advantage is that it has a much simpler API. If I had to choose a PHP platform for desktop, probably I would go for Winbinder. Unfortunately is in the same state, is not dead but is not exactly alive. It also have the support of a community, but without any particular special results.
The issue with the compiled code is found here also, and even more the issue with platform distribution is just as bad. I firmly believe that if you want to develop an app using this platform, to make it work on your computer is the easiest part, to make it work on someone else’s computer is the real issue…
The documentation is pretty small, because of the API. But simplicity is good when it comes to programming, that means you can easily build pretty interesting apps.
Compilers
There a few, and the majority of them have some issue because they use old PHP versions of even old GTK. I’ve spend many hours on Google trying to find some reals solution but with no success.
Most popular compilers:
- Bambalam – works well with CLI and Winbinder. But it has a great disadvantage: it’s only compatible with PHP 4.4.4, and I believe that says it all. Anyway I believe it was the most interesting solution, unfortunately to old (the last version was released in 2006).
- PriadoBlender – works well with PHP-GTK and CLI, but is not very stable. The last (beta) version was released in 2007, and since then nothing new was ever heard from it. Probably if that version would be updated it would help a lot the PHP-GTK project.
Conclusion
When it comes to Web, everything is great!
PHP as a command line tool is ever more popular and more tools appear each day!
In the desktop environment is a “the living dead” sensation… This projects are not dead but there not exactly alive. Of course there are other solution for PHP on desktop which I did not mention, but there are in about the same state. Probably a new approach would help, something more attractive for web developers and those passionate about this language.
-
After my second little project, I’m back with my opinion on Adobe AIR!
Working with Adobe AIR I had a revelation, in 2004 John Battelle and Tim O’Reilly presented the concept “Web as Platform”. These days, using the Web as a platform we can develop desktop applications. Basically we’ve left an environment to come back to it with a new perspective.
If the first time I had only 3 days at my disposal, this time I wasn’t constrained. During this time I had the opportunity to discover some of the features, like NativeMenu and the support for SQLite.
I believe that SQLite has the purpose of compensating for the storing possibility that are not available on this platform, like cookies. Of course, SQLite is using a database, and the storing is way superior to the traditional Web.
But way choose Adobe AIR compared to other platforms like Java or C#? Because it is simple! I don’t believe that Adobe AIR was intended to be a tool for developing large applications, even though only time will tell if that’s possible. This is a great tool for small to medium scale apps, which can bring something extra to the Web. For instance in my app I had an alert system, I thought what I would like next to what I already have on the Web. With this alerts I don’t have to check all the time what’s new. Just as well I believe features like chats can be implemented or similarly features, after all if it can be done on the Web, it can be done here.
What Adobe AIR has is a very interesting distribution system, basically the platform is distributed with Adobe Acrobat Reader, thing that can make it available even on your computer without even knowing.
What Adobe AIR does not have, and I thing it would be useful, is a system for accessing COM objects for instance, possibility to access different database systems different then SQLite, which is quite simple.
Another feature that I would like is the possibility to access Adobe Flesh features from JavaScript. I know, I should use Flash if there are Flash features, but I prefer JavaScript as a platform. Probably the reason this features are not available in JavaScript is because this language has the HTML 5 features, like: Canvas and Audio, which somehow compensate with Flash features that are not available in JavaScript by default.
Adobe AIR 2 which is in beta version for the moment, will probably solve some of the need to access the system resources.
In my opinion, Adobe AIR is the platform on which a Web developer can develop desktop apps with ease!