Friday, November 6. 2009PhotoModel vs. WorldControllerOk, everybody is using MVC now. And everybody talks about the best template engine for the View and the best Implementation of PageController pattern or such. One thing that you find only very little definition about is the "M" in MVC. The Model. Sometimes it is referred to as a ActiveRecord or any other representation of a database row. This appears much too short-minded to me. MVC is about separation of concerns. Who is responsible for what? Clearly, the View should be responsible for visualization of Data. The Controller should control user interaction and page flow. I.e. it recieves all requests, and decides what to do and what do answer after the job is done. Now, my definition of the Model is: "Facade for the Business logic". This means not more or less than a small class that offers all the Controller needs to do his work. In my world, the Controller accepts input parameters (GET, POST, SESSION, COOKIE, whatever). It checks for correct syntax and converts into internal formats (example: date fields etc.). The Model will not check for correct number or date formats. The controller then makes a model instance and calls methods with very speaking names in this model. Each Controller uses only one Model. Multiple Controllers may use the same Model if they work in comparable area of concerns. The model now takes care about all the bits and pieces it needs to process a given task. It reads config, makes DB connections, DataAccess Objects, Entity-Objects (i dont like ActiveRecord, use a JEE-like Entity approach). In bigger projects, your business logic might consist of hundreds of classes, containing factories, singletons and whatever patterns you want to apply. But the Model abstracts this all away from the Controller. This way, the structure of the business logic can be completly changed without impacting the Controllers or even the views. Models then return all values in internal data representation (example: date as JDDate or PHP-Date). The Controller passes the results to the View. The view is then responsible for giving it the right output format. This way, also some other responsibilities become clear: - Syntactical Input Check (including locale aware conversion of typed input fields to internal data formats) happens in the controller - The Model will check the passed data for consistency - Output formatting and -escaping of typed data fields is done in the view - Template translation is done in the view (template engine etc) - Models (and everything they invoke) may not access $_GET, $_POST, $_REQUEST, $_SESSION, $_COOKIE etc. - a Model may not invoke any other Model (nor Controller or View). - Communication between Controller and Model works with internal data representation For example, the Controller might get the user-id out of the session and transfer it to the Model at initialization time. The model will create a DB connection and a user-object as singletons in the constructor. ... in the controller: $photoId = (int) $_GET['photoId']; $albumId = (int) $_GET['albumId']; $m = new PhotoModel($_SESSION['userId']); $m->removePhotoFromAlbum($photoId, $albumId); $res = $m->getAlbumContent($albumId); $this->view->album = $res; // will be rendered by a cool template afterwards ... in the Model: function __construct($userId) {
$this->conn = MyDBAbstraction::getConnection($userId); $this->user = User::getInstance($userId); } etc. This way, Models stay very lean, at the same time they clearly separate the business logic from the UI logic. What google knowsGoogle released the "Google Dashboard" lately. In this app it shows all information the different google apps store about a given user. Analytics, Groups and Wave are currently not listed there. But it shows all information about Contacts, Account info, Text and Tables, Web Protocol (search queries) etc. Seems like the "We are not Evil" benefit of google is not enough anymore and they need to show us how transparent they are about storage of personal data. Thanks Google, we appreciate it Wednesday, November 4. 2009Javascript: The good parts
I cannot get around it: Just started reading an interesting book about Javascript. And i must say: After my tendency to prevent Javascript wherever possible in the past, i actually start to like the language. It has a bad reputation because it is in 100% of cases used to do DOM manipulations and browser feature enrichment and the environment it finds in today's browsers is still quite undefined and often unstable. But the language itself is surprisingly well defined and it has a lot of interesting constructs.
My favorite sentence so far: "Javascript was built on some very good ideas and a few very bad ones.". And the most interesting fact i learned: Javascript is a functional language like Scheme or Lisp. It has nothing to to with Java. Fun... Saturday, October 17. 2009iPhone verloren: Telekom gibt aufJaja, ich bin manchmal ein Schussel, alles klar. Mir ist letzten Donnerstag mein iPhone abhanden gekommen. Vergessen, verloren, geklaut, ich weiss es nicht. Jedenfalls hat niemand es gefunden. Also hab ich mich mit dem Verlust abgefunden. Nun habe ich ja diesen iPhone Spezialtarif bei der Telekom. Und da bin ich heute mal zum T-Punkt gegangen, um zu fragen wie es da jetzt weiter geht. Meine Erwartung war eine Aussage wie: "Selber Schuld, dann müssen Sie sich ein neues iPhone kaufen, kostet 250 EUR". Vielleicht, so dachte ich, gibt es ja sogar ein bisschen Kulanz und weil ich so viel Gesprächsumsatz mache, kriege ich ein neues iPhone für nur 100 EUR oder so. Aber die tatsächliche Aussage der Telekom hat mich dann echt aus den Socken gehauen: "Da können wir nichts machen". Auf die Frage, was denn werden soll, sagte man mir: "Der Vertrag ist ja für 2 Jahre geschlossen und kann auf keinen Fall aufgelöst werden." Und: "Ein neues iPhone bekommen Sie bei uns nur mit einem neuen Vertrag". Und das macht mich jetzt echt sauer, muss ich sagen. Die gehen wirklich davon aus, dass ich meinen aktuellen 50 EUR/Monat bei der Telekom 1,5 weitere Jahre laufen lasse und weil es so ein Erfolgsmodell ist, noch einen zweiten im Wert von erneut 1000 EUR abschließe, damit ich ein neues iPhone bekomme? Auf mehrfaches Nachfragen gab es keine andere Antwort. Nur die Antworten kamen in zunehmend patzigem Tonfall. Sorry Telekom, auch wenn ich für Dich arbeite, hiermit hast du einen Kunden verloren. Und zwar dauerhaft... Saturday, October 10. 2009Cash flow analysis in MS-ExcelNow to something completely different: (might be trivial for Excel Professionals, so forgive me that i am so naive) My management asked me some days ago for the cashflow of my current project. I know basically how this needs to be calculated: You define a period of time, take all money that comes in and substract all money that goes out. You do this for every period and then you have a cashflow per period. Then you want to calculate an accummulated cash flow so you see, if you need to put money into a project or if it brings in all that it costs throughout the runtime. So far, so good. But how to do it automatically. What do i have? Incoming invoices (those which are already there and the forecasted ones) with due dates: 10,000.-- EUR on Oct 03 from XYZ 5,000.-- EUR on Oct 23 from BlaBla 20,500.-- EUR on Nov 05 from ABC etc. Then the invoices we send out with their respective due dates: 100,000.-- EUR on Oct 01 50,000.-- EUR on Nov 01
Assuming, the due date of the incoming invoices is in column E of a sheet called "invoices in" and the according amounts are in column D, you would calculate the incoming amount for a given month like this: =SUMPRODUCT((MONTH('invoices in'!$E2:$E200)=10) * (YEAR('invoices in'!$E1:$E200)=2009) * 'invoices in'!$D2:$D200) This will give you the sum of all amounts (column D) where the month of the due date is 10 and the year is 2009. You can also replace the 10 by a reference to another date field (Oct 1 2009) (in cell C5 for example) and then make a table with date fields in the header for each month and below this you just fill this formula in a slightly modified form: =SUMPRODUCT((MONTH('invoices in'!$E2:$E200)=MONTH(C5) * (YEAR('invoices in'!$E1:$E200)=YEAR(C5)) * 'invoices in'!$D2:$D200) This way you can count all incoming vs. all outgoing cash. All you then need to do is to subtract and there is your dynamic cash flow. What i added then was a nice diagram of course. Works well and looks good Friday, October 2. 2009SVN update client performance under windowsAfter i re-entered the open source version management area again (used Perforce for years and i know why While most others have no problems with update performance, it is horrible for me. Our repository consists of 8 GB and a couple of thousand files and our current revision number is 18644. So nothing specatcular (with perforce we were in the 1 Million change lists area). Now clicking on "UPDATE" on my nice Vista notebook takes up to 5 minutes before the first files are actually transferred. While there was only little network traffic, HDD is working like mad. I could not explain that and so i searched for reasons online. First i suspected Tortoise to be the bad guy. But after i had de-installed it and used command line SVN i learned that it is not the case (Tortoise has its oddnesses, but my bad update performance was obviously not linked to it). Also, our server is not the problem. It works fast for other clients. Eventually i found this blog post, that gives a hint: http://svn.haxx.se/users/archive-2009-09/0879.shtml Obviously SVN is using a lot of small files to lock the local copy. And under windows this kills performance especially on notebook-hdds. The statement seems to be: Wait for 1.7 and then the locking mechanism for SVN will be replaced by something more optimized for Windows Platform. In the meantime i will have a look for acceleration for handling of a lot small writes for NTFS... Update: I have now enabled "write caching" and "performance optimization" for the harddrive i use with SVN. Unfortunately that still does not do it. SVN UP still takes 5 minutes. What i see is 100+ page faults per second, but no significant network I/O and also not too much HDD throughput (1 MB/sec). Thursday, October 1. 2009Back inAfter 2 weeks in lovely Alghero i am back in the office. It is not as warm here and the sea is missing. But the internet is much faster. And no roaming. So be prepared, Mafia Wars players! I am back in the game Monday, September 14. 2009Monopoli City Streets
Ever wondered what Google Maps was for? Of course for fun! The old idea of Monopoli now goes web and world wide. Since September 9, you can buy any street worldwide and build houses in a massive multiplayer Monopoli. What a cool idea! http://www.monopolycitystreets.com/game.html#de
Namespaces in PHP 5.3, Webcast
Interested in an introduction to namespaces in PHP 5.3?
Zend has a webinar led by Stas regarding this topic tomorrow (September 15, 9 am PDT. According to my Outlook calender it would be 18:00 german time) Javascript editor currently broken, therefore copy/paste this link for more information: http://www.zend.com/en/company/news/event/webinar-namespaces-in-the-wild-with-php Javascript vs. PHP: RIA 1.0 and RIA 2.0?
On the weekend i attended the #phpunconf in Hamburg. We had a lot of very interesting discussions there with Michael Mayer, Johann-Peter Hartmann and Cornelius Weiss about PHP in the Javascript world. In these discussions we found that there are basically two approaches discussed at the moment:
Server side frameworks integrate JS widgets into their libraries now. They try to generate JS code from templates on the server side to control the user interface. This way, forms can be enritched with some special input fields that can provide nicer user interface (for example date-pickers, grids, tab controls, etc.). The widget structure that JS libraries like dojo or JQuery provide today seem to be targeted on this kind of usage. It appears to be a solution for sites with low user interface requirmements or for a transition period. Would that be RIA 1.0? However, a lot of applications will need much more. Users demand top-level interactivity also from web applications these days. That introduces a different approach to javascript (RIA 2.0?). The server only sends one page and a bunch of Javascript to the client. From then on, the application flow is controlled by the client (JS) code. The server only supplies data here and there and executes transactions triggered by the JS application. For this kind of application, more code structuring is needed on JS side. Fortunately, there are already frameworks for this approach. JavascriptMVC is one of them. It contains a special JS-adapted implementation of the MVC pattern and is completely event driven. It even has a template engine implemented in JS in order to separate code from html when the JS app renders data from the server into html fragments to insert in the DOM structure of the page. With this kind of structure elements, the Javascript code can be structured in a way that even big javascript applications can be built, maintained and automatically tested without losing overview. For the application we are currently building, this appears the only feasible approach. Especially functional testing with tools like Selenium becomes fundamentally critical when feature rich JS applications are built. There are too many details that can break and each change needs to be tested on different browsers to do it all manually. Personally, i believe there will be both models in the future. The first approach (JS enritched server controlled applications) will probably stay around for CMS sites with little user interaction. But the more interesting model for me is the second one. This model opens a whole new world of feature ideas but also technical design and architectural challenges for the next years. Friday, August 21. 2009Tamagotchi vs. Social Networking A few minutes ago, i accidentially found an old "Tamagotchi" i got as a present quite some years ago. When i thought about it, i saw an analogon to my current use of social networks: The Tamagotchi needs attention. It requires you to think about it all the time. You just needed to invest a couple of seconds every now and then, and if you did it right, you saw it grow and prosper. Now isnt that the same principle with you Facebook account? You log in 5 times a day, look what your friends are doing, give it some food represented by tweets or picture-uploads and then leave it alone. You see your network grow and prosper over time and just as a Tamagotchi, you build something up by investing just a minute here and one there. Does that thought lead to something? Deeper understanding? No. Probably not. But i gave my Blog-Tamagotchi a little food again...
Monday, August 17. 2009automated build process
A couple of years ago, everybody was fascinated by automating build processes with ANT. This more modern version of MAKE worked with XML (how hipp) and Java. Instead of the old shell-level make environment, everything was contained in nice java packages and quite extendible. Some PHP users (including me) hopped on that train to automate packaging and some build-like PHP postprocessing. With PHING, even a PHP version of ANT is available. Nowadays the java guys have moved forward. Martin Fowler described in an article in 05 the benefits of the Ruby driven domain specific scripting language called RAKE over ANT and MAKE. In other places you read that build scripting has large benefits over configuration based systems especially for large systems. It seems like innovation is more and more driven by Ruby these days...
Since i am a PHP guy, i asked myself a few questions instead of just repeating the Java world (which i used to be part of some years ago, but now things are different). What do we need from a build system in PHP? - SVN support - ZIP support - Embedding of a JS compressor (ok, that was not easy, needed rhino which is java again) - manipulating / generating config files out of configuration databases - logging of deployment processes - building RPMs - transferring packages to remote systems - calling web services to unpack there So guess what: I think the perfect scripting language for this job is: PHP! We built a small management system and some scripts in PHP and voilà: It works fine. Even more interesting: No special knowhow needed. Everyone can look in the code and understands how the build process works. And virtually no limits! We even fake a Browser and use the customer's web based upload service directly from our build system. And if we need to change the process: It's easy, all PHP. I think we have a good solution now... Friday, July 31. 2009Virtualbox and VMWare not running on Ubuntu 9.04 due to KVM kernel moduleIt turned out that the Q8200 processor i had in my machine at home was the only 4-core from intel without virtualization support. Therefore i could not run 64Bit clients in VMWare or Vitrualbox. So i went into a shop and bought a shiny, new Q9400 instead. I went home, installed it and started my system, expecting more power and 64-Bit Support. But the effect was that neither VMWare 2.0 nor Virtualbox could start an image anymore. Not even 32 Bit images. A little research showed what the problem was: The kvm kernel module that comes with Ubuntu by default, could not be loaded with the old processor because of missing hardware support. With the new CPU, it loaded. Obviously the kernel module prevents the other virtualization engines to work. De-Installing KVM was no option for me because i wanted to use it also for some tests. Therefore i searched for other options and found one in the ubuntu forum. The solution that worked for me was to just unload the kernel modules before starting VirtualBox: modprobe -r kvm_intel Thursday, June 25. 2009Der Alvar im Fernsehen
Gestern abend zappe ich durchs Fernsehen und was sehe ich? Nachdem in Hart aber Fair eine Diskussion über das freiwillige "Entbößen" in den Medien zu einer Internet-Verständnisdiskussion abglitt, kommt auf Phönix mein alter Bekannter Alvar Freude in Diskussion mit Ossi Urchs und einer als Internetkritikerin auftretenden Journalistin zum Thema "Außer Kontrolle. Welche Macht hat das Internet". "Werden „Twitter“ und „Facebook“ reale menschliche Beziehungen immer
mehr ersetzen? Und wie viel Freiheit verträgt das Internet überhaupt?" Da gibt es wohl einiges gesellschaftlich aufzuarbeiten...
Wednesday, June 24. 2009Internet und Politik
Politiker gehören offenbar - trotz ihrer Kommunikationslastigen Arbeit
- zu den eMail-Ausdruckern in der Internet-Bedürfnispyramide. Aber auch
das scheint sich langsam zu ändern. Während hierzulande offenbar Ignoranz und Unverständnis vorherrschen, gewinnt man in den USA Wahlen durch konsequenten Einsatz von Blogs, Twitter, Video-Plattformen...
« previous page
(Page 3 of 9, totaling 121 entries)
» next page
|
Calendar
QuicksearchCategoriesSyndicate This BlogBlog AdministrationTop ReferrersChoose Language |
|||||||||||||||||||||||||||||||||||||||||||||||||
A few minutes ago, i accidentially found an old "
