BlogKontaktTagcloud

Zend Framwork 1.5 is out

I know, that's definitely old news. But still it's worth to mention that the Zend Framework 1.5 is out since some weeks. It's a big jump from Zend 1.0 but also they have a lot new features in there (and probably some Zend Developers drink too much Java). They have also a new and cooler website for the project now.

In my point of View specialy the improvment in Zend MVC makes the framework now usable for companies with a lot of developers working on the same project (without patching the code over and over again).

The full list of improvments:
  • New Zend_Form component with support for AJAX-enabled form elements
  • New action and view helpers for automating and facilitating AJAX requests and alternate response formats
  • Infocard, OpenID, and LDAP authentication adapters
  • Support for complex Lucene searches, including fuzzy, date-range, and wildcard queries
  • Support for Lucene 2.1 index file format
  • Partial, Placeholder, Action, and Header view helpers for advanced view composition and rendering
  • New Zend_Layout component for automating and facilitating site layouts
  • UTF-8 support for PDF documents
  • New Nirvanix, Technorati, and SlideShare web services
Ähnliche Beiträge:
Coding Contest addicted
Coding Contest
Array instead of switch-case in php
A eventfull PHP-Week
PHP Programming Contest
Comments (0)  Permalink

Coding Contest addicted

As I allready mentioned I can't let my finger from coding contest. Unfortunately Bob found in a comment in my blog more nasty stuff about links in html comments which makes parsing even harder.

I trimed my script again under the size of the original script (ok, nearly the original), but I think if my regex skills would be a bit better, I could still squeeze some bytes out of it. But as I go finaly to holiday tomorow I will send my script to Paul and hope to get some points for the shortest script, as it will definitely not win any price for speed or beauty (did not wrote so ugly code since ages).

BTW: If you still trim you script, I brought up a new testfile. You should still come up with the same 11 links. This testfile is so ugly that my old konqueror is not able to parse it correct (but the comments are absolutly valid, according to the documentation and the validator).
Ähnliche Beiträge:
Zend Framwork 1.5 is out
Coding Contest
Array instead of switch-case in php
A eventfull PHP-Week
PHP Programming Contest
Comments (0)  Permalink

Coding Contest

Unfortunatly I can not resist if somebody brings up a coding contest. This time Travis and Paul wrote about the coding contest of php architect at planet-php. I did not invest a lot time into it, but still ways more then I planed.

The problem is that the ranking is once by speed and once by size of the script. Two parameters which usually not go well together. After having some great ideas for speeding up my code (even parallel processing, shared memory and map-reduce came to my mind) I decide to let this race to others and fully concentrate to the size. I not even run benchmarks anymore.

Unfortunatly some nasty html special cases (whitespace, case independence, single- and double-quoting, various attributes and so on) blow my perfect sized script a bit. But with some nasty php method tricks it's hopfully still the shortest possible script that gets all valid cases.

Just to let you feel not to save, I wrote a littel nasty html example that might break your own script. (You should get exactly 10 11 links out of it.)
Ähnliche Beiträge:
Zend Framwork 1.5 is out
Coding Contest addicted
Array instead of switch-case in php
A eventfull PHP-Week
PHP Programming Contest
Comments (11)  Permalink

Is Dalvik the better J2ME?

Androide the "gPhone" software stack

There was a lot buzz around when Google launched Android, there mobile platform. A lot of newspapers write a lot of articles about it, but technical insides are really rare. Even on the official android-page it's hard to find a good written architectural overview. Probably the best start to understand how Android works is probably this video from google. If you don't can or want to watch a video there's also, as I think a bit a short, explanation on the google code site.

The architecture view

Let me give you a short overview. Android is basically a layered architecture for mobile phones. At the bottom there's a Linux kernel 2.6 that basically handle the drivers to access the hardware. That's really nothing new there; there are already some phones out there that use Linux as a foundation. The most famous one of the Linux mobile Phones are probably the Nokia Internet Tablet or the OpenMoko.

On the next layer there are c-written libraries that bring some basic stuff to the phone. Although this layer is mainly internet-computer and not phone related (Google PC anyone ;-)). There are libraries to display stuff ("Surface Manger", "Open GL|ES", "SGL", "FreeType"), WebKit to display web pages (the same engine that is used in the iPhone and KDE), a SSL library for secure communication, SQLite to simple store stuff and libc as basic c layer.

