Advice for New Software Developers

June 1st, 2011

When starting a new path, it is often difficult to know which way to go. Some good advice I once received is that when people are starting something new, they need to be told exactly what and how to do it. It is only once they have a bit of experience that you can remove the “how” from the equation and just say what needs to be done.

For new programmers just getting started, here are the steps I recommend taking until you understand your working style better and can make adjustments.

1) Understand the problem

What you are trying to accomplish should be clear in your mind. You should know what will happen once the task is complete and what the user will see. If you are confused about anything, as a developer, it is your responsibility to ask for more clarification until your are clear about it. There is nothing about writing code at this stage. Often times, developers just want to jump right into coding but understanding the problem is paramount.

2) Plan your approach on paper – pseudo code

On a piece of paper, away from the computer, write out all the steps necessary you think it will take to accomplish the task. Don’t write any programming code. This should be pseudo code and written in plain English. Write one action per line. The more detailed, the better.

If you get stuck on part of it, then you do not understand the problem well enough. Go back to step 1 and get it clear what you are trying to do. Notice, there is still nothing about writing code at this stage.

3) Understand existing code

Once the pseudo code is written out and your plan makes sense, now you can find the files and the areas that you think you will need to modify in existing code. You should read the surrounding code and understand it first before making any changes. If you do not understand it fully, there is a greater chance that any changes you make will introduce more bugs. Notice, there is still nothing about writing code at this stage. So far, it has been all understanding and planning.

4) Write code, one line at a time

Ok, now you can start writing code because a) it is clear what you want to accomplish and b) you understand the existing code well.

NEVER, EVER copy code from somewhere else. If you do find code somewhere else that (once you fully understand it) you think applies to your task, then type it out line by line. You may think this will be slower but making sure you understand what you are doing ALWAYS saves you time down the road. When typing it line by line, you should be reading it and understanding it as you go along. If you are copying and pasting code, alarm bells should start going off in your head.

When writing code, only write out enough code for one of your pseudo-code lines. Do not write out everything. Start at the first line written on the paper and then convert that into actual code. Then go on to the next step.

NOTE: this stage should actually take the least amount of time in the process. Yes, it’s a little ironic that as a developer you’ll be spending the least amount of time writing actual code but you should be spending the majority of your time understanding the problem, planning it out, reading and understanding other code and testing your work. If you are spending the most of your time here then there is something you do not understand well enough. If it is the problem, then go back to step 1. If it is the other code, then you need to read and understand more. If it is the programming syntax then you need to read and understand more about the applicable programming language.

5) Test what you have done

For each line of your pseudo-code that you have written in actual code, test it to make sure it is doing what you expect. Do this immediately after writing the code! You do not want to write a whole bunch of code and then find out that it is not working somewhere. You should be testing after each step so you can fix it at that point while it is fresh in your mind instead of finding it hours or days later and you have to think again about what you were doing. If you test it and it works as you expect, go back to step 4 and write the code for the next line of your pseudo code.

6) Don’t give up

You are probably closer to the solution than you realise. Have you heard the story about the gold miner? During the gold rush he bought a mine and after weeks of exploration, found gold. Experts said that he had found one of the richest mines in the state. Returning with more equipment he spent time mining but no more gold could be found. Frustrated, he finally gave up and sold the mine. The new owner brought in an expert to assess the mine and he discovered that the main vein was just a few feet away from where they had stopped mining.

Sometimes it can be frustrating when you are programming and going in circles. Instill good habits at the start of your programming career and they will treat you well down the road. Be as orderly about your programming style as your code and you will find a successful career as a developer. I wish you the best.

Did you find this article valuable?

How to Find Your Passion

December 20th, 2010

Did you find this article valuable?

Why I Don’t Have a Girlfriend

October 31st, 2010

This is a speech I wrote for the Toastmasters Humourous Speech contest. Unfortunately, I didn’t have it completed in time for the contest so I delivered it a couple weeks later. There were some jokes that didn’t come off as funny as I didn’t deliver them well. I think this is a speech I could refine to make it much funnier.

Welcome guests.

