KevinUp

real world programming

Peer reviews

Posted by kevinup on February 26, 2009

I’ve always been a big fan of peer reviews. I enjoy both giving them and receiving them. However, I find there is generally a developer resistance to them. Which is unfortunate. I hate reposting what someone else has already written, but I think Jeff Atwood really hit this right on the nose: Who’s Your Coding Buddy?. I think with a decent unit testing framework combined with code reviews, it should be possible to deliver software virtually defect free.

Advertisements

Posted in Uncategorized | Leave a Comment »

debugging code

Posted by kevinup on February 23, 2009

I was helping another developer debug some code the other day. We had an if statement, that when it was true, it should throw an exception. The problem was the exception was being throw every time even when we knew the expression should have been evaluated to false. I had to laugh when I saw the code and realized what was going on.

bool some_expression_that_evaluates_false = false;
if (some_expression_that_evaluates_false);<-------------
{
    Console.WriteLine("Why is this code executing?");
    throw new Exception();
}

Posted in Uncategorized | Leave a Comment »

Central Ohio Day of .NET

Posted by kevinup on February 17, 2009

While technically you can’t register till about a month prior, I fully anticipate that I’ll be there. April 18th 2009.

Central Ohio Day of .NET

Posted in .net, ASP.net, C#, javascript, performance, tdd, web development | Leave a Comment »

Changing Priority

Posted by kevinup on February 3, 2009

So a while ago my client gave me new requirement that went something like this:

It has to be fast, really, really, really, fast. And did I mention it has to be fast? Oh almost forgot, it has to go fast.

Well, I coded it up, was pleased and moved on. This week our QA server was having some problems. It would slow down, and then suddenly be responsive again. Apparently the testers had finally gotten around to testing my little piece of functionality. The head architect came to me saying that everything was running slow on the box. My code was basically spawning a bunch of threads, doing a bunch of work, and then closing out. This was causing the processor to peak at 99%, which is apparently a problem J.

Part of me was a little proud of my code. In hindsight I should have asked more questions about how fast it needs to run in.

Anyway, with the following code, it still was able to run pretty quick, without doing any major refactoring:

Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;

Posted in .net, C#, performance | Leave a Comment »

CodeMash 2009 Followup

Posted by kevinup on January 15, 2009

CodeMash is over. I should probably say something about it before the events are stale and forgotten.

For me, I started attending topics pertaining to .Net and Agile. They were all okay nothing great. It was suggested to me by James that I should attend an Erlang session. I was skeptical at first, so I sat near the door so I could bail once it got boring. It was awesome. I was fascinated by the language, especially because it seemed to be built for performance and multi-threading; something that I have a sweet spot for. The lesson learned here is: Try to look at the sessions as a buffet, and try and get a wide variety of everything, don’t just stick with the stuff you do 9-5.

I didn’t checkout the open spaces till I missed a bunch of good ones. I did attend a good session on getting started on speaking, which is something that I’d like to start doing in 2009. Here a picture of my back during the open space, I’m wearing the green shirt on the left 🙂 http://www.flickr.com/photos/sadukie/3185385499/

Carrie and Julia really enjoyed the water park. It was nice that CodeMash provided a Cabana for the CodeMash families. Julia dragged me into the tree house one night which was pretty freaking awesome.

I’ll definitely have to get up there next year.

Posted in Uncategorized | Leave a Comment »

FUSLOGVW.exe

Posted by kevinup on December 16, 2008

I was recently tasked with deploying some code I had written. I consider myself a good heads down developer, and prefer to let deployment issue and problems be covered by someone else. Its definatly a weak point on my resume.

The deployment wasn’t too complicated, I had a little console app, that would call two different WCF services. The problem was the box I was using had different versions of the the same WCF services, and several common libraries already in the GAC. Some things were signed, some stuff wasn’t. I was about ready to jump off a cliff with amount of DLL problems I was having then someone told me about FusionLog.

FusionLogvw.exe is probably one of the coolest tools in the .Net Framework. It basically gives you a bunch of data about your DLLs as they are loaded. You can set it up to log exceptions, or just log everything. It took me all of 15 minutes to figure my problems using FusionLog. Here are some screen captures and roughly some of the information that it spits out:

fusionlog

By clicking settings you can set up what you want to log:

settingfusionlog1

By clicking on each row on the main screen here’s the type of information you can see:

—-

