Matt McCormick

Forget Sunscreen….Focus

Posted on October 21, 2011 ·2

Focus. If I could offer you only one tip for the future, focus would be it.

In the next 20 years, we are going to face an extreme shortage of people who are able to focus single-mindedly on what they are doing. Children growing up these days face an onslaught of distractions thanks to news feeds and smartphones and it is only going to get worse.

Why is this a problem?

People cannot multi-task well. I know there will be many people who say they can, but they can’t – at least not on a task that requires concentration and focus. If you think multi-tasking is fine, answer me this: if you were going into surgery and saw your surgeon preparing while checking his mobile phone messages and watching TV, would you feel comfortable?

The ability to focus is a habit that can be trained or drained. Growing up in a distraction-oriented world, this will be a problem because the best work gets done when someone is focused on what they are doing.

When programming, my best days are when I don’t even check email until the end of the day. I have my tasks laid out and just start on them. When I need a break, I take a break but focus solely on the break during that time. Then when I am refreshed, I get back to work and focus just on the work. Days like these are bliss. I finish work feeling energized and enthusiastic.

The worst days are days I usually check email first thing in the morning. Immediately the distractions start. And even though I may check email only for a few minutes, it can throw me off for the rest of the day. On these days, I finish work feeling drained of energy and wondering what I got done.

My first full-time job after university was at a large, bureaucratic organization. As part of their IT policies, they blocked access to “time-wasting” sites like Gmail and Facebook. At the time, I thought this was a horrible, Orwellian thing to do. By restricting access, they were treating employees like children instead of trusting people to get their work done.

Now, I realise there is some benefit to this course of action (although it is better for people to figure it out for themselves – you can’t block every non-work essential website).

How to focus

What is focus? Focus is setting limits on yourself. In today’s world where most North Americans are in debt, setting limits is something that very few people do. The average person might even be annoyed at just the idea of setting a limit on themselves. Most people don’t even limit their spending to the income that they earn. After all, it benefits others when you don’t set limits on yourself. I hear advertisements all the time saying things like “Buy this. You deserve it.” I never hear an ad saying “Buy this if you have the money saved and can afford it.”

Luckily, the ability to focus can be improved just like any skill.

There are two parts to it – mental fitness and physical fitness

Mental Fitness

I meditate for 15 minutes a day in the morning. There are different kinds of meditation but for improving your focus, the best one I know of is just trying to focus on your breath and only your breath. Whenever another thought or sensation enters your mind, just picture a bubble or cloud forming around it and floating away while you come back to focusing on your breath.

It can be a very challenging activity. Currently, I can only last up to a few minutes before getting distracted without even realising it. However, improvement comes with practice.

After a couple weeks, you should start noticing that you are able to focus more while working. You will build up higher resistance to those thoughts that enter your mind throughout the day which tug at you saying “Let’s just check Facebook for a few minutes…” This will help you get more done in less time.

Physical fitness

It should go without saying but being physically fit helps you in so many areas of your life, focus being one of them. Your body can only expend so much energy at one time and if you are unhealthy, your body needs to spend more energy to keep your heart beating or your lungs breathing. The more energy your body uses keeping you alive, the less energy you have to expend on the task at hand.

As we get further along in the technological revolution, the focus divide between people is going to become more noticeable. If you want to set yourself apart from your peers, train and improve your ability to focus. While other people are distracting the day away, you will be able to accomplish more in much less time.

Focus.

Categories: Productivity, programming ·

How to Refactor a PHP Application

Posted on October 13, 2011 ·0

The great thing about PHP is how easy it is to get started.

The bad thing about PHP is how easy it is to get started.

I’ve worked on a few PHP sites where the code lived up to these statements. While it is incredibly easy to get a site up and running with PHP, that ease of getting started could turn into a nightmare as the site grows and becomes more complex.

When you’re faced with a site which has no separation of view code, business logic and model code, it can be daunting to figure out where to start. Here is a simple list you can follow to keep from getting overwhelmed.

1. Write PHPUnit Tests

In Martin Fowler’s book on Refactoring, he proposes to always write tests before changing code. It is an easy way to know that the output remains the same even if the underlying code has changed. I think this is a great practice to follow, however, with a PHP site that may not necessarily be broken into neat, testable units, this may be a difficult process to follow.

Edit: Since I posted this, I came across the SimpleTest testing framework which provides an excellent format for testing PHP applications by imitating the browser.

2. Create models

