TDD Test Driven Development for Beginners pt1

by percent20 29. November 2007 13:27

Part 1: TDD Test Driven Development for Beginners pt1
Part 2: TDD for Beginners pt2 - Pig Latin
Part 3: TDD for Beginners pt3 - The Application
Part 4: TDD for Beginners pt4 - Unit Tests

You know I might not be the most qualified person to talk about TDD. I may not be the best developer in the world with TDD, but I struggled with it for a long time and I want to help others get through the “Basics” with less pain than I went through learning TDD.

First Let's talk a bit about TDD. We are going to hit the basic questions.

Who: Who can do Test Driven Development?

- Anyone. Everyone who programs can do test driven development since it is a type of development. A way to do development.

What: What is Test Driven Development?

- Good question. Test Driven Development is a type of development where you use your code before you write it. Yeah you read that right. You use your code before you write it. What this basically means is that you write a test for a piece of code before you actually write your code. This may seem odd, but once you get the hang of it TDD is quite powerful.

When: When do you use Test Driven Development?

- All the time. Again TDD is a way to develop software so it can be done anywhere on anything for the most part.

Where: Where do you use Test Driven Development?

- Everywhere. If you write code somewhere you can use TDD to help write it.

Why: Why would you use Test Driven Development?

- Ah, the 100 million dollar question. Why would you possibly want to do this. Well the answer is simple. Eventually you are going to need to use your code. At some point your code is going to be implemented and you want to make sure it works. So the best solution is to put forth a little for-thought and pre-implement your code. That way when you write your code you know when it is working.

How: How do you use Test Driven Development?

- Well we will get to that in the next few parts as this is a multi-part series.

Now these are some vague descriptions and answers. I did that on purpose for one key reason to make you think for a few minutes.

Let me just run you through some of my experience with Test Driven Development. At first it was plain hard to figure out what in the world was going on. It didn’t make any sense of why or how you can implement code you haven’t written yet or why you would. It still kind of boggles my mind. However, as I have used TDD more and more I have grown to like it A LOT. In some respects it is like a video game while using NUnit you write a test write enough code to get a compilation run the test hey it fails and is red. Now you plug away at that one piece of code until it is green.

I think the absolute greatest thing about TDD since I have started it and is why I am loving it is because I can completely restructure my code and as long as ever test passes I know my code is good. Also if I do break something I know where it is broken and where to begin to look. Think about it for a second. If you have say 10,000 lines of code and 90% of it has tests and you have to do some major refactoring or redesign you will know what breaks and where immediately instead of having to try and run the program to figure that out.

I just want to make one last point. I am still learning TDD and am still a junior developer. However, I have a passion for coding and passion to help other people not fall victim to learning stuff the hard way and the long way like I had for TDD.

I also suggest reading a post I made before I decided to do this series TDD (Test Driven Development) for beginners and More on TDD "so much code"

Stay tuned for part 2.

Note: as part of full disclosure this is not a new post.  I just changed the date as I started this series then stopped blogging for a while and am wanting to get back to this.  I just feel people should see this before I go into part 2. Just trying to stay honest.

kick it on DotNetKicks.com

Currently rated 3.3 by 4 people

  • Currently 3.25/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Real World Interfaces in C#

by percent20 26. November 2007 10:20

I have been on a bit of a "quest" lately to learn interfaces better. While at work I hit up a couple of fellow developers on "why" you should use interfaces in the real world. Believe it or not after going through some code and getting some commentary on it I think I have an understanding of interfaces.  Here is my understanding in a possible "real world" situation.

Let’s say you want to render out commonly used objects to the screen.  They can be textbox's, images, or even labels.  Each of these might have a common set of properties like title, id, width,  and height; plus a method like Render() to show it on the screen.  Now in .NET we might call these objects controls so we will use that naming convention for example sake.  You might create an interface called IControl that all controls will inherit from.  One reason to use an interface instead of a separate class is because the render method could be different for all the different controls, but is all that is needed to be called in order to show the control.

So, let’s look at some basic code.  First we will look at the interface.

IControl Interface

This interface IControl has our common properties and the render method. We are going to implement different render methods for each of our different controls so we might not necessarily want to create a control class to inherit from. To illustrate this more let’s look at two different controls implementing the IControl interface

TextBox

TextBox Class Implementing IControl

Label

Label Class Implementing IControl

If you notice both the TextBox and the Label controls have slightly different render methods, but both contain the same properties because of the IControl interface. This is important to note because we KNOW that if the IControl interface is being used that you can always call the methods and properties from them. So that means you can make a method like the following which will always call the render method as long as the object implements the IControl interface no matter what the control is.

OutPut Method that calls IControl Render Method

With this you can create an instance of TextBox and Label and pass both of them to the above method and they will call the render method and output the correct information.

