Refactoring Your Code

As mentioned in my earlier article, Technical Debt, refactoring your code is very important.  It’s the primary method of managing/reducing technical debt, and helps to constantly improve your codebase. However, knowing what to refactor, what to refactor first, and how to refactor code isn’t always obvious.

What Is Refactoring?

Refactoring is the act of modifying the internals of your code, normally without altering it’s external behaviour. For example, you could change the algorithm used in a function to make it more efficient, without changing what that function returns.

The reason you want to constantly refactor your code is to improve it, as you should always be learning new things. You’ll find faster/cleaner ways of doing something, you’ll learn about potential exploits or bugs in functions, and maybe you’ll just reread your code and realize your comments aren’t as helpful as you first thought. By refactoring your code, you aim to increase the quality of your code.

Continue reading

Technical Debt

Technical debt is an issue that all programmers have to deal with at some point in their careers, and more often than not, it’s an ongoing issue. What is technical debt, you ask? When you do something the quick & dirty way, such as patching up a bug without fixing the underlying issue, or prototyping a new feature and using that code in your live environment, you accrue technical/code debt.

Like most forms of debt, you have to pay interest on technical debt, in the form of extra time spent working with said code at a future point in time. That bug you patched up might cause other issues somewhere else in your code, but you want remember why in 6 months or if somebody else takes over your project. They’ll have to track down the cause of the unexpected behaviour and fix it again, which will take longer than fixing it the first time around, when the issue and cause was fresh in your mind.

Continue reading

My PHP Router Class

Recently I had some spare time and decided to rewrite the PHP Router I’ve been using on many of my recent projects. I prefer to have my projects setup with .htaccess which redirects all page requests to index.php which uses my router to decide which function to call. This approach allows me to write very clean, modular code.

My new router is very flexible, supports unit testing and can be extended. I’ve attached the source code to this post as well as an example of how to use it.

Continue reading

PHP 5.4.0 Is Now Available

It’s been an exciting first quarter this year in technology. Apache HTTPD 2.4 was just released (Apache is a very popular web server and this was a significant upgrade), and now PHP 5.4.0 just went live.

PHP 5.4.0 is a big upgrade that I am very excited to start using. It includes a feature called traits that works like multiple inheritance, only horizontally not vertically. Anything that minimizes code reuse is a good idea in my mind.

Continue reading

My Experience With Bootstrap

If you’re in the web development world, you’ve probably been hearing about Twitter Bootstrap, a new HTML/CSS framework that takes some of the tedium out of setting up a web application. Instead of worrying about creating basic styles for forms, layouts, tables, etc., you can just jump in and start coding your application.

For me, it’s an absolutely fantastic resource. I’m rubbish at designing the small details for an application. I know how I want things to be laid out, function, etc., but when it comes to making a button that looks nice or making form inputs look just right, I start to struggle. Bootstrap solves this issue for me, and allows me to do what I do best: program.

Continue reading

FizzBuzz Examples

FizzBuzz is a very popular “test” used when interviewing programmers. It’s mostly used to filter out people who can’t actually program. Now you may wonder why such a test would be necessary, after all, why would somebody who can’t program apply for a programming job? The unfortunate truth is, many people believe they can program (Some CompSci graduates for example), when in reality they may have a strong theoretical knowledge but no practical experience. There are also people who think it’s easy and they can pick it up as they go (I’ve had a couple of these people come in when I was interviewing programmers to replace me an an old job).

Here is how FizzBuzz works. The interviewer asks the interviewee to write a program in a language of their choice (Or a specific language depending on the job, maybe even pseudo-code). The program should count from 1 to X, X being a random number such as 20 or 100. For each multiple of 3, the program should output “Fizz” instead of the number. For each multiple of 5, the program should output “Buzz” instead of the number. For each multiple of 3 AND 5 the program should output “FizzBuzz” instead of the number. It’s a very trivial task for any competent programmer, and the output should look like this:

Continue reading