If you have MySQL queries mixed in with HTML code, the first thing I like to do is get that SQL outta there! SQL should only be seen inside model classes. Each mysql_query() function should be replaced with a call to a model’s method for the table that is being accessed. For example, if there is a statement like:

mysql_query("SELECT * FROM users WHERE id = $id");

I would create a Users.php class that can be used as a model for the users table. Since the code above is needed quite often, it would be a good idea to have a parent class that the Users class can extend from which implements something like a find_by_id() method.

That would allow you to something like:

$users = new Users();
$user = $users->find_by_id($id);

If the site isn’t using PDO, this is also a good time to set that up. There is no reason not to be using PDO these days. It helps with security and Object-Oriented design while keeping queries cleaner.

3. Consolidate duplicate code

I’m a big fan of DRY – Don’t Repeat Yourself – and have worked many times with sites that have a lot of duplicated code. After separating the models, identify duplicated code and start separating that code into libraries. Use a tool like PHP Copy/Paste Detector which can help identify duplicate code or just keep your eyes open for code that looks like you’ve come across it before.

4. Separate views and controllers

Once the model code is separated out, the view and controller code should be separated from each other. In combination with the previous step, sometimes the header or footer HTML might be duplicated throughout the site. It’s good to create a standard layout that contains the common HTML. You might choose to use a templating tool like Smarty which can help to make sure PHP code stays outside of your templates and views.

5. Clean up PHP errors and notices

Make sure you have PHP error_reporting turned on to include all errors including Strict. (In PHP 5.4, E_STRICT will start to be included under E_ALL). This can help you identify stray variables, deprecated code, non-existent array indexes and much more. Cleaning up these errors and notices will make your application run smoother and can help reduce bugs.

Refactoring a whole PHP application can seem like a daunting task. Depending on the size of the application, it’s not something that can be done overnight or even within several weeks. It may take several months of minor, gradual improvements but the end result will be worth it. You’ll be able to add new features quicker, reduce the number of bugs and increase your enjoyment while working on the application.

These steps may not all be applicable to your refactoring challenge but the key thing to keep in mind is to break down a large and complex refactoring job into a series of smaller parts and steps.

Categories: software ·

Everybody Loves Learning

Posted on October 1, 2011 ·0

A few weeks ago, my 2.5 year old niece was over in the evening. She was running around as usual. As I sat down to read something, she watched me turn on a lamp. As soon as she saw the light come on, she came running over to see what kind of magic had just taken place. Seeing that she was interested in this wizardry, I turned the lamp on and off a few times so she could see how it worked. Then she wanted to try. This lamp has one of those switches that you need to turn and her motor skills aren’t quite developed enough yet to be able to hold the knob firmly. She tried but couldn’t quite do it. I turned it on a final time and started reading.

A couple days later she came over again and saw the lamp again. She immediately went over to it and wanted to try again.

Just do a search on Youtube for baby ipad and you see dozens of videos of 2 and 3-year-olds going nuts on the thing. They just jump right into it and try everything. No fear.

This is a great example of how kids just love trying things:

The amazing thing to me is that everybody used to be like this at one point. Unfortunately, growing up in systems like school where a lot of the learning is forced on to people, many people lose this excitement around learning. Instead of learning for its own sake, now it becomes about grades and the results. In high school, when questioned about the value of going to school, some teachers would reply that “You’re in school to learn how to learn.” That’s complete BS. Everybody knows how to learn from birth. We don’t need to be taught it. Did you need to go to school to learn how to walk or talk?

About 10 years ago, one summer I worked at the local library teaching free lessons to people how to use the Internet. The Internet was just reaching its critical mass stage where everybody was hearing about it. Most of the people who came were elderly – probably in their 70′s or 80′s. It was an incredible experience for me in seeing how people new to computers use them. It was also an eye-opening experience of how people’s mindsets affect their learning ability.

Some people would come in and say to me “I really want to learn how to use the Internet.” They would be very open-minded and would pick things up very quickly.

Other people had an incredibly tough time learning. Some people came back week after week and would repeat the same mistakes they made the previous week. They wouldn’t pay attention to what I was saying and would get frustrated. One specific guy I remember was telling me about how he had just been fired but he was swearing throughout the whole lesson and had a very negative attitude about pretty much everything. It shouldn’t be surprising that this guy had a really tough time learning. He ended up leaving after only half the lesson as he just got too frustrated.

The thing is, we all started out as those kids we see in the videos. We all enjoyed the process of learning how to walk, learning how to talk, learning how to hold things, learning how things worked. We all had incredible enthusiasm around learning.

