BlogPhotosContact

Topics

On the move

There was recently an interesting post about scripting languages by Steve Yegge. What I particularly liked are the hints on other languages he gives and his invitation to try new languages.

I have been programming PHP since 1999 and felt a need to learn something new approximately when they launched Rails a few years ago. But instead of learning Rails, because I don't usually follow the hype, I decided to learn Python.

So, recently, I have been learning Python, then Ruby and now the Lua programming language. Out of these three languages, my favorite is Lua and it is where I spend most of my time now.

PHP blobThey are all excellent languages to learn and in many ways, they are better than PHP. As I said in a previous post, I now see PHP as a big blob which along the years have been developing in too many directions and is now facing a lot of problems because a lot of things were implemented incorrectly and were not carefully planned. It is not obvious at first, but when you start looking at other languages, you understand how some things could have been done and you realize how wrong they are in PHP. I am thinking of all the stuff you find in SPL, create_function(), call_user_function(), ::, $this->, parent::, instanceof, is_a(), the way static are handled, etc, etc. It's all a mess. And it starts to look in blog posts. From time to time, I read things about how nice it would be to have closures, traits, anonymous functions, weak references, duck typing in PHP and some hacks on how to imperfectly implement them.

And because PHP is not idiot proof, you will find a lot of people there with little knowledge about programming. Like this week's post of someone who says "function in_array() sucks because it is slow"... The more I know about programming and the less I find the PHP community interesting. It's like all the interesting people here are doing things secretly and don't take the time to share their experiences (unless they write books).

And the last things I have started to dislike is the way a company like Zend is taking over the language. I have also recently very much disliked Oracle buying InnoDB and Sun buying MySQL, although I was not surprised for MySQL given the road they had taken lately, which is actually a lot like the road PHP is taking with Zend at the moment. With rumors about Microsoft, Oracle, IBM buying Zend, I start to feel the fear. Because in the end, who decides what goes where in PHP core?

Here is a list of programming languages that deserve a look soon:

Comments (10)  Permalink

Stop stealing, innovate

Today I saw this proposal for the Zend Framework. I wouldn't be surprised if this proposal was accepted. Zend Framework seems to be unable to propose anything innovative to PHP developers. The examples provided on this page look like they are copy/pasted from code available in PEAR that already is 5 years old.

I think Zend as a software company has a real problem with innovation. Not surprisingly, PHP suffers the same problem. Most of (if not all) the new features are stolen from Java, C, C++, PERL, ... but nothing seems to be invented here anymore.

Of course, I think HTML_QuickForm2, the project we have been starting to work on will be a lot more interesting than these Zend_Framework proposals. It will be invented here and it will stay in PEAR. PEAR is where the innovation is. Zend_Framework is just, well..., a framework ?

Comments (11)  Permalink

My experience with Python

During the last 5 months, I have been learning Python. I read a few books about the language and subscribed to various mailing lists, RSS feeds and followed Open-Source projects.


Learning Python was easy and interesting. My experiences with programming languages so far have been mostly with PHP (since 1999), Objective-C, some C, Javascript and Actionscript for Flash. So I was at ease with Python and everything seemed well thought and designed.


Compared to PHP, Python is pretty. Even the syntax is prettier. The obligatory code indentation is in my opinion an excellent idea to make sure your code is readable and respects some coding standards. Compare this with the code you can find in PHP apps libraries where each script has its own way...


Python seems to have been thought from the start. On the other hand, features were added to PHP one after the other in order to "solve the web problem". So compared to Python, PHP looks like an ugly fat blob. It borrowed from C, Perl, Java, C++... In comparison, Python looks more like a nice girl in a pretty dress. But as Rasmus Lerdorf said, PHP was never designed to win a beauty contest.


I started learning Python mostly because I was getting bored with PHP. I write PHP code almost every day, 10 hours a day, so I wanted to try something new. I had to do it on my extra time since PHP is our language of choice at work. I picked Python instead of Ruby because I didn't want to follow the hype around Rails. I was also interested in projects like Python for Series60 from Nokia and pyObjC, a bridge between Python and the Cocoa framework.