Then there's the Android runtime, that’s the layer where a programmer can start building there own application on the top. It consists out of a virtual machine that can execute byte code that’s build out of the "Java Programming Language" and a core API that have a very big similar to sun's java package (in fact Google is using part of Apache Harmony, a open source implementation of the Java class library). Let this be enough for now, we go back to this part later on.



On the application framework is the stuff that makes programming a phone easy with android. There are classes to access resources and creating windows. Some stuff here is still in development, there is no MMS or HSPA support yet.

On the top there are the applications of a phone, they are all written in Java and use exactly the same system, no matter if they are written by Google, the phone company, the network carrier or you.

Java or not to Java

Google always talks and writes about "Java Programming Language" and not Java, why comes that? Well what's running on Dalvik, the virtual machine of android, is not really Java bytcode. You program as every Javaprogram just as usual in Java and compile them to bytecode. After that you need to transform your bytecode with the "dx" tool to a .dex file. What you get is now Dalvik bytecode.

Ok!? Why the hell so complicated? Well there may be a few reasons for that. As you still use Java until just before delivering you App, you can easily use your usual tool chain. Eclipse, JUnit, Cruisecontrol or more exotic stuff - it's all no problem! But why they don't just use Java then, you may ask. Well, for mobile phones you still have not the resources like on a pc. So Dalvik-Bytecode is well optimized for the CPU and hardware you will typically find in a mobile phone. And there's another fact which is no secret: Google don't like to pay license few to Sun. So that's the reason why Google is using the "Java Programming Language" and not "Java". It might be a not too big difference for technical guys, but for the lawyers it definitely is.

Smart decision

After all Android, and therefore also Dalvik looks like a smart idea to me. As Sun tried to run Java with J2ME on every device, Android will never run on today’s low coast phones. You just need some basic CPU power to run it. As J2ME is not really a strong framework, you have a single programming language, but it's up to the vendor which functionality he likes to integrate, every single phone is different. That makes porting J2ME to a real pain. As it looks now, the open handset alliance is putting on some standards on library and functionality that needs to be implemented by every vendor. This will make developing an application for every Android phone easy. As the vendor needs to use the same libraries and framework to develop his own applications it's pretty much "eat your own dogfood" and this will give a little security that Android will be useful.

Android will hopefully be a strong platform until we have enough CPU power on the mobiles to just run some standard operating systems on them. And yes, Dalvik is the better J2ME for me, less compromise and more technical possibilities to the programmer.
Ähnliche Beiträge:
Google Open Source Jam Zürich
MySQL drinks java
SCJP, now!
ROFL Prog 1
Java Bug: Process.waitFor() hangs
Comments (3)  Permalink

Array instead of switch-case in php

First of all, be warned, this article has no pratical relevance. It even might guide you to bad code. But this week it just popped into my mind that I could use an array instead of a switch-case construct. So see how we can do this. This is the example for the switch in the php manual.

switch ($i) {
case 
0:
    echo 
"i equals 0";
    break;
case 
1:
    echo 
"i equals 1";
    break;
case 
2:
    echo 
"i equals 2";
    break;
}
Now I'm able to implement this in a array, for that I put the code for every case statement in a arrayfield Afterwards I can access the field over the parameter and execute the code in it with eval.Here's the example: (Take care to not forget the semicolon in the code string)

$case[0] = "echo \"i equals 0\";";
$case[1] = "echo \"i equals 1\";";
$case[2] = "echo \"i equals 2\";";
eval($case[$i]);
Looks pretty, but what to do if you have to do the default statment. Nothing easier then that, we just have to look if eval goes ok and if not we do something after AND-short circuit:
eval($case[$i]) === false && print("default");
Ähnliche Beiträge:
Zend Framwork 1.5 is out
Coding Contest addicted
Coding Contest
A eventfull PHP-Week
PHP Programming Contest
Comments (3)  Permalink

Why your database says paging sucks!

On the view of your database the worst thing you can do in your web app is paging. Paging is horrible in the view of performance. To explain let me take a little example:
SELECT SQL_CALC_FOUND_ROWS gb.*,
u.username,
u.uid,
u.geschlecht,
u.mitfoto,
[... some more fields...]
FROM member_gold_guestbook gb
LEFT JOIN users u ON u.uid=gb.uid_from
[... some more left joins...]
WHERE gb.uid_to='22152'
AND visible='1'
LIMIT 0,10;