Chinese are very inquisitive people. When I lived in China, some people would come up to me and they would ask me things like “How much money do you make?” and “Are you married?”. If I answered “No, I’m not married” they would follow up with “Well, do you have a girlfriend?” If I said “No” again, they would get a perplexed look on their face saying “Why not?”. They couldn’t understand this.

I think this is because in China they have girlfriend shops scattered around town. And when you do not have a girlfriend your friend’s job is to take you to one of these shops so you can pick out the latest model. You walk through the store with them and say “Oh yeah, I’ll think I’ll take Girlfriend 3.0 there.” She’s not as up to date as the 4.0 model but not as costly and she runs well. So I’ll go with that.

Unfortunately, none of my Chinese friends ever took me to these girlfriend shops. And I think because China has a lack of women that these places are off-limits to foreigners. They’re trying to keep all the women in China. No foreigners allowed to choose girlfriends.

But it’s a good question – Why don’t I have a girlfriend?

And unfortunately, I consider myself a shy guy which is a disadvantage when it comes to dating. So, at the beginning of this year, as part of my goal setting I set a goal to regularly ask out women I was attracted to. And as the year has gone on, I think I’m becoming better and better at it however, still no girlfriend.

I have discovered one thing though and that is women have a very special talent. They are very good at coming up with excuses when they don’t want to date someone.

Let’s see here, some of the excuses I’ve gotten have been:

- The standard “I have a boyfriend” which may be true, may be not true
- I’m going on vacation in a couple months and don’t want to get involved – ok, I can see that. It takes a couple months to pack and get ready with airline security these days.
- I’m busy at my job and I just can’t find an hour to meet with you over the next month or so.
- I’d like to meet you but if I meet you I want to bring a bunch of my friends. I don’t really want to spend time just with you.
- I only like married men.
- I’m don’t really know if I’m into this whole heterosexual thing. It’s not for me.

Although a good one I had was when I did have a woman who said “Yes” to meet for coffee next week. So when I followed up with her and said “Do you still want to meet up this week?” She just simply said “Mmmm, No.”

So at least she didn’t give me an excuse because I find these excuses – they’re very frustrating to figure out. I know they’re just excuses and I know I’m the common denominator so it’s complicated. What can I do?

Unfortunately, what I wish there is like Toastmasters for women – women masters – where someone could follow me around and give me feedback and evaluate me on at the end of the day on well I did. That way I can get feedback on my strengths and weaknesses that I can improve for next time. Unfortunately, Toastmasters hasn’t branched out of public speaking yet. Hopefully in the future.

So I realised I needed to figure this out for myself.

So many nights I went trekking up Mt. Doug and meditated on this problem – Why don’t I have a girlfriend. Finally the answer came to me.

So the reason is…

Oh, this is too embarrassing. I don’t know if I should really say. I don’t know if you really want to hear. Do you guys want to hear?

Well, the reason is….I’m just too perfect.

Yes, I may just be the most amazing guy in the world, God-like if you will.

And this is a big problem because one other thing I’ve learned about women is they like to get a guy they can fix up. When they get a boyfriend, it’s their own personal renovation project. They want, you know, they want to change different clothes, differently ways of talking, interact with different social groups. It’s just a big improvement project to them. So when women meet me they take a look at me and they think “What could I possibly do?”

So this is a big problem to me and I know…

Yeah, so they can’t fathom this, and that’s why they come up with all the excuses.

So I want to give a message to all you ladies out there. To just make it easier on yourself and for me next time. So that you don’t have to come up with excuses just say the truth next time.

“Matt, you’re just too perfect.”

Don’t worry. I’ll understand.

Did you find this article valuable?

Programming Spiritually

October 28th, 2010

If you are a spiritual person, you may sometimes wonder how programming connects to the bigger picture. Working in front of a computer day after day can seem like an activity most removed from the world, nature and God. Here are some things to do to feel more connected:

Awareness of Thought

You are a complete individual connected to a higher source. This higher source offers answers to any question you throw at it. It is extremely important to be aware of your thought process while programming. Often running through my mind are questions like “Why is this not working?”, “Where is the problem?” and “How can I solve it?”. It never fails that I receive answers to my questions. Sometimes they come quickly. Other times, I may need to take a break and go for a walk so that I can be open enough to receive the answer. In cases of extreme disconnect, a good night’s sleep will relax me and let the answer flow in.