As my work consists mainly in writting web application, my first attempts with Python were to see if I could also use it for the web. Well, the answer is not definitive but it's closer to no. Python is not ready for the web. The community is working hard on web frameworks but they go in every directions and none of them is well tested. And none of them is near PHP in terms of ease of use, features and deployement options.


Still, I really wanted so I picked up a simple web framework called Colubrid and tried to find a template engine that would fill my needs. In the past I have been using HTML_Template_Sigma and was after something as simple. Well, without success. There are a lot of template engines in Python but they are either too big and do easy thing the hard way, or they are too simple and don't support the basic stuff you would expect. So I decided to simply port HTML_Template_Sigma to Python.


In a way, I managed. My version supports everything that HTML_Template_Sigma supports. It took me 2,5 days approx. But the experience made me see how a language that tries to win the beauty contest is limited compared to its ugly brother. Here are some of the problems I met:

  • No isset(). If you use a variable that is not bound to an object, Python raises an exception, even if it's in a comparison clause. And you have no way prior to this exception to check whether the variable was bound. Some people suggest to catch the exception... This is like the chicken and egg problem.

  • Too many array types. PHP has only one type of array even if it can be used in different manners. Whether it is associative or not, the PHP arrays share the same set of funtions. In Python, you get dictionaries, tuples, lists, etc. And they don't have the same API. Arrays are probably the most useful way to store information in my code, with Python I always have to remember which kind of storage I used.

  • Values added to dictionaries are not stored in any specific order. Dictionaries are like associative arrays. Except that when you iterate them, the items you carefully added to them are listed in no specific order. This makes them totally useless and even dangerous. And there are no other datatypes provided by default to take care of your data in an ordered way. You have to write your own.

  • No easy one liners. I use a ? a : b; quite a bit in my code since it makes it shorter and easier to read (at least for me). You can't do something as simple in Python, you have to use convoluted ways.


There are a lot of other things in Python I felt were missing or wrong compared to PHP. The opposite is also true, but I mostly do web development and in this area PHP is way beyond. I agree that Python is a prettier language but that's not enough. Beauty is a subjective thing and to stay pretty you have to stay slim. I expect a language to provide me with the tools and the syntax to be as productive as possible, eventually with less code.


Actually, a lot of Python users seem to be in love with their language. They even invented a silly word to define and label other people's code : "pythonic" and "not pythonic". It means pretty. For example, interfaces, from Java or PHP5, are not pythonic. I actually got amused by the number of things that were not pythonic.


"Pythonic" is a geek term. In fact, I think Python is a language for geeks. The majority of Python users have no idea about marketing, business, promotion, press, corporate... Commercial terms are dirty. Python programmers like concepts and programming challenges. Python is their playground, their moment of fun, their hobby. There are actually a very little number of Python developers that seem to use the language for their living. Python is often used for prototyping and testing concepts.


I am not a geek and what I am really after is a tool to help me get more productive at work. Unfortunately, Python didn't fill my needs. I was happy to learn it and it showed me some interesting concepts implemented in interesting ways. Now I can read and write Python code that is maybe not "pythonic" but that does the job. Thanks to my initiation, I also discovered Mercurial, a very good RCS written in Python and switched to it from Subversion. I didn't loose my time, I simply had to try.


Now I am learning Ruby and enjoying it so far. It seems to fit the bill, along with Rails as a potential replacement to PHP. There is also an Objective-C/Cocoa bridge called RubyCocoa. Nothing for the Nokia Series 60, but this will force me to use my new Python skills so it's ok. In terms of beauty, I think Ruby won the contest over Python a long time ago. I will report about my experiences with Ruby later on.

Comments (9)  Permalink

Using CSS and list to build a pager

