Category: General

My feelings on testing

Posted by on November 15, 2009

 

At one of the recent WAN Parties, there was some discussion on testing. Some items came up that really got me thinking about why the last 2 years has sold me on testing. From memory, I’m going to go over my thoughts on some of the comments.

It’s hard to write tests first. How did you learn?

Well, I didn’t have a choice. I learned TDD by taking a job as a junior looking for some mentorship. My first two projects were:

  1. Get every old app we supported (~ 24) into a build script and onto our CI server
  2. Write a small make work app, but do it completely via TDD.

Me and my coworkers had done some pairing and I had written some tests with people, but I always had someone to lean on so it was kind of easy.

However, once I started out on my own, building a system from the ground up and having no idea where I wanted the design to go? That’s when things got difficult. I remember spending literally an entire afternoon writing a single test. One. I don’t even know if I finished. I just remember knowing Point A and Point B and having no idea which path to take between the two.

Of course, as my boss would come and check in on me he would say "That’s good… but why can’t it look like this"? He’d sit down and write a few lines and suddenly I’d feel like a total moron.

The point of the story is: It takes work. It takes writing tests and realizing their crap and continuing on writing more. Don’t expect your first foray into true TDD to be easy, and don’t expect to do it well. However, I can guarantee you that if you stick with it, it _will_ become second nature.

Also, if you can get one, find yourself a mentor to help you. It will help immensely.

How do I know what I should be testing?

I’m inclined to say "Pretty much everything". I’m not a coverage nazi, though we do have some guidelines and goals around it in our shop. However, there’s just code that it doesn’t make sense to test. Like a value object made up entirely of autoprops. I’m pretty sure I know how that thing’s going to work.

Don’t tests force your design?

It seems like many people feel that because everyone has their brilliant idea of what the design of the system is going to be, that they will write tests that will suit their perceived design. For me this is true, but the true power of it is that it shows you ahead of time where your design has flaws.

Yes, I usually have a path that I think I’m going to take when I start writing a test. However, often times before I’m done a set of tests for a feature, I end up changing my mind. The thing about writing the tests first is that it shows you where your design has flaws and where it’s going to cause you pain. If it’s painful for me to write a test then it’s probably going to be a pain in the ass to write and maintain. Pain in writing tests usually signals that you’re trying to do too much at once, often you’re trying to break SRP.

In the end, you’re not only testing your code. You’re also testing your design.

I hear all this propaganda over and over, but how do you know?

For me, I have two projects that I currently work on. One with tests and one without. The one without tests was started before I learned about TDD (though I’m currently trying to begin adding tests, it’s very difficult to retrofit). As well, the one without TDD uses ruby. I heard someone say at the WAN Party the other night that Static Languages and their compilers are just a set of implicit tests. After using a dynamic language I can totally agree.

Anyway, I always find myself trying to find excuses to do something else than my non-TDD project. Why? Because I’m scared to do anything with it. Since I have no tests, I have spent (literally) countless hours fixing bugs only to have them come back into play the next time I fix another bug. I have no way of telling whether what I’m fixing is breaking something else that depends on it. Personally, I think that had I just bitten the bullet a year ago and started putting the tests ever just around the bugs I was currently fixing that I would be well ahead of where I am today on that project.

I’m starting to notice a trend here….

I agree. The funny part I’ve always thought about testing is that as someone learning it, you don’t really see the benefits. In fact, in most cases, the benefits don’t ever fully show themselves until you’ve been working on a project for a long time, or even better, need to come back to it.

Maybe you’re at the opposite end of the spectrum. You’re not skeptical of the claims, you’re curious. Maybe you’re curious like I was 2 years ago because making any changes to an old project is like pulling teeth. Or maybe your current project has hit a standstill because bugs keep creeping in and every change introduces two new ones.

My Story (in a nutshell)

I graduated from University in 2004. I had been working for an Oil and Gas company doing some development part time during the 3 years prior. After graduating I took my first job as a software developer in a small (2 developers, about 6 hardware/network/whatever guys, plus admin staff) company. I was taught to develop in ways I always somewhat questioned. After a while I started to read up on things. The only article that still stands out in my mind that I read was Martin Fowler’s article on Dependency Injection. I know I read some on the Open Closed Principle. And none of it made sense to me. I had too many stumbling blocks in my way:

  • I didn’t learn anything in my Computer Science Degree except algorithms and some cool hardware stuff
  • My current ‘mentor’ didn’t understand these things either
  • I knew I had problems, but I couldn’t even define them even though I was reading about the solutions to my problems