Untruthful thoughts should be avoided. These thoughts question and doubt the power within you. Some examples being “I can’t figure it out”, “It’s too complex for me to understand” or “The person who wrote this code is an idiot.” True, the code may not be up to par, but that is just an indication that the previous programmer could be lacking knowledge or experience, not that they are a stupid or bad person.

The Ripple Effect

Everything in the universe is connected in a vast web. Each created thought or action gets sent out as a wave throughout this web. It’s like dropping a rock in a pond. When you drop the rock, the water is affected the most immediately around the entry point. The waves start out high and become calmer and calmer as they get further away from the entry point until they are not noticeable anymore.

When fixing a bug, be aware that any changes you make are going to have an effect throughout the system. Before making the change, think about what possible effects this change could have on other parts of the system. Nothing is isolated.

When designing a system, one can help this situation through abstraction. Abstraction is like taking a big bowl of water – your system – and pouring it into several cups or glasses. Now if you drop a stone into one of the glasses, the ripple effect will be limited to just that glass.

Be Present

Use the power of focus to help you maintain a flow-like state. Email and IM notifications are a distraction which take you away from your present. Anytime something comes up, you should be asking “Does this contribute to my present?” I have always disabled email notifications and deal with my email twice a day at set times. This allows me to focus on my present and still get back to people in a timely manner.

Programming is your craft. Cultivate it. Your personality and character is expressed through your work. Make it worthy.

Did you find this article valuable?

Things You Didn’t Know About Victoria

August 11th, 2010

This is my 7th Toastmasters speech from the Competent Communicator’s manual.

Thank you Madame Toastmaster, fellow Toastmasters and welcome guest.

Do you know what I like about Europeans? They know their history. Just look at Graham here. Graham can probably tell you everything about British history – all the relevant and irrelevant facts dating back hundreds of years. I lived in Europe for a year after university and I realised this isn’t unique amongst Europeans and British.

Most of the friends I met there could tell me all sorts of details about their hometown. They would invite me to their hometown for a day or a weekend and as we’d be walking around they’d point out “Oh this building was designed in 1405 by Sir Black” or whatever. “This statue was donated to us from Italy in 1692.” And I would ask them “How do you know all this stuff?” and they’d say “Well it’s my hometown, of course it’s my duty to know all this stuff.” And I think, well, here in Victoria I don’t know anything about my hometown. That’s one of the differences between Europeans. They’ve lived there their whole lives and their family may have been there for generations whereas here not many people stay in Victoria. For instance, how many people were born in Victoria? Two people. So Victoria’s a very transient place and I don’t know much about it. So for this topic of researching your topic, I thought I would research a little about Victoria.

Most of the stuff I do know about Victoria comes from walking down Government Street and as I walk along the streets, the Kabuki Kabs go by – the little peddlers – and so for a few seconds I’ll hear them explaining to the tourists some interesting tidbit of information. Over the years, I’ve gathered a little bit of history that way but still not really enough. And I don’t know if it’s true. Sometimes I think they’re just making it up. They could be just telling stories to the tourists to get more tips.

So one story I hear sometimes is that the Parliament Buildings were designed by someone who came over from Britain who had no training in architecture, he lied about buildings that he developed in Britain and then he was murdered by his wife. So I wanted to find out if this was true or not.

In fact, it is partly true. The Parliament Buildings were designed by Francis Rattenbury. He came over from Britain to BC in his 20s. At that time the government had an open competition for designing the Parliament Buildings. Anyone could enter with their designs. He entered and he beat out almost 60 other applicants. He didn’t sign his name but he submitted it under a pseudonym called ‘A B.C. Architect.’ He did, however, have a little bit of training. He had no formal education in architecture but he had done an apprenticeship with a firm in the UK for about seven years before coming to BC. However, beating out 60 other people is not that easy so maybe he did have to fib a little bit on his application. I never found that out.