This is one way to build a pager using CSS. A pager is most of the time composed of a Previous page link, links to Pages and a Next page link. It can also have First and Last page links. This can be boring to build dynamically and to have elements aligned correctly, we often use tables. If we could use html lists, this would make the pager more accessible and easier to place in a modern layout (Web 2.0 anyone ?). Well, here is the solution I came up with.

First the markup your pager will generate:

<ul style="pager">
<li><a href="/0"><<</a></li>
<li><a href="/1"><</a></li>
<li><a href="/1">1</a></li>
<li>2</li>
<li><a href="/3">3</a></li>
<li><a href="/4">4</a></li>
<li><a href="/5">5</a></li>
<li><a href="/6">6</a></li>
<li><a href="/3">></a></li>
<li><a href="/6">>></a></li>
</ul>

It's pretty straightforward.

Now, the css

ul.pager {
	margin: 0;
	padding: 0 ;
	list-style: none;
	text-align: center;
	white-space:nowrap;
}
ul.pager li {
	margin: 0;
	padding: 0;
	list-style: none;
	display: inline;
}

Feel free to remove the white-space:nowrap if you don't mind it if your links wrap when the container is too small to fit them all on one line. The text-align:center is here so that the links are centered in the ul container. The trick really consists in making the li elements inline instead of blocks as they usually are.

Result

Bitmap rendering in Firefox

Pager rendering

I am going to elaborate on this pretty soon and show how such a simple pager can be styled easily. In the meantime, feel free to post your comments about this technique and its compatibility in other browsers.

Comments (3)  Permalink

We are family

My father is PERL 5. My grandfathers are C and sh. My grandmothers are nawk and sed. Who am I ?

Answer: http://www.levenez.com/lang/history.html

First time I also here about a Gogol programming language. I wonder what the syntax is like...

Comments (2)  Permalink

Guide to PHP Security, small book review

I ordered Ilia Alshanetsky book - php|architect's Guide to PHP Security - about a month ago. I did so because php|architect said there would be books with Ilia's signature for the first ones being ordered. I thought it would be nice to have one, for the fun and because I enjoyed Ilia's speaks at the International PHP conferences (in Amsterdam).

Anyway, I received the book without the signature so I was a bit disappointed. I thought I misunderstood the ad. I did not really ordered the book for its content because I thought, with 6 years of PHP programming, I now knew enough about PHP security and stuff like that. I admit my first web applications really sucked in this matter, but now I think they should be ok.

As I take the underground everyday, I sometimes find myself without anything to read and having nothing to read in Paris underground is pretty boring, so I picked up Ilia's book for the ride.

Now that I reached the middle of the book (took me approx. 8 underground rides), I can say it's very good and I have discovered many ways to further improve my applications. I learned something new about PHP on almost every page. This book is not exactly for newbies, it sometimes goes into PHP internals and give you excellent tricks on how to improve both your scripts security and performance. The code examples are very short and illustrative. This makes the book very easy and fast to read.

Ilia definitely knows what he writes about and goes well beyond security by also giving you useful tricks on PHP performance and how PHP works internally.

The only thing I thought was missing is a chapter about backup strategies, because if your server gets compromised, the only recourse you'll have in most cases are your backups. It would be nice to have this as a free chapter :)

The good thing is that today (only), php|architect is making a special offer on the book.

Comments (3)  Permalink

New year's resolutions

And in the IT business domain, my new year's resolutions for 2006...

  • Learn Python. Python is an exciting language with a large community of skilled developers.
  • Make my first Python web application. I am going to use lighttpd or snakelets for that. Unfortunately, at the moment Python for the web really sucks, so I will start with a small application, something like a Python photo gallery.
  • Release my first commercial application for Mac OSX, written with Cocoa. I already released Rula, it was free and but is not available anymore because I didn't have the time to maintain it correctly (too many users, with too many good requests). I have written another one (a manager for sqlite 2) but sqlite got to version 3 before I got the time to release it, so I sort of postponed the project. My next application will be really cool :) Anyway, it's already work in progress...
  • Release Phreez, my Object persistence with php and pdo framework, under BSD license (as soon as I have implemented the history feature).
  • Rewrite HTML_QuickForm, probably for Python and PHP5.