Then I got lucky. I went looking for jobs because I knew there was a better way and I told everyone I interviewed with that. Then I was finally told at one interview that they knew exactly what I was feeling because they had just gone through that pain. They also told me that they had the answers I was looking for.

I took that job and it was the best thing I ever did.

It gave me the things I needed:

  • People who understood where I was coming from
  • A requirement to learn every day
  • Mentorship

I truly believe that the easiest and best way to learn is to have someone with you guiding you in the right direction while also forcing you to go out on your own. I can understand people skepticism, I once had it. But then I got sick of fixing the same thing over and over. I realize that this is getting long so I’ll just end with another personal note: If I hadn’t taken that job and learned what I have over the last two years, I would no longer be in software.

The short story is, Testing saved my career.

It’s not supposed to be inflammatory or controversial

Posted by on November 19, 2008

 

I tend to be an opinionated individual. As such, when I present (or defend) my opinions, I tend to go out of my way to push my opinion as the correct one. I may go as far as to insinuate that others are wrong. This tends to get mixed feelings from a lot of people. Some people just think I’m asserting myself. Others think I’m a know it all. Others just think I’m a plain jerk. There maybe some truth in all three.

Sometimes it just ends up that things work one way for me, and another way for someone else (See my last post). There’s nothing I can do when it comes to that. People are different. Just because something is wrong for me, doesn’t mean it’s wrong for everyone.

I do however, realize that sometimes I’m wrong. Consider this my open invitation to all you (nonexistent) readers out there. If you think I’m wrong, incorrect or just plain out to lunch. Please call me out. Don’t just tell me I’m wrong though. If you can’t back yourself up, then don’t bother. Tell me why I’m wrong. Make me defend myself, or it’s just not worth it.

If there’s one thing I’ve found in my time on the internet, it’s that if you assert yourself enough and just act like you’re right, people will listen to you. Most people don’t have the will to stand up to someone who thinks they’re right.

I hope you do.

If programmers are typists first, then I’d better get a Typing Tutor

Posted by on November 18, 2008

 

This afternoon I found that Jeff Atwood has once again made another post that left me shaking my head. Kind of like a car wreck, I just couldn’t look away. This evening, Jimmy Bogard posted a response. I have to say that I agree with Jimmy wholeheartedly.

The only exception to this rule as I see it is that you can’t be a hunt and peck typist. I don’t care how much code you write, if you have to watch your hands fingers while you’re writing code, you probably could benefit from a round or two of QWERTY Warriors. I’ve worked with hunt and peck typists and it can be infuriating to pair program with them, but I’m admittedly brash and impatient. It’s something that I’ve actually been working on.

Anyhow, I’m a C# coder. C# isn’t exactly known for it’s brevity, and neither are some of my class and method names. However, we developers are a crafty bunch. If there’s a way for us to do things quicker, better or faster, you can rest assured that someone has attempted to solve the problem with some sort of little app or program. Tools like Intellisense, Keyboard Shortcuts and especially ReSharper are all ways to help us reduce the time and number of keystrokes required to do things. In fact, I’d say that 90% of the code I write, I don’t even type entire words. I write I type u-s-ctrl-space and I have userService. I don’t care if you type 84 wpm or 20 wpm: 4 keystrokes is always faster to type than 11.

Also, I don’t see too many typing tests that emulate  string Username { get { return username; } } or for (int i = 0; i < 10; i++) very well. But even that is nearly a moot point. A tool like ReSharper can add a read only property in just a few keystrokes, and with its live templates the for loop almost writes itself. Coding and the associated thinking and planning involved aside, we should be the users of tools first and typists a distant second.

Basically, what I’m saying is that if you’re a C# coder (isn’t StackOverflow written in C#?) and you are writing code in a manner that requires you to be a typist first and a programmer second, you’re doing it wrong. You’re either writing some pretty crazy legacy code (who here hasn’t written a function with a couple hundred lines in it?) or you’re the victim of a problem that’s already been solved.

History has already shown that Jeff is quite happy being a victim.

The Obligatory Developer Rig Post

Posted by on November 15, 2008

 

Seems like everyone has done one of these posts. I’ve spent the better part of the last week rebuilding my workstation and my test/backup workstation. We had a power surge and my aging test/backup station just wouldn’t start up anymore. So I decided to get a new workstation and bump my current one down the line.

Because of circumstances, I decided I was going to put it together myself. So Friday night after work I went down and picked up everything. Just like Jeff Atwood, I like my workstations to be powerful, but quiet, and a quiet PC starts with the case.