After designing the Parliament Buildings – after building them – he went on to do a number of other buildings in Victoria including one of the other famous buildings, the Empress. He was commissioned by the Canadian Pacific Railway to do that and he was also designed the old Carnegie Library on Yates Street on the corner of Yates and Blanshard and the old Bank of Montreal on Government Street which is now the Irish Times as well as Crystal Gardens. So he had a big impact in Victoria for developing our architecture.

Unfortunately for him, he never really found success after Victoria. He started to…His personal life started to come unravelled a little bit and in his 40s he divorced his wife to marry his 27 year old mistress at the time or girlfriend. He left his children and his wife and they went back to England.

At the time he was going through financial troubles through investing in poor business ideas and whatnot, and that continued in England at the time. After about 10 years his wife, kinda did the same thing. She had a ‘mister’ who was actually their 18 year old chauffeur. And they formed a plot to kill him so that they could be together. They actually did murder him, 10 years after they were married, and he – the chauffeur – ended up going to jail and his former wife committed suicide a few days after the trail was over.

He was buried in an unmarked grave somewhere in England, until just a few years ago when a family friend finally put up a tombstone for him.

So this is the man that helped develop Victoria around here – our designs. He was a cheat and squandered all his money.

In a way it’s kind of fitting that he designed the Parliament Buildings.

Did you find this article valuable?

Learn Quickly: How to Soak up things like a Sponge

August 7th, 2010

All my life I’ve been able to pick up things very quickly. This has led me to being bored with classes at times since they need to go at the pace of the average learner. I still remember taking Math class in high school. One year my teacher would assign the homework due for tomorrow at the beginning of class. I would usually just ignore what he was talking about and read the textbook and do the homework in class. Often I would be finished by the end of the hour.

When I’m learning something new now, I’ll often look around at other beginners and see them struggling with things while I’ll be ready to move on. I often wonder what is the difference? I have no doubt that some of it might be due to nature and genetics. But I have also noticed general things I do that allow me to learn faster than others. Here is what you can do to learn faster:

Adopt a Learning Mindset

This is probably one of the biggest aspects. People are 99.9% the same. We are much more similar than different. A lot of the time we don’t realise this because it’s much easier to notice the differences. Being similar means that anything someone else has learned, you can learn too…if you put in the effort.

Know you are going to Fail

When you start something new, you will fail the first time. Maybe the second or third time too. I think everyone innately understands this. Unfortunately, many people try to avoid this. When starting something, they will spend a long time trying to decide the best way to do it in an attempt to avoid failing. This leads to people giving up before they have even started or overthinking.

For example, when I decided to learn salsa dancing last year, I signed up for a course which was quite expensive and wasn’t teaching me what I wanted to learn. I spent a lot of time and money on it and didn’t receive as much value from it as I should have. Later I found different classes that were much cheaper and more valuable to me so I switched. Signing up for those first classes was a failure in that I wasn’t getting good value for my money but it was much better to do that than take time hemming and hawing about which direction to go.

Another reason people learn slowly is ego. As we grow older, many people don’t want to be seen as beginners. It’s a good thing we didn’t know this when we were babies. There may be a lot of people who never learned to walk or talk if we did. Can you imagine a baby not enjoying the process of learning to crawl or walk?

Knowing you are going to fail at something the first few times means you should jump right in. There is no avoiding it. Get those failures out of the way quickly so you can move on to the learning stage.

Rest and take Breaks

Rest is completely undervalued in our culture. I like not being busy and having lots of leisure time. Many people don’t seem to be like this. They “brag” about how much they work or how little sleep they get. There is a limit to how much a person can do or learn in a set period of time. Once you reach that limit, you will not be able to do any more until you rest and re-charge your batteries.

I have forced myself to go to dance classes when I was really tired and they have been a waste of time. I wasn’t able to retain anything I learned. Contrast that to classes where I had a nap beforehand and the difference is incredible. I was able to retain a lot more of what I learned and I had a lot more FUN! You should be taking breaks after 45 minutes of learning to let your mind absorb and process the new information.

Understand the learning curve