*** Assembly Binder Log Entry  (12/16/2008 @ 2:01:38 PM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  c:\WINNT\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\FindGoodGuids\FindGoodGuids\bin\Debug\FindGoodGuids.exe
— A detailed error log follows.

=== Pre-bind state information ===
LOG: User = KevinUp
LOG: DisplayName = Oracle.DataAccess, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342
 (Fully-specified)
LOG: Appbase = file:///C:/Documents and Settings/My Documents/Visual Studio 2008/Projects/FindGoodGuids/FindGoodGuids/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : FindGoodGuids, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\FindGoodGuids\FindGoodGuids\bin\Debug\FindGoodGuids.exe.Config
LOG: Using machine configuration file from c:\WINNT\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Publisher policy file is found at C:\WINNT\assembly\GAC_32\Policy.2.111.Oracle.DataAccess\2.111.6.20__89b483f429c47342\Policy.2.111.Oracle.DataAccess.config.
LOG: Publisher policy file redirect is found: 2.111.6.20 redirected to 2.111.6.20.
LOG: ProcessorArchitecture is locked to x86.
LOG: Post-policy reference: Oracle.DataAccess, Version=2.111.6.20, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:\WINNT\assembly\GAC_32\Oracle.DataAccess\2.111.6.20__89b483f429c47342\Oracle.DataAccess.dll.
LOG: Assembly is loaded in default load context.

Posted in Uncategorized | Leave a Comment »

CodeMash 2009 – I’ll be there

Posted by kevinup on December 15, 2008

I just booked my hotel for code mash!. See everyone there!
CodeMash 2009

Posted in Uncategorized | 1 Comment »

Multi Threading

Posted by kevinup on December 10, 2008

A little something that I’ve found myself doing a lot is performance tuning. It’s something that I find myself being delegated with, and something I really enjoy.

When performance tuning one technique is to look for places where there is work being done sequentially that could be getting done in parallel. When found, I usually start writing the same class to use the .net framework to parallelize it. Its time to make that code available for anyone else that wants to use it, plus I’ll have this post so I can start to have a repository for my code.

The idea is you have a list of inputs, do work on it, and get back a list of outputs. In the middle you have some worker class that takes a single input, and returns a single output. For the sake of an example, let’s say I have a list of urls, and I need to hit a couple websites, and return their HTML. The syntax would look like this:

List<string> returnedHtml = ThreadManager.ExecuteParallel<HitWebpage, string, string>(inputUrls);

ThreadManager spools everything up, and does the parallelizing. The first generic in ExecuteParallel is the class that does the actual work. The second represents a list of that type of inputs, in this case, a List of string’s. The last generic represents a list of the output, in this case also a list of string’s.  When using this method of parallelizing, all you have to do is write a worker class. It needs to inherit from ThreadBase, and you just need to implement Execute. Here’s what my HitWebpage class looks like:

    public class HitWebpage : ThreadBase<string, string>

    {

        public override string Execute(string input)

        {

            WebRequest request = WebRequest.Create(input);

            WebResponse response = request.GetResponse();

            StreamReader reader = new StreamReader(response.GetResponseStream());

            return reader.ReadToEnd();

        }

    }

 

I’m hoping this looks pretty simple. I’m putting the rest of the code here on http://www.codekeep.net/ if you’re interested.

Posted in .net, C# | 2 Comments »

mint.com

Posted by kevinup on December 5, 2008

I’ve been using quicken for almost 3 years, just managing the day-to-day, month-to-month budgeting of my family’s finances. It worked alright but it wasn’t great. I didn’t have the ability to send my wife information. She didn’t have the ability to see if checks she’s written had cleared, or what bills needed to be paid. And I didn’t have a way to access my information remotely.

A couple weeks ago, I was compaining about this to my Brother, and said he had started using http://www.mint.com/. I only been using it a couple weeks but it is awesome and also its free.

It has the ability to query my bank account, and retrieve transactions. It can pull down my 401k information so I can see how depressed I should be. It supports email or texting for various types of alerts, like large deposits or that you’re over budget.  It has some nifty charting, and ways to compare your expenses that are similar to quicken, but they are accessible anywhere, anytime.

My only gripe about it: I can’t import my quicken file. I’d probably even pay for it, if they could import it for me. You also can’t back date, or create new transactions.  So you couldn’t import it manually if you wanted to.

Posted in reviews | Leave a Comment »

code coverage

Posted by kevinup on October 20, 2008

I was recently talking to another developer about code coverage and it made me re-think about code coverage.

I had asked him what his code coverage was on this project, and he replied it was probably pretty bad, but that coverage didn’t matter. The quality of the tests mattered. His argument was that if you had good tests that is all you need. 

At first I agreed, I love high quality tests. I like the idea of having 2 high quality tests over 10 medium to poor quality tests. Depending on the quality of your developers that isn’t always possible to have high quality tests.  I’d rather take over a project with 70% coverage with average quality tests than one with <20% coverage with high quality tests. A high coverage number gives you a lot more confidence about your source code, and any potential changes.

I recently was on a project where we were adding items to a shopping cart. There were around 150 tests built around adding items to the shopping cart, and it broke all the time. The team was around 10 developers, and the issue was that developers didn’t have the time to run all 150 tests, which could take up to 5 minutes. So they would check in and move on without running the tests. (Yeah I know, not a good practice)

I went through and identified 3 tests which captured most of the base functionality. I asked all the developers to at least run those tests before checking code in. Coverage-wise they were probably only hitting 60% of the shopping cart logic. But because they were higher quality tests, and could be run in <30 seconds, we were able to have the best of both worlds.

Posted in .net, C#, Uncategorized | Leave a Comment »