That's not that bad at all, but when you go to page 300 your database server will hat you for this. The database server has not only to calculate the 10 items you want to show but also all 3000 previous items.

Sure you may argue nobody will ever go to page 300. Somebody will not, but "googlebot" and his evil brothers will. And the bad thing is that you can, as long as you need paging, nothing do against it. There are just a few tricks that may reduce your server load a bit.

Optimize it!

A fast query that uses good indexes is just faster, no matter where you use it. But on paging where you might calculate thousands of lines it really does matter a lot.

Avoid ORDER BY and GROUP BY because you have to do this (depending on index use) on every line in your table, the limit can't help you here.

Cache it! But still the query has to be run once, especially for fulltext searches, even the first run of a query might put a lot of load on your servers.

YAGNI (You aint gone need it!)

Nobody will ever see page 300, so why you don't set an upper limit for you paging. Your user will not mind and I'm sure the bots will find another way to your stuff. If you really care about SEO, you probably can do a separate list for bots that perform with less operations on the database (remove unneeded joins, don't sort it).

Don't join tables you don't need, sure that might sound obvious, but I'm seen this too many times to not mention this here.

Count is evil

Never, never use SQL_CALC_FOUND_ROWS it's just equally slow then "SELECT COUNT(*) FROM table", but you have to do it on every page. The count(*) variant you can cache at last, so you don't have to do it on every page.

And there's even another way to avoid the count on paging. It's the way Facebook does paging on some places. Facebook don't give you the usually list of pages from 1 to n there, were you can click at any page. They just give you the page before, the current page and the next page, if there's one. On the application side it's very easy to find out if you have a page befor the current, when you on the second page there's one before (so no surprise here). But what's about the next page if you don't want to make a count. Easy stuff, let me predict you display 10 items per page, so query 11 items instead of 10 per page. This one extra item will cost you nearly nothing and now you can count the returned rows in your application. If you have more than ten rows you have a next page and you can happily throw number eleven away.
Ähnliche Beiträge:
MySQL drinks java
Peter Zaitsev in Zurich
Most boring
Xobni - Pulic beta
All new webtuesday
Comments (2)  Permalink

Endlich gelesen: The Pragmatic Programmer

"The Pragmatic Programmer" sollte für jeden der mit Software Entwicklung zu tun hat Pflichtstoff werden. Warum ich so lang gehabt habe um dieses Buch zu lesen kann ich mir nur damit erklären das ich denn grössten Teil des Inhalts schon in Vorlesungen und in einem Vortrag von Andy Hunt gehört habe. Die Zusammenfassung des Vortrags, der einen grossen Teil des Buchs abdeckt, findet man in meinem Blog (Teil1, Teil2).

Andy Hunt und Dave Thomas erklären auf nur knapp mehr als 250 Seiten alle wichtigen Paradigmas der modernen Software Entwicklung. Bei so wenig Seiten kann natürlich nicht immer ins Detail gegangen werden, gewisse Themen werden nur angeschnitten und müssen bei Interesse weiter vertieft werden.

Die Tipps wie man ein Projekt zu einem erfolgreichen Abschluss führen kann sind absolut unverzichtbar. "The Pragmatic Programmer" muss man einfach gelesen haben.

Mein nächstes Buch aus dieser Reihe wird, sobald ich es von Mirko endlich bekomme, "My Job went to Serbia India".
Ähnliche Beiträge:
Lesen: iWoz
Gelesen: Afghanische Reise
Buch: Computerlogik
Trockener Code
Pragmatic programming with Andy Hunt (Teil II)
Comments (1)  Permalink

First time PHP5 troubles

Support GoPHP5.orgNach dem ich den Umstieg auf PHP5 immer als sehr problemlos angesehen, hatte ich letzte Woche das erste mal ein PHP5 Problem. Meine Gallery Installation ist hoffnungslos veraltet, zum upgraden bin ich aber nie gekommen.

Als nun ein paar Freunde viele Bilder mit dem Javaclient hochladen wollten ging gar nix. Den Fehler sieht man dann leider nicht so genau, mit ein wenig sniffen bin ich dem Fehler jedoch auf die Spur gekommen. "Fatal error: Only variables can be passed by reference in ..." meldete das Script zurück. Das Problem war relativ leicht aufzuspüren, in PHP 5.0.4 wurde am Reference Handling rumgeschraubt. Folgendes funktioniert dann eben nicht mehr:
function gr_move_album( &$gallery, &$response, &$set_destalbumName ) { }
gr_move_album( $gallery, $response, getRequestVar('set_destalbumName') );
Der ziemlich hässlich Workaround ist in diesem Moment denn Wert einfach einer noch nicht existierenden Variable zuzuweisen:
gr_move_album( $gallery, $response, $foo2=getRequestVar('set_destalbumName') );
Nichts desto trotz, es gilt immer noch "go PHP5". Mit Support für PHP4 is spätestens am 8/8/8 definitv Schluss.
Ähnliche Beiträge:
Zend Framwork 1.5 is out
Coding Contest addicted
Coding Contest
Array instead of switch-case in php
A eventfull PHP-Week
Comments (0)  Permalink

SCJP, now!

Ok, I got it! After a hell lot of work I managed today to get my "Sun Certified Java Programmer". It was just the same like with my lpic, it's really hard if you don't use the topic, you want to certified with,in your every-day-work. SCJP isn't a piece of cake, and after not writing productive Java-Code for more than half a year it was hard to survive in all the Java details they want to know.

Probably the hardest thing was to know if something get a compile- or a runtime error. I think this is also hard to figure out for very-experienced-java-senior-developer™. The other hard thing was to know all the API-Methods. To be honesty you didn't have to learn so many API-Methods, but they test if you you know the Java-Collection-Api quite well. Yeah and that's the point where my missing every-day-use nearly kills me again. And the collection-stuff was also my worst part in the test (got only 60%). And before I forget, you should really know "everthing" about Java 1.5, probably more then the half of my test was somehow related to it.

But on the other end I did quite well in the multithreading-part. Don't get me wrong, it's not easy! But after surviving marines-like "Parallel- und Netzwerkprogrammieren" (the parallelprogramming-course at my school) nothing about java-threads can anymore surprise me.

For preparation I used the "SCJP Sun Certified Programmer for Java 5 Study Guide" from Kathy Sierra and Berth Bates. The book did a quite well job. It's very well written and sometimes it even makes me laugh (not a bad thing for a tech-book). From time to time the description of some topics (specially when you knew them allready) get a bit longish. But the book describes everything you need to know for the exams and the short self test at the end of the chapter helps to find your weakness. Bye the way, the selftests are harder then the exame itself. The book-cd is a bit a crap, the not very nice looking test program (actually it looks nearly as horrible as the original testcenter interface) runs only on windows. Not the way to go for learning a OS-independent language.

And now 10 things I didn't knew about Java, even I thought I knew everything when I left university (or I have allready forgotten since then, I'm getting old):
  • In the case statement you don't have to fully reference your enum (you don't need the type)
  • In the For-Each Loop you can not define the loop-variable befor the loop.
  • You can use covariant return type, but only in Java 5
  • The method with var-args is allways chosen last
  • You can not widen and autobox arguments in one step
  • You can do "if(a = b)" (yes, with only one equals sign!) As long as both types are boolean.
  • binarySearch has the most C-like interface you will find in the Java-API.
  • If you have a "private final" method you can "override" it in the subclass. (Well, not really override, but because the private method do not exist in the subclass you can redefine it)
  • You can instantiate an inner class from the outside with "new Outer().new Inner();" (Ok, this is one I allready knew. But is still the most weird construct in Java and I think if you see this in really life it might mostly refer to a design flaw.)
  • For numberobjects with small numbers (usually bellow 127) java compare the number when you do "==", for bigger numbers java use the object reference. (Do Sun-Engineers smoke Java?)
You asking about score?! It was much better than it has to be, but for sure it wasn't a 99% certificate. But for somebody how drinks no coffee...
Ähnliche Beiträge:
Java Bug: Process.waitFor() hangs
Zend Framwork 1.5 is out
Coding Contest addicted
Coding Contest
Is Dalvik the better J2ME?
Comments (4)  Permalink

Last Minute Call for webtuesday

You still hang out in the office and have no clue what to do with your evening! Here come's your rescue, it's webtuesday again!

Mirko and I will give a talk about refactoring, it should be entertaining and not to long. My boss looks for free snacks and drinks. Just take the train to our HQ. A bit more info on the webtuesday page (english) or on the tilllate techblog (in german).
Ähnliche Beiträge:
All new webtuesday
Peter Zaitsev in Zurich
Most boring
Xobni - Pulic beta
Zend Framwork 1.5 is out
Comments (0)  Permalink
Next1-10/67