The best book I have read on learning is “Mastery” by George Leonard. One of the many great insights in the book, that is obvious when you think about it, is that we don’t learn linearly.

Linear Line

Not how we learn

Instead, we learn in a series of rises and falls.

Plateau Lines

Two steps forward, one step back

We take two steps forward, one step back and then be stuck at a plateau. This plateau could be anywhere from a few minutes to several years. Many people quit when they are in one of these plateaus. It’s easy for us to get frustrated and think we have stopped learning. Instead, enjoy the plateau! It is your mind’s way of saying “Ok, you have learned enough for now. I need to process all this new information and master it before we can move on.” The plateau is a necessary part of the learning process. It allows you to retain what you have learned.

A great thing to know about the learning curve is how fast you can advance. After just 6 months of practice, you will be better at that skill than 90% of the population. It doesn’t matter if you are a complete beginner. No matter what you take on today, you will be better than almost everyone in only six months if you practice regularly.

After that, the curve really steepens. It takes another 10 years to get into the top 1%. Understanding this scale lets you be aware of how much effort you want to put in. Maybe the top 10% is good enough for you. I am in Toastmasters but have no aspirations to become a professional public speaker. Because of this, I don’t feel bad if I am not putting in as much effort into that as in other areas. Some other things, like dancing or programming, I do want to be in the top 1% and so I need to practice regularly for a longer period of time to achieve that.

Everyone has the ability to learn. If you haven’t used the learning portion of your brain for a while it may take longer to re-activate it. You can learn quickly and you can learn whatever interests you.

Enjoy the learning process. Be like a child. Jump into things. Have fun!

Did you find this article valuable?

High Performance the Lazy Way

May 24th, 2010

This is my 5th Toastmasters speech. Re-watching it now, I was quite disappointed with it. I wasn’t prepared enough and it did not come off as smooth as it could have been. I also need to work on my vocal variety more. Luckily, that is the purpose of my next speech. Please evaluate this speech at Soapbox Guru.

Thank you Mr. Toastmaster, fellow Toastmasters and welcome guests.

Now I hate to start off by bragging about myself but I am lazy. And people come up to me and they say Matt “How can you be so lazy?” and they tell me all sorts of excuses. They say “I want to be lazy but I don’t have the time.” Or “I want to be lazy but, you know, being lazy sounds like a lot of hard work.” And, of course, “I want to be lazy but I just don’t know where to get started.”

Now, I’ve found that there are a number of benefits to being lazy. And I’m going to cover three of them today to help you become lazier in your own lives. First one is that being lazy can help you save money.

Now, I’ve been wanting to buy a new computer for about a year or so because the computer that I have, it’s a bit loud and it overheats and shuts down sometimes so I think “Ah, I should go out and I should buy a new computer for me.” But then I start thinking about all the effort and time that it requires to go out and buy a new computer. I gotta go to all these different stores and do research and pick out the one that suits me best. So I keep putting it off. Buying a new computer – it just takes too much time and energy for a lazy person like me. So I’ve realised that being lazy can help you save money.

Are you one of those people that buys 10 pairs of shoes or shirts and never wear them again? You can put laziness to help you. So the next time you want to buy something you might see at the store, instead of buying it there, go home and think about it for a week. A week later, you’ll think “Maybe I want to buy that shirt” but then you start thinking in your head “Well I gotta get in the car, I gotta go to the store, I gotta pick it out again and find where it is. Ah, it’s just too much work. I’ll be lazy. I’ll save money.”

So that’s the first benefit. Be lazy, save money.

The second thing I’ve found is that being lazy can help you be more efficient. So my philosophy is “Why do something twice when you can only do it once?” In software development, a good practice is called DRY – D R Y – Don’t Repeat Yourself. And I try to incorporate this into my work because I don’t like repeating myself. For example, a few months ago, I was working on a website that needed user registration. And I forgot to put a part where users can, if they forget their password, they can get it sent to them by email again. One day, the guy comes up to me and says “Oh Matt, this guy forgot his password. Can you reset it for him?” I think “Ah, this is petty work. I don’t want to do this work.” So instead of resetting this individual password, I just write code that allows user to reset their own password. And I don’t need to be bothered by this petty work anymore. So be lazy, be more efficient in your own life.