Previously, I’ve been a HUGE fan of the Antec Sonata. I own 3 different Sonata cases of both the Sonata I and Sonata II variety.  My main requirement was that the fans in the case were 12cm with a decent airflow. I’m also not a fan of the flashy cases with lights and windows and the like. Eventually, I decided on the Antec P182. Here it is just barely unboxed.

IMG_0848_cropped

And the inside:

IMG_0851_cropped

You can’t really see it here, but on the other side of the case is about a half inch of space to run all of your cables so you don’t have to put them in the middle of the case and block airflow.

As for the components, I was actually quite surprised with how small of a box they all fit in.

IMG_0846

For the motherboard, I chose the EVGA 780i motherboard. I guess the biggest draw for me was the 6 SATA ports and dual gigabit networking. Honestly, after years of using AMD processors, I found almost all of the Intel motherboards to be vastly overpriced. It may have made a difference that I won’t buy any motherboard that is not an NVidia chipset.

For my processor, I chose the Intel Core 2 Q6600 Quad Core processor. Compared to other processors it seems to have one of the best price to performance ratios out there.

IMG_0868

As stated earlier, I prefer my PCs to be as quiet as possible. This stems from back in my university days when I used to have 2 PCs in my room with me.  This is no longer the case, but the need for quiet PCs has stuck with me. My first preference for CPU heatsink was the Scythe Ninja 2. I had one for a previous computer and loved how quiet it was, coupled with the excellent cooling  it provided.

However, the store near my house happened to be all out of them at the time I went to pick it up, and I didn’t want to have to go across the city to get one, so after reading some reviews I ended up choosing the Thermalright Ultra-120 eXtreme. It doesn’t come with a fan, but I have a few 12cm fans kicking around the house, so I wasn’t too worried. However, after getting things all set up, I ended up not even putting a fan on. That’s right. I now have passive cpu cooling, and I couldn’t be happier.

IMG_0860

Considering the catastrophic hardware failure I suffered to put me in this predicament, I’ve decided to begin doing some virtualization. As such, I decided that I needed RAM. Lots of RAM. In fact, I decided to get 8GB of Corsair XMS2 DHX ram.

IMG_0869

And since I’m going to be virtualizing, I wanted to get as much performance out of my drives as possible. I’m also really weird about losing ANY data that I have. So I decided I wanted a RAID 0 for performance, and a RAID 1 for redundancy. So I got 4 Seagate 7200.11 500 GB hard drives, and put them in a RAID 0+1 configuration.

IMG_0871

Finally, since I’ve recently been playing games a bit more often, I decided to splurge and get a video card beyond what I really need. I settled on the EVGA GTX 260 Core 216 Superclocked Edition. I kind of think that to go along with my brother’s thoughts that the longer your Starbucks order is, the bigger a jerk you are, the longer your video card name is, the bigger geek you are. So I guess I’m a pretty big one.

IMG_0874

And to tie it all together, the power supply. I ended up choosing the OCZ GameXStream 700W power supply. I decided that with all the stuff I had in there, I was going to need a fairly large power supply, so I chose this one. Added bonus: its fan is a 12cm fan. Yes, I’m that picky about my cooling.

IMG_0853

Here is the motherboard with the CPU, Heatsink and RAM mounted:

IMG_0870

And finally, here is the entire computer put together:

IMG_0876

As you can see, the cables are run behind the back wall of the case. Here is a better view, my socks included:

IMG_0875

I spent a lot of time trying to make the cabling as good as possible. I’m a notoriously bad cabler, so I was actually quite impressed with the job that I did here. I just know someone who does this for a living is cringing as I say that too.

In the end since I had so much memory, I ended up putting on Vista Ultimate 64bit. So far it has been blazingly fast and stable. I’ve ultimately been very impressed with it. I haven’t yet had any time to write any code on this new machine, but I’m greatly looking forward to it. I’ll let you know how it goes.

Also, I would like to say that if you live in Calgary, Edmonton or Winnipeg and you have any hardware needs, use Memory Express. I’ve been using them almost exclusively since around 2000 and am always impressed. I’ve only had one bad experience when someone was too busy showing a co-worker pictures of girls on facebook to really pay attention to the fact that he was helping me. Once in 8 years, and it wasn’t even that bad. On the other hand, every time I try another store, I wonder why I did it. Take that as you will.

Anyway, if you are a computer person and you’ve never put together your own computer, I greatly recommend you try.