Here is some “example” code on how-to use and put together everything above.

Main Method Implementing Controls

Conclusion

To wrap it up you can make an interface and an interface basically says “hey I have at the very least these properties and methods and you can use them however you need without worrying about what they do to actually use them” Which means that you can write any code you want to implement each of the properties and methods and as long as you use the interface as your “datatype” there is no need to worry about what the code actually does for each and every object that implements the interface. In the case of the example there is no need to worry about how many or what the controls actually do when rendered because they will all be rendered by using the output method since the datatype of the parameter is IControl.

Please, feel free to leave comments and critiques on this. I am still learning about interfaces and this is as “real world” as I could figure out on how to use interfaces as that is what helps learn. Any help would be great and please feel free to download the code I have attached and play with it a bit. I am sorry for the length I just wanted to be thorough, I hope I was.

 

Interfaces.zip (6.33 kb)

kick it on DotNetKicks.com

Currently rated 4.0 by 4 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

Video from My Phone

by percent20 24. November 2007 18:30

Here is a video from my phone it isn't too good, but kinda fun.  I might see about recording stuff and posting it up.

http://www.youtube.com/watch?v=gn3HXbneH6E

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

What and Why of Design Patterns

by percent20 24. November 2007 07:26

While I do like to write over things I know especially with regards to development I still have a lot to learn still.  Lately I have been doing a lot ofl ooking at design patterns as I keep hearing a lot of people talk about using them.  So I wanted to know WHY use design patterns and what are they specifically.  Here are some of the better things I have read over design patterns.

How to Use Design Patterns
Design Patterns
How design patterns can help you in developing unit testing-enabled applications
Patterns-Discussion FAQ
How to Use Design Patterns
Effective Object-Oriented Design with Design Patterns
Design Patterns Isn’t a Golden Hammer
Why aren't design patterns common knowledge?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Just WOW

by percent20 23. November 2007 17:30

I don't normally post stuff like this, but after watching this video all I have to say is WOW.  Be sure to watch the WHOLE thing it gets better the longer it goes. 

H/T Mac Tyler

http://youtube.com/watch?v=lLYD_-A_X5E

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Ideas on Code Comments

by percent20 22. November 2007 07:30

I have been doing reading lately on documentation and more specifically code comments.  Here are three that you might find interesting.  I'll post more as I find them or they are shown to me.

Are your code Comments a way to say I'm Sorry for the actual Code
1 Common Mistake Involving Code Commenting
Programming *is* much more than "just writing code".

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Simplicty of Nutrition

by percent20 21. November 2007 07:28

I am about to get back to serious weight lifting, and to do that requires some good nutrition to be effective. I needed a refresher on what I knew so I dug up an old thing I wrote about nutrition for some extra motivation and decied to post it and read it.  Sorry for the long read, but it is informative. 

The biggest thing that people need is a proper amount of calories a day. The way to figure this out is to use their calculator based on your BodyFat % and your current wieght and age and activity level. This will give you the amount of calories per day that you need to eat to maintain current wait with your lifestyle. I'll run through tings based on a 2500 calorie a day diet.

Ok, this does not mean that you can eat what ever you want all the way up to 2500 calories. While technically this can work you will have a lot of side effects for yourself that can really screw your body up. So no 2500 calories a day of cake and ice cream. Now what do you need 2500 calores a day of well 3 things. Protien, Fats and Carbs.

Now you may be saying oh no fats are bad for you no no no you lie. Well that is completely wrong. There are 2 basic types of fats Saturated Fats and Unsaturated fats. Your saturated fats are what is solid at room tempurature. Your unsaturated fats are liqued at room tempurature. Well your body NEEDS unsaturated fats. Now this is easy to obtain through fishes and gel caps. Just when you get that steak trim off that saturated fat cuz it is bad.

Also you need protien this is the good stuff this is what heals your body. Basically, when you are sore from a workout or you cut yourself your body goes to the protien for the amino acids to promote healing because when you work out what you have done is created tons of micro tears in your muscle and the protien stimulates muscle growth.

You also need Carbs. Carbs are great they can burn body fat at a higher rate than than anything else if used effectivly with some caffiene. :D Carbs are what your body burns through and when you get the right amount your body will hurry and burn through that really really fast it speeds up the metabolism. That is why you can easily get hungry after eating just rice.

Now, lets put all this together as one to see how it works. When you eat effective portions of all 3, which I will explain next. You can literally turn your body into a fat burning machine and be able to burn nothing but body fat, but it takes precision and patience. Basically you need about 6ish meals a day that vary in size. The reason you eat so many is once you eat your body's metabolism is no high speed and peaks after about 2 1/2 hours then if you eat around then it keeps it at that high rate of speed. So by eating about every 2 1/2 hours to 3 hours you will maximize the amount of food burning time.