The third great part about being lazy is it can help you kick bad habits. There’s a famous psychologist named Milton Erickson who was known for solving patients problems using very creative techniques. One day a patient came to him and said “Doctor, I’m an alcoholic. I’ve tried everything to stop but I still keep drinking. It’s ruining my life and my family’s life. What can I do?”

And Dr. Erickson thought about it for a minute and said “Alright, drink as much as you want.”

And the guy’s thinking “What? You’re telling me to just keep drinking?”

And he says “Yes. Drink as much as you want but it has to be at this one pub three miles from your house. And you have to walk there if you want to drink.”

So the guy thinks “This is peculiar but I’ll give it a try.”

The doctor says “OK, try it out for one month and come back and see me.”

One month later, the patient comes back and says “Doctor, I don’t know what you did but I’m cured of alcoholism. I haven’t had a drink in three weeks.”

And the doctor asks him to explain and he says “Well, you know, I walked to the tavern the first couple nights and then the third night it was raining so I thought, ‘Ah I’m not gonna go out in the rain to drink’. Then the fourth night I start walking there and about half an hour into my walk I start thinking ‘You know, it’s gonna be another half an hour to get there. I’m a little bit tired. I don’t know really want to go the next mile and a half to get a drink’ so I just turned around and went home and spent time with my family. And the next night ‘Ah it didn’t really interest me anymore’ so I just stopped going to the pub. So this is another benefit of being lazy. Being lazy can help you kick bad habits.

See, I think I’m lazy but laziness is a general trait among people. People try to do things the easiest way and if you make things that you don’t want to do harder you will usually take the easy way out and you will take the lazy way out which if you structure life can actually improve things. For example, if you don’t like going to the doctor, if you absolutely hate it, then eat healthy and take good care of yourself. Then you won’t have to waste your time going to the doctor. Same thing if you don’t like cleaning, then don’t make a mess and it solves itself.

So be lazy in your own life. It can help you save money, make you more efficient in your job and can help you kick bad habits. Mr. Toastmaster.

Did you find this article valuable?

Increase Your Productivity. Work in 45 minute blocks.

May 3rd, 2010

Over the years, I have settled on a system that best allows me to focus and be productive.

Work 45 minutes. 10 minute break.
Work 45 minutes. 10 minute break.
Work 45 minutes. Longer break.
Repeat as necessary.

How did I come about this system?

Mostly by trial and error and observing my energy. I would notice that it would take me about 45 minutes of working on something to come up with a solution. For example, if I was working on a bug fix, from the moment I started to the moment I finished would be 45 minutes. I would feel good about accomplishing my task and would take a break to relish in the accomplishment and prepare for what I needed to do next.

After doing this system for a while I came across a study that found people can only focus on one thing for about 45 minutes. After 45 minutes, your mind starts to wander and you have a tough time remaining focused. A break helps re-energize your focus.
(Unfortunately I do not recall where I read this. If I come across it again in the future, I will edit this post)

What about longer tasks?

Longer tasks are just broken down into smaller pieces. No matter how large the project is I break it down into something that can be accomplished in about 45 minutes. In fact, you need to do this otherwise the project would just seem overwhelming.

Sometimes I do want to keep working but I usually feel worse if I do. My muscles will start to ache from sitting so long. You need breaks. Standing up and walking around helps improve your circulation causing better blood flow to your brain.

During the breaks, I will usually use the time to think about what I want to do next. I try to turn this break time into planning/thinking time. Too often as programmers, we just want to do, do, do. It is important to spend some time each day thinking about and planning your work otherwise you may end up spending time working on something that is not important.

To make sure I take breaks, I use SlimTimer to time my work. I start by simply clicking on the task and when 45 minutes are up, I take a break. Sometimes I will go to 50 minutes if I just need a few more minutes or stop at 40 if I have accomplished my task already but it usually averages out around 45.

It is important to remain as focused as possible for the 45 minutes otherwise this system does not work. You must resist any temptations that may pull you away from your task. Stay focused on one thing. Turn off email notifications and IM and close your browser.

