Posts Tagged ‘PHP’

Things I showed to people not knowing Perl but PHP

Sunday, March 7th, 2010

Thank you for reading this article. If you continue, please read it completly before judging or writing about it and expecially before using any information written here!

We were talking to many PHP guys on CeBit 2010. I tried showing the huge power of Perl but – as far as I remember – I never said anybody “forget PHP”. Here are the most important items (odered by usual order of appereance):

1. You don’t need to learn Perl

Neither PHP not Perl people like that fact, but PHP was originally based on Perl. There are still many similarities between both considering keywords and syntax. But most PHP people agree if you say: “If you know PHP, you basically know a good amount of Perl.”

2. CPAN

There are about 20.000 modules for all kinds of things on CPAN, like database access, file parsing, templating and math and all of them are free. All CPAN modules could be installed by a CPAN client which usually comes with your Perl.

Please tell me if you know any other language which has something comparable.

3. DBIx::Class

Most of the PHP users also use MySQL but for the full time of CeBit 2010, I met only one person (who actually was a database expert with some PHP knowledge) who answered the question “Do you like to write SQL statements, expecially SELECT JOINs over some tables?” with yes, all others answered between “no”, “not really” and “less than writing PHP”.

Basically DBIx::Class abstracts the SQL statement layer: Your source dosn’t need to contain one SQL statement any longer. The results are:

  • No need to SELECT JOIN, just point DBIx::Class to some property of the table row you need, maybe using a referenced table in just one line of source.
  • Once you got your object, you could use all referenced tables as simple childs. Sample: $user->customer->company gets the company name out of the customer table starting from the user table pointing to the customer table.
  • DBIx::Class reduces database load by fetchting the object when it’s first actually used, not at the time the object is created.
  • DBIx::Class makes SQL injection impossible because it’s encapsulated by DBIx::Class without any additional development.
  • Reduces development time of database actions by about 50% compared to writing SQL statements (depending on the developer, of course)

Nothing written above has anything to do with comparing PHP and Perl. It’s just comparing DBIx::Class to $dbh->select… (or other ways sending SQL statements in other languages). There is something on PHP which might be compareable to DBIx::Class even (up to me) it isn’t nearly as powerful as DBIx::Class, but most PHP – people I met on CeBit 2010 were still writing plain SQL statements – as I did about eight month ago.

Also remember that using DBIx::Class will introduce a slight part of OOP even to people who don’t actually use it. Up to me this would be the preferred way of starting OOP development because it’s a slow start – you could add more and more OOP as time goes by and you feel ready to look into another world.

4. Catalyst and Template::Toolkit

There are technologies for PHP which are really better in many situations than these two. Catalyst is a complete Web framework which reduces the typical programming amount for weblications and Template::Toolkit (TT) provides a very powerful template engine, but I was working together with some webdesigners in the past which can’t handle it because it was too programmish.

If you pass a DBIx::Class object to TT, the one writing the HTML code could easily access all data of the table row including any child objects and any future changes to the table structure without any additional application source.

5. Coming back to CPAN

I wrote about three examples of the more than 20.000 CPAN modules, but if you ask people what else do they want to do and live-search for it on CPAN, it usually gives you some results. Please recheck this if/when the CPAN search engine (which shows modules even on very slow relations to the search) is being fixed.

Good samples to show are

  • Parse::CSV for parsing CSV files in two minutes development time instead of ten
  • Creating or modifiing PDF files
  • Accessing external things like network servers of any kind

6. How to start

Padre, the free Perl IDE comes with some few lessons within the examples, not enough for really learning Perl but good for looking into the syntax.

The next step would be http://learn.perl.org for many more resources how to learn Perl.

If you want to meet the community, look at the PerlMongers groups who meet maybe also in your area.

If you don’t even want to look at Perl…

…you should at least try Padre which also has a PHP plugin for working on PHP files. You’re welcome to improve it by testing or changing the source.

Last notice: Writing Padre Plugins in PHP should theoretically be possible using the Parrot engine, if you want to try it, please add your experiences to the Padre Trac wiki.

Padre listed on German PHP IDE comparison

Monday, November 9th, 2009

Padre is now discussed at php::bar, a German PHP related website:

Padre auf deutscher IDE-Vergleichsliste

Monday, November 9th, 2009

Padre ist jetzt auch bei php::bar, einer deutschen PHP-Community-Seite, gelistet:

Neu: Padre::Plugin::PHP 0.03

Monday, November 9th, 2009

Die neue Padre Version 0.50 kam vor ein paar Tagen raus und jetzt folgt die neue Padre::Plugin::PHP – Version 0.03:

  • Fehler behoben: Die PHP-Einstellungen (Interpreter-Pfad, Parameter) konnten u.U. nicht gespeichert werden
  • Ein neues PHP-Menü bringt einige nützliche Funktionen und viel Platz für weitere.
  • Padre 0.50 bietet jetzt die Direktbearbeitung von Dateien auf einem FTP-Server

Jetzt verfügbar auf einem CPAN – Spiegelserver Deines Vertrauens.

Schnellanleitung für Installation oder Update

Linux

  • Starte eine Linux-Shell
  • Gib cpan ein.
Windows

  • Klick auf Start -> Ausführen und gib “cpan” ein.

Alle Betriebssysteme:

  • Eingabe: o prerequisites_policy follow
  • Eingabe: install Padre Padre::Plugin::PHP Wx::Perl::ProcessStream

Diese einfachen Schritten installieren Padre, das neue Padre::Plugin::PHP und ProcessStream, das in älteren Versionen bekannte Fehler hat.

Eine genauere Anleitung und weitere Informationen findest Du auf den Padre howto pages (auch auf Deutsch verfügbar).

New: Padre::Plugin::PHP 0.03

Monday, November 9th, 2009

The new version 0.50 of Padre was just released and now the new Padre::PHP::Plugin – version 0.03 follows:

  • A bug in the preferences dialog was fixed which sometimes did not save the PHP interpreter path
  • There is a new PHP menu giving direct access do some useful functions and space for many more
  • Padre 0.50 comes with a embedded FTP-File editing function which allows you to edit files directly on a FTP-server

Get it from a near CPAN mirror.

Quick Install/Upgrade

Linux

  • Open a shell window
  • Run cpan
Windows

  • Click on Start -> Run and enter “cpan”

All OS:

  • Type o prerequisites_policy follow
  • Type install Padre Padre::Plugin::PHP Wx::Perl::ProcessStream

Padre will install itself, the PHP plugin and the ProcessStream module which is known to have some bugs in older versions.

More detailed information is shown on the Padre howto pages.