What Makes A Good Code Review?

At Eagle Eye, where I work, the question came up as to what constitutes a good code review. In any large organisation, you get a wide variety of software engineers, and all of them have different standards when it comes to code reviews. I’ve written before about why we should do code reviews, so I thought it may be helpful to explore how I approach code reviews, based on personal experience and what I’ve learnt from working with others.

While we use primarily PHP for our code, I’ve tried to keep this generic enough that the same principles can apply for any language.

Continue reading “What Makes A Good Code Review?”

Why Do Code Reviews?

I do a lot of code reviews as part of my work. If you’re a coder in an organization with more than one developer, chances are you do, too. If you don’t, you should start. You can learn a lot from code reviews, and I don’t just mean learning to be a better coder. You also learn about people you work with. And when your code gets reviewed, you can learn about yourself.

Continue reading “Why Do Code Reviews?”

Fictional Programming: Simplicity

As a coder, I like to continually draw inspiration and insight into my craft from as wide a variety of sources as possible, and one of the most rewarding sources of inspiration has been from my enjoyment of writing and reading fiction. This has been a personal pursuit, rather than with a goal of being published or becoming an author, and while I’m not going to be the next Terry Pratchett, the more I’ve explored the craft of writing, the more I’ve come to realise how the basic principles of good fiction can be applied to writing good code.

In a series of posts, I’ll explore some key principles about writing fiction, and how these can help you become a better coder.

Continue reading “Fictional Programming: Simplicity”

PHP Patterns: The Composite Pattern

A while ago, I covered The Observer Pattern, a really useful pattern, particularly when it comes to event-handling systems.

Today, I’m going to take a look at the Composite Pattern, another really useful pattern that allows you to treat individual objects and collections of those objects as if they were the same. That may sound a little strange, but we’ll look at a concrete example, which should help clarify things: a List-based system.

Continue reading “PHP Patterns: The Composite Pattern”

PHP Patterns: The Observer Pattern

The Observer Pattern is probably one of my favourite patterns.

It’s fairly straightforward, flexible, and best of all, the base classes you need to implement the Observer Pattern are available in the Standard PHP Library, so it should be available to all PHP5 applications.

Let’s jump straight in, and take a look at a possible scenario where we could use this pattern.

Continue reading “PHP Patterns: The Observer Pattern”

10 Useful PHP String-Related Functions

No need to elaborate much on this one. Here are ten very useful functions for manipulating strings. Some are very simple and straightforward, but are still very useful.

I would normally use these in class called something like Common_Strings, and make each function static but I’ll just provide them here as functions for you to use as you please.

Continue reading “10 Useful PHP String-Related Functions”

The Singleton Pattern Is Not Evil

At the recent PHP UK Conference in London, one speaker described the Singleton Pattern as being evil. The main point brought up was that it brought global variables in through the back door, including all the problems associated with them.

Well, this is true, but only to a point. Just like eating ice-cream or junk food all the time would be bad for you, so would relying on the Singleton Pattern. However, it is still a very good pattern when used in specific instances, and when used sparingly, with discipline.

So, when could we consider using it?

Continue reading “The Singleton Pattern Is Not Evil”

Tips for Better Code Comments

Okay, I’ll admit: comments are not an exciting topic for most programmers. They generally aren’t viewed by anyone else except other coders, and if we’re honest, most coders ignore them, either by folding them up in their IDE, or by skipping over them. This is normally because coders don’t think about their comments in the same way as they think about their code.

So here are the tips I’ve come across over time that have helped me make better use of comments.

Continue reading “Tips for Better Code Comments”