Give this a try for your own work. Use a timer but only time the periods you are focused and productive. When you notice your focus is slipping or you need to take a break, stop the timer and observe how long you remained productive for. Keep recording this information for a week or two and you will start noticing patterns about how you work.

Edit: Here is one reference I have come across from “How to Stop Worrying and Start Living” by Dale Carnegie (unfortunately no reference is given for this passage):

“Why is [rest] so important? Because fatigue accumulates with astonishing rapidity. The United States Army has discovered by repeated tests that even young men – men toughened by years of Army training – can march better, and hold up longer, if they throw down their packs and rest ten minutes out of every hour.”

SlimTimer

Did you find this article valuable?

Never Compromise Quality

April 27th, 2010

In programming people sometimes feel they have to sacrifice quality in order to get a product out the door on time. Never do this. You are hurting the customer, the company and yourself if you do.

This American Life had a very interesting program on the New United Motor Manufacturing Inc (NUMMI) plant in Freemont, California. NUMMI was a joint venture started in 1984 between Toyota and GM for both parties to learn from each other. GM would learn about Toyota’s quality control systems and Toyota would learn about building cars in America.

The amazing story is the turnaround of the plant. Prior to the joint venture, the plant was operated by GM and was one of their worst factories. The program talks about workers gambling, having sex, and drinking at work. They produced very low quality cars and didn’t really care. The plant was closed as a result. However, for this joint venture, GM agreed to re-open the plant and hired back many of the original workers. Thanks to Toyota’s quality systems, the plant turned around to become one of the best GM had.

One example of change was “stopping the line.” The GM workers grew up with the notion that you don’t stop the line. If you notice something is wrong, you just keep it going. Just get the cars out the door. With Toyota’s system, workers were encouraged to stop the line if they noticed something wrong and fix it on the spot. This was a big shift for them. The process became about quality over quantity. Within just three months, cars coming off the lot were being made with near perfect quality.

When you let an error slip, either with cars or with software, you are compounding the problem. It takes much more time and money to fix the problem later than when it is first discovered.

How much more money? One study estimated “it would take 50% more workers under the old system to produce the same car.”

Recently I had a situation like this. I was responsible for checking over and delivering database scripts to a client. I noticed one of the scripts had an input parameter and while I got a feeling I should double-check about it, I ignored that intuition and delivered them anyways. The client ended up running the scripts in their environment but ignored the input parameter which caused part of the scripts to fail. There was a lot of back and forth to get it fixed. I estimate it probably wasted about one man-days worth of everybody’s time. Because I didn’t take 5 minutes to check about something that could be wrong, I ended up costing hours worth of time.

It’s not mentioned explicitly but it is implied that the vices went away after the quality program was introduced. While workers were embarrassed to be working at the plant before, they now were proud to tell friends where they worked.

In ancient times, brick makers, engravers, and other artisans used a symbol to mark the things they created to show that they were the makers. The symbol that each one used was his “character.” The value of the work was in proportion to the skill with which the object was made. And only if the quality of the work was high was the character esteemed. In other words, the quality of the person and his work gave value to his credentials. If the work was good, so was the character. If it was bad, then the character was viewed as poor.
- “Becoming a Person of Influence” by John C. Maxwell & Jim Dornan

This is why the morale and esteem of the workers improved once quality became the focus. Your character is revealed in the work you do and vice versa. If you are producing shoddy work, your character is being revealed as such.

In programming, quality does not mean taking a stand over something trivial such as whether to use tabs or spaces for indentation. Quality means being consistent in your work. It means following design principles that will save time and effort down the road. It means doing things right the first time so you don’t need to correct them later.

Always do things in a quality manner. Never compromise. For if you do, you are compromising your character.

This American Life episode about NUMMI
Becoming a Person of Influence

Did you find this article valuable?

How to easily create Models and Table Relationships in Zend Framework

April 24th, 2010

When I first started using Zend Framework, I was so frustrated when trying to figure out how to get information from the database. I fought against the framework for the longest time. Instead of working with it, I would write the SQL and then simply query the database to get the data back as an array of objects.

