Friday, August 21, 2009

Code Readability vs. Number Lines of Code

Last night I read a blog post by Phil Hack. In the post he talks about why do I have to write a commit inside an using statement when working with transaction. He then wrote some nice code to abstract the commit into a reusable function. It was a nice solution and reduced the total number of lines of code.

I was reading through the comments and someone said that by doing this he makes the code less readable. He also pointed out that debugging will also be more challenging since it is an abstraction, but I want to focus on readability. In Phil's example I did not think the readability really changed all that greatly but the person did have a valid point in general.

When writing code there are always trade offs that need to be made. less lines of code could be seen as cleaner and more optimal but at the same time it is harder for understanding what is really going on. Usually when I write code I try to make it readable, and then refactor in areas I feel are to verbose. The reason I like this is because someday someone else will be looking at the code to support it and I might not be around for them to ask me why it is as it is. Heck, I might be around and not remember why did what i did.

Don't get me wrong some abstractions I think are good, and I might use Phil's technique in future coding I do, but developers need to find a balance between abstraction and readability. I really am not a big fan of AOP for this reason. Sure it makes sense but from a practicality side of things it might not be the best solution.

Well rambling on this topic is done for now. If you have comments or want to agree or disagree hit me up.

Tuesday, August 18, 2009

He's Back

So Brett Favre is out of retirement. Again. No for sure this time. I saw the pictures of him in the Viking helmet.

I really don't know what to say about this. I guess for me the Brett Favre ship passed a year ago when he left my beloved Pack. Do I care he is a Viking? Not really. Do I think he makes them better? Maybe marginally. Will I watch him play? Yes twice when he face the Packers. Will I burn my Favre jersey? No probably not I will keep all my collectables of his. Should the Packers or the city of Green Bay name anything after him or retire anything of his? No I dont think so.

so those are my thoughts on BF. Flame away!

Tuesday, August 11, 2009

Random Thoughts

My Dad was giving me a hard time about not updating my blog enough so I guess I need to do a better job of postig things.

The Brewers are in trouble. I know there are still a lot of games left, but I don't think they have enough pitching right now to make the playoffs. That said I dont thing the sky is falling in Milwaukee, just that some key injuries have hurt them this year. They will rebouond for the 2010 season.

The Badgers have started practice and this is a team I have no idea how they will do. They have talen at RB, WR and TE. The O Line will be breaking in some new guys but should not be a drop off from last year. The QB spot looks to be weak again and thisis a team that needs to get solid play from this position. The defense should have more depth on the D Line, but the LB's are young, and the secondary is again looking like trouble. They do get Henry back, but he is coming off a knee injury.

The packers should be better than there 6-10 record of last year. The offense will be as good or better than last year, and if the Defense can learn the 3-4 defense they should come up with stops late in the game that they couldnt get last year.

Well thats it for now....

Friday, August 07, 2009

New computer

My new computer was just delivered!!

I cant wait to put it through it's paces. It is a HP laptop, with an 18.4 inch screen. It apparently does full 1080p. I loaded it up with 6gb of ram and a 1gb graphics card. It came with 64 bit versio of vista home premium. I might upgrade that to ultimate though. I also get a free upgrade to windows 7 when released.

What do I need all that power for? Well I will tell everyone it is so I can develop faster using visual studio, SQL Server and all the other tools I use, but the truth be told, SecondLife and Eve Online will just run awesome on it, plus with BluRay and hdmi out it just became the center of my entertainment hub.

IOC Containers

I know I haven't blogged lately. I have been well busy with other things but now have some time.

I am at a new client and was brought on the project mid stream. I was talking with the "Boss" about unit testing and how some of the application is tightly coupled and how that makes testing a little tough. He mentioned to me that he as planning on introducing some decoupling in the back ends and somehow we got to talking about IOC Containers.

I started talking about StructureMap and he saw value of an IOC Container framework. He asked me to build a prototype, that was a little more advanced than the basic example you see on line using StructureMap, Unity, and CastleWindsor.

I know all the Spring.Net people are going crazy now because we decided not to use spring without even comparing it, but sorry, I have used spring and I already know I like StructureMap better. Since I havent used the other tools, they were included.

The prototype was an n-tier app that used mvc.net in the ui. It had a service and datalayer. the idea was using the same interfaces and services, set up the three containers, turn one on run the app, turn another one on run the app, and so on.

The only changes to the app were in the global.asa file, where we build the containers and setting the controller factory.

So lets talk container setup. I felt the setup was pretty easy with windsor and StructureMap. Unity was a little tougher because setting things like default constructers and life management was not as clear. Luckily there was a wealth of information on the internet for how to do these things. The one thing that I really like about StructureMap is on the container you can call a method to assert that the container is valid. If it fails, it gives you a very clear error message explaing why it was not valid. you can have this check and at runtime it will throw, but better practice is just to wrtie a unit test for this. Unity when set up wrong gave me an error at runtime that was hard to understand and I had to parse throught the error about 2/3 of the way through to find out what item was causing the trouble.

As far as using the containers Unity and Windsor dont give you a static object to get your items like StructureMap does with it's ObjectFactory class. You have to manage the access to Unity and Windsor yourself. That said some will argue that if you use Unity or Windsor you would use it with the CommonServiceLocator library. This library will actually handle the container for you.

After showing the "Boss" the protorype and differences he decided to go with StructureMap. Like I told him any of the three would have worked for us, but StrucutreMap's use of Lamdas, and the added auto mocking features won him over.