Now for the first month you will not lose any weight in fact you may gain a pound or two no worries. What is happening is your body is slowly speeding up the metaoblism and getting used to the food consumption. After about a month your body is now used to the food and you will drop your calories from maitenance level of 2500 to 2000 calories. This will allow you to lose nothing but fat with out any extra effort physically a week.

Now I will go a bit into the math of loseing weight because in a sense all weight maitenance, losing, or gaining is basic math.

A few things to know is that in order to burn a pound of fat you need to burn 3500 claories a week, or 500 calories a day. That is for 1 pound of body fat. That should be done with nutrition I do not suggest ever going below 500 calores below maitenance level a day. The rest should be burned with cardio workout, running what ever. Not weight lifting though that is something completely seperate don't even count that.

Now how do you figure out how many protien fats and carbs you need a day well that is easy. You know that you need lets say 2000 calories a day so we just do some simple conversions.

1 gram of protien = 4 calories
1 gram of carbs = 4 calories
1 gram of fats = 9 calories

the suggested scheme to follow is 40 40 20. 40% protien 40% carbs 20% fats.

Now 40% of 2000 is 800. So you need 800 calories or 800/4 = 200 grams of protien and 200 grams of carbs.
20% of 200 is 400. So you need 200 calories or 200/9 = 22.2 grams of UNSATURATED fats a day. Now that may seem like a lot and when you eat clean foods it is a lot of food, but look at it this way eat clean food to equal these stats and you will be eating a lot. Now what do I mean by clean food. Well stuff like grilled chicken breast eggs broccolli fruits vegetabals tuna things like that fish. There is a food database at bodybuilding.com that gives the proportion sizes and stuff like that to create a perfectly balanced diet.

Also when I refer to carbs I don't mean sugar, potato's, fires anything starch that almost imediatly turns to fat well really fast anyway. What I am refering to is stuff like grits, oatmeal, or brown rice (no white rice) You can also have wheat bread but not too much and be sure to get bread that does not have fructose in it.

The fats you need mostly come from fish the quickest way to get it is to have fish oil gel caps or flax seed oil.

Also, the reason I say that weight lifting is completely seperate is because you are trying to gain muscle and while you won't gain a lot you will be burning that fat and converting some to muscle the more muscle you have the more fat you will burn faster. So depending on how you want to do it you could bulk up really big and then do a clean cut to a low body fat range.

Here are some things to be aware of. You have to change how you look at weight loss it can't be oh I need to lose x number of pounds it needs to be I need to lose x number of bodyfat %.

Now some things to keep in mind women and men are made up different so they have to have a certain amount of body fat that is higher than men, but you wouldn't be able to tell.

For guys: body fat percentages
3% = dead
3.5 - 4% = Bodybuilding competition weight
8% = 8 visible abs
9.5 - 10% = 6 visible abs
13% = average male athalete
16% = average male
32% and up = obese

for Women: Not as sure since i don't give much advice to women.
7% = dead
9% - 10% = Competition
14% - 17% = visible abs
20% - 24% = average girl
38% and higher = obese

Thes are all relative but pretty dead accurate.

I hope this helps someone now don't take my word solely for it go read http://bodybuilding.com they also have forums with nutiritionists that can give you pointers and all that.

btw, losing fat is 80% nutrition 15% phyiscal and 5% mental, though that 5% can really cut into it big time when starting.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

I'm Still Alive

by percent20 18. November 2007 05:43

For anyone that has checked my blog for the last several days may have noticed a lack of updates.  Well that is because I got knocked sideways with a cold and couldn't think straight enough to write an effective blog post.  I am happy to say though that things are looking up and I "seem" to be getting better. 

Anyway stay tuned.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Links of the Week (11-13-07)

by percent20 13. November 2007 10:16

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

5 Truths of On Call

by percent20 12. November 2007 13:22

I currently work for a development company doing on call support and let me tell you there are 5 things I have learned that never seem to fail.  While some of them are tiny bit of an exageration ;) sometimes it seems like it happens allllll the time.

Problem Patterns
     Patterns don't really exist because once you find the pattern it immediatly changes before you can fix it.

Sleep
     If you do support at night sleep is what you day-dream about as the problems know EXACTLY when you are about to sleep.

Reboots
     Sometimes just rebooting the machine fixes the problem even when one "does" exist no matter the OS.

Remote Access
    VPN into the office only works on the small issues, you know the 5 minute fixes.  However, as soon as that HUGE 6 hours problem happens suddenly VPN isn't reliable if it even exists.

Life
    You no longer know what a "life" is as you need to be available at a moments notice to fix the problem because as soon you aren't available immediatly you get 5 phone calls from the higher-ups asking why you aren't on it yet.

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

RecentComments

Comment RSS