Unfortunately, many people lose this enthusiasm as they grow up. Instead of something fun, learning becomes a chore. Instead of just enjoying the process, people focus on results. It becomes a matter of “What am I going to get out of this?” instead of just being curious about things.

We were all like those kids at one point. And because that passion for learning was within us at one point, it can be revived and re-discovered again.

Categories: Life ·

Make Time for the Long Term

Posted on September 22, 2011 ·0

The biggest mistake I see with fellow colleagues are people that just focus on the immediate tasks at hand. Day after day they only work on the tasks given to them and just try to get them done. Focusing on the immediate short-term tasks all the time is a recipe for mediocrity. It also leads to boredom.

Everyone should block off a portion of their day for thinking long-term and investing in skills that may pay off later. Unfortunately, many work places don’t see the value in doing this.

Do it anyway.

My first job post-university was relatively slack. There would usually be extra time every day. Luckily, this workplace had an awesome IT library with pretty much every technical book I could want. (This was before I discovered Safari Books Online) Knowing that I had extra time, one day I decided to bring in “The Mythical Man-Month” to work to read on my downtime. I figured since it was a book about IT projects, it was related to my work and should be no problem for me to read.

After I started reading, my manager came by and asked what I was doing. I said I was learning. He looked at my book and told me “You can’t read here. If you need something to do, ask me and I’ll give you something.” That was probably the moment that I knew I wouldn’t work there much longer. From then on, I just read on my computer so he wouldn’t know.

Some people might say “You shouldn’t be reading on company time” but as long as it is related to the work you’re doing, I see it as a benefit to the company. After a while of doing this, I definitely noticed that I was progressing faster than colleagues and that long-term investment started to pay off in my work. A couple times, senior developers with many years more experience than me would be discussing a problem and I would propose a solution from something I had read which they then implemented. These are the times when the long-term investment starts to yield short-term rewards.

Only enlightened managers will understand the payoff an hour or two of long-term investment can bring and, unfortunately, we can’t all work for the enlightened ones. That is why, as a programmer, you need to take control of your own craft. Software development is a profession that not everyone can do. It’s kind of like plumbing in that aspect. Most of the people who plumbers work for do not know anything about plumbing. Most of the people software developers work for know next to nothing about software development. Remember that you are responsible for being the expert so be sure to develop your expertise.

Categories: Productivity, software ·

Book Review: The Passionate Programmer

Posted on September 16, 2011 ·2

The Passionate Programmer

The Passionate Programmer is a book everyone in software can benefit from. For those of us working in software, there is the tendency to get complacent. After all, salaries are usually pretty good, working conditions are generally comfortable and good software developers are usually in demand. I know I’ve gone through phases in my career where I let myself get a little too comfortable. Maybe I stopped reading regularly about technology or stopped building things on the side.

The Passionate Programmer offers many ideas for how to improve your career. As with all self-help books, it would be impossible to implement everything but I think each person could find a couple ideas that can improve your work and your well-being. Early on in my career I wasn’t sure if I wanted to continue software development. At one time, I wasn’t very happy with what I was doing. However, once deciding to continue, I wanted to be the best I could be so I started to get more interested in learning about software development. I found that as I began to learn more, I naturally became more interested in my work.

I think this is the premise behind “The Passionate Programmer.” To become happy with your work, you need to put your full effort into it. I think we all know this. If you think of who is happier – a person giving their full effort or a person who is just trying to do the minimum to get by – the answer is obvious to us. It just jumps out in our mind that the person giving their all will feel more fulfillment. You get out of life what you put in to it.

One of the chapters that jumped out at me was “Learn to Love Maintenance.” The title will be an oxymoron to most developers for obvious reasons. Everyone loves building new things. The times in my work where I have been the most engaged have definitely been when I have been involved in building new things. It’s understandable. Progress is made quickly in new software projects and you know at the end of the day just how much you accomplished. Maintenance doesn’t offer those quick wins as much and yet more time is spent on software maintenance than developing new products. So no matter your career path, odds are we all have to do maintenance at some point. We might as well enjoy it.

In short, the points of this book can be summed up as:

  • Learn the business side of software
  • Invest in keeping up with new technologies
  • Promote yourself
  • Enjoy what you are doing

If you are currently excited about software development then this book may not help you much at the present time. If, however, years down the road you start wondering “Where did my passion for software go?” or if you are currently in this situation then this book may just help you wake up and re-discover your passion.

Categories: Books ·