Should a failed function return a value or throw an exception?

Thursday, March 11th, 2010

You have created a nice, well written function, but you realize you forgot something: The failure case. What should a function do when it fails? There are two schools for this - the "throw an exception" school and the "return an error value" school. But which of these is the correct ...

A simple way to make your code better: Stop adding more parameters

Wednesday, November 11th, 2009

You need to add some new functionality to your function or class. Let's say you need to remove all objects stored, but optionally also call a method on them. It's pretty simple, isn't it? Let's just add a parameter to removeAllObjects! If you make it true, the additional method is called, ...

Is commenting your code useless?

Thursday, October 15th, 2009

James Carr has written a well argumented post about comments. To sum it up shortly, he says comments are the lowest form of communication, and that commenting freshly written code is not a good idea. I tend to disagree, and here’s why.

Improving code with peer reviews

Tuesday, September 1st, 2009

Peer reviewing is the practice of looking at code written by others to find errors or ways to improve the code. Sometimes also called desktop reviewing, this approach can be useful for various reasons: If you have a coworker who is more experienced than you, you can learn from him/her It's often ...

Decoupling models from the database: Data Access Object pattern in PHP

Monday, January 5th, 2009

Nowadays it's a quite common approach to have models that essentially just represent database tables, and may support saving the model instance right to the database. While the ActiveRecord pattern and things like Doctrine are useful, you may sometimes want to decouple the actual storage mechanism from the rest of ...

Food for thought: utilizing models in MVC

Saturday, December 6th, 2008

"What is a model" and "Is Zend_Db_Table a model" seem to be asked once in a while on #zftalk. Frameworks say they have a full model available, thus they are MVC frameworks ORM libraries say they generate models. It seems the ActiveRecord pattern has become somewhat synonymous with model. Pádraic Brady ...

Base classes in OOP programming languages

Wednesday, November 19th, 2008

David Otton posted a short but thought-provoking post about stdClass, which many think is the "base class" all PHP classes automatically inherit from. I have to admit that I had this misconception as well. On the other hand, "true" OOP languages such as C# and Java both have a base class ...

You should know at least three languages

Saturday, September 20th, 2008

I think a good programmer should know at least three languages: English C or C++ A scripting language with dynamic typing Why?

Theory vs. Practice in coding

Tuesday, September 9th, 2008

When working on a project, I sometimes find myself stuck - thinking about some implementation detail, such as how to tell my admin-module which other modules are installed in my CMS (but that's another story) - and being stuck, unable to get anything done, just thinking of the problem at ...

On template “tag soup”

Tuesday, July 22nd, 2008

Jeff Atwood's latest post (at the time of writing this) talks about mixing HTML markup and server-side code, àla He also throws in the question: Is there a better way? - However, it seems there's at least as many ideas of a ...