Later on I learned at just how powerful Zend Framework can be when it comes to retrieving models. It is actually easier and more fun to do things in the “Zend” way.

This is the post I wish I had read before spending hours going about things the wrong way.

I’m using Zend Framework for a project which has videos, users (each user can have many videos) and tags (many tags to many videos). This example will show you how to setup your models correctly:

/application/models/DbTable/Videos.php

class Model_DbTable_Videos extends Zend_Db_Table_Abstract
{
	protected $_name = 'videos';	// database table name
	protected $_rowClass = 'Model_Row_Video';	// row class for extending
	protected $_dependentTables = array('Model_DbTable_VideoTag');	// videos depends on the many-to-many join table for tags

	protected $_referenceMap = array(
		'User' => array(
			'columns' => 'user_id',	// the column in the 'videos' table which is used for the join
			'refTableClass' => 'users',	// the users table name
			'refColumns' => 'id'	// the primary key of the users table
		)
	);
}

/application/models/DbTable/User.php

class Model_DbTable_Users extends Zend_Db_Table_Abstract
{
	protected $_name = 'users';
	protected $_rowClass = 'Model_Row_User';
	protected $_dependentTables = array('Model_DbTable_Videos');
}

/application/models/DbTable/Tags.php

class Model_DbTable_Tags extends Zend_Db_Table_Abstract
{
    protected $_name = 'tags';
    protected $_rowsetClass = 'Model_Rowset_Tags';
}

/application/models/DbTable/VideoTag.php (the join table for many-to-many relationship)

class Model_DbTable_VideoTag extends Zend_Db_Table_Abstract
{
    protected $_name = 'video_tag';
    protected $_referenceMap = array(
		'Video' => array(
			'columns' => 'video_id',
			'refTableClass' => 'Model_DbTable_Videos',
			'refColumns' => 'id'
   		),
   		'Tag' => array(
   			'columns' => 'tag_id',
   			'refTableClass' => 'Model_DbTable_Tags',
   			'refColumns' => 'id'
   		)
	);
}

The protected fields allow you to tell the framework the setup of the tables. You can also extend the Row on Rowset by simply setting the $_rowClass or $_rowsetClass field.

In Model_DbTable_Videos, you see I have specified the $_rowClass field. This means any row returned will be an object of Model_Row_Video. In the class Model_Row_Video, I have added extra methods for easily retrieving the user of the video and tags belonging to that video:

/application/models/Row/Video.php

class Model_Row_Video extends Zend_Db_Table_Row_Abstract
{
	private $tags = null;
	private $user = null;

	/**
	 * @return Model_Row_User
	 */
	public function getUser()
	{
		if (!$this->user) {
			$this->user = $this->findParentRow('Model_DbTable_Users');
		}

		return $this->user;
	}

	/**
	 * @return Model_Rowset_Tags
	 */
	public function getTags()
	{
		if (!$this->tags) {
			$this->tags = $this->findManyToManyRowset(
				'Model_DbTable_Tags',	// match table
				'Model_DbTable_VideoTag');	// join table
		}

		return $this->tags;
	}
}

Because I have all the relationships setup, I simply need to call findParentRow() or findManyToManyRowset() to get the Row or Rowset of a related record.

Here is an example for the Rowset:

/application/models/Rowset/Tags.php

class Model_Rowset_Tags extends Zend_Db_Table_Rowset_Abstract
{
	/**
	 * @return array the tags in an array
	 */
	public function getAsArray()
	{
		$tags = array();

		while ($this->valid()) {
			$tag = $this->current();
			$tags[] = $tag->name;  // the actual tag name
			$this->next();
		}

		$this->rewind();

		return $tags;
	}
}

So to get the tags of the video with ID 23 all I need to do now is simply:

$tblVideo = new Model_DbTable_Videos();
$video = $tblVideo->find(23)->current();  // returns Model_Row_Video
$tagsArr = $video->getTags()->getAsArray();

Working with Zend Framework becomes very easy and pleasurable once you follow their setup.

Refer to the Zend_Db section of the manual for more information about working with the database.

Did you find this article valuable?