Along with all the daily work I have to do, my little daughter and other family occupations, these would probably be enough to keep me busy in 2006.

What are your new year's resolutions ?

Comments (1)  Permalink

Offre d'emploi Développeur PHP Région parisienne

Nous avons actuellement un poste à pourvoir dans ma société, Mamasam, pour un développeur PHP. Le poste concerne la réalisation de plusieurs missions de développement de sites et d'applications spécifiques sur Internet, ainsi que la maintenance d'applications existantes.

Les missions seront principalement développées en PHP 5, mais d'autres langages et technologies pourront être utilisées si besoin (ex: Python, C, Objective-C, ActionScript, JavaScript). La connaissance de JavaScript et d'ActionScript est un plus.

Une connaissance même basique de la programmation orientée objet est obligatoire. Avoir participé même légèrement des projets open-source est un plus, indiquer éventuellement sur votre lettre de candidature.

  • Lieu : Saint-Maur-des-Fossés (94), direct RER A
  • Contrat : CDI ou CDD
  • Rémunération : A déterminer en fonction de l'expérience
  • Date de début : Début 2006
  • Contact : Bertrand Mansion, jobs@mamasam.com
Comments (0)  Permalink

Very first impressions of Zend Studio (installation) on Mac

Zend bin folderHere are my first impressions about the installation process of Zend Studio on Mac OS X. Please note that I have never used this software before, I use BBEdit instead.

1. The zip archive could not be decompressed with Stuffit Expander, I had to use Apple's BOMArchiveHelper application which I usually never use. But it worked.

2. Once installed, you get a new Zend folder in your Applications folder. I would have appreciated to be told that I could install the software anywhere on the disk beforehand. I would have put it on my Dev partition.

3. The Zend folder contains a bin folder which in turns contains a lot of things that should certainly be hidden to the end-user: .jar, .sh, .ico, .zip... Zend should learn about Mac OS X bundle feature. It allows you to put all this stuff into your application without making it visible.

4. There are 2 applications (I can tell by looking at the icons). Apparently, there are just launchers. Unfortunately, they are named ZDE and ZSS. I have no idea what those acronyms mean. I guess the Z is for Zend but what about the rest. Am I supposed to know already ?

5. Anyway, I asked the installer to put a Dock icon of the application in my dock but it doesn't show.

6. It's only after the software is installed that you are told your Java version is not up-to-date. I am running Tiger in its very last version with the last Java update downloaded from Apple automatic updates. Zend requires a more recent version of Java than the one provided by Apple. But I don't understand why they can't check this beforehand, before the installation starts...

I didn't go any further, I don't have the time right now to install a new Java version. It's really a pity Zend Studio doesn't feel more like a Mac application from the start. I will try to test it further before my evaluation period ends. I hope I will be more successful.

Comments (15)  Permalink

Phreez, object persistence with PHP and PDO

phreez_logoI am going to release Phreez, my object persistence framework for PHP 5 (everyone got one theses days, you know) under BSD license. The project is currently hosted on Novell Forge, the code is in the subversion repository.

The code is not very clever, not very clean and not well tested so I wouldn't recommend anyone to use it at the moment. I plan to add some features and tests as I have to use Phreez for a real web-based application quite soon. At the moment, only MySQL is supported. Others will be easy to add.

The ideas behind Phreez are:

  • Performance
  • Use PHP Data Objects (PDO)
  • Use Iterators, ArrayAccess (SPL)
  • Use other PHP 5 features like overloading
  • Less code, Rapid Application Development (RAD)
  • No configuration (well, almost)
  • Handle relationships
  • Be flexible
  • Try not to be as good as Hibernate :p

There is still a lot to do, I will post more details on my blog as the project evolves. At least the logo is done.

Comments (2)  Permalink
Next1-10/17