Jan/080
ADO.NET Performance Improvements with .NET Framework 2.0 SP1
Recently a service pack was released for the 2.0 version of the .NET Framework.
As usual there was a laundry list of fixes, most of which were difficult to figure if they fixed or improved your production code.
ADO.NET performance was improved considerably especially when using the SqlDataReader
Original Article
Dec/070
Writing Readable Code
I think the single most important principle to writing readable code(imho)is SRP(Single Responsibility Principle)
In a nutshell
It is just making your classes and methods do one thing and that's it.
Or at the very least name your methods accordingly if they do a couple of things.
An MS Example of breaking the SRP Rule.
bool Int32.TryParse(string s, out int result)
The benefits are numerous.
It is easy for other programmers to read your code.
Your methods get much shorter.
Refactoring becomes obvious when code starts to do more than one thing.
Unit Testing is easier and clearer.
Dec/070
Inversion of Control
Even though topics on Inversion of Control have been done to death.
I want to revisit the subject to talk about the use of interfaces in inversion of control.
I think Interfaces should be used to isolate all dependencies on the outside world, not just databases.
When doing something with WCF. The client side service calls should also be using IOC so they can be isolated and the client side as a unit can be tested.

Nov/070
Xna Studio 2.0 beta
The XNA Studio 2.0 beta was released today.
The biggest feature is the ability to create networked games.
You can create them from Windows to Windows on your own own subnet right out of the box.
You can create them from windows to Xbox 360 with a creators club membership.
The functionality lives in Microsoft.XNA.Framework.Net namespace.
(Great another Net namespace in .Net)
It is great that it works out of the box with XBox Live, but at the same time it sucks that in order to play a game developed in XNA with a friend outside of my subnet I have to convince them to pay $100 to join the creators club.
I can barely convince people to play games with me for free, how on earth will I convince them to pay $100.
My solution create a proxy using wcf.
Sure would be nice if MS used Inversion of control and a factory for their connectivity piece. Then it would be easy to just drop in a proxy.
Looks like I have my thanksgiving project:)
Oct/071
Building my own .net framework
Now that Microsoft has revealed plans to release the source.
I wonder if I will be able to download it and build it on my machine.
Or is it strictly for debugging purposes?
Maybe they will even allow us to access the current build and tinker with the new features:)
That would be awesome.
I can't wait to start utilizing this feature, it will be great to be able to see what kind of stuff microsoft is doing under the hood.
Sep/073
C# 2.0 Language Features — Brown Bag Lunch Transcript
- Introduction
-
What will be covered
-
A lot of language features were introduced in the C# 2.0.
- Partial Classes
- Generics
- Static classes
- New Iterator and the Yield Statement
- Covariance and Contravariance for signatures of delegates.
- Accesibility of property accessors can be set independently.
- Nullable value types
-
I will be covering
- Generics
- Delegates
- Iterators and Yield Statement
-
-
Generics
-
Generics allow you to create type safe data structures without committing to a data type
-
Code Sample One – Wrong way
- Here is typical array list, I want to store a collection of dogs.
- What is to stop someone from adding a cat to my list?
- Nothing since this is not type safe the compiler will throw no error.
- But when we run it, it will blow up.
-
Code Sample One – Generic Way
- Here is a similar list but instead we are using generics.
- Notice the angle brackets this is where we pass in the type.
- A list is merely a generic version of a list collection that takes a type T as an argument.
-
-
Performance
-
When you use value types you have to box them in order to store them and unbox them when they are popped off of the stack.
- This leads to a performance penalty and increased pressure on the garbage collector.
- Even if you use reference types you have to cast to and from an object, which incurs a performance penalty.
- When using generics for value types expect to see a 200% performance gain, when using for reference type expect to see a 100% performance gain.
-
Using the type argument
- Code Sample Two
-
Being lazy with Aliasing
- Modify Code Sample Two
-
Constraints in the Generic world.
-
Inheritance Constraint
- Code Sample Three
-
You can also use constraints to enforce interface implementations and constructors.
-
-
-
-
Delegates
-
What is a delegate
-
The delegate keyword is used to declare a reference type that can be used to encapsulate a named or anomymous method. Once a delegate is assigned a method, it behaves exactly like any other method, with parameters and a return value.
- Example One
-
Delgates work great for callback methods.
- Example Two
- An example of this would be to define a method to transform a DataRow into an object like an account.
-
Multicasting
- In other words you can assign multiple methods to one method.
- Example Three
-
-
Fun with big words
-
Covariance and Contravariance
- Provide a degree of flexibility when matching method signatures with delegate types.
- Covariance permits a method to have a more derived return type that what is defined in the delegate.
- Example One
- Contravariance permits a method with a parameter types that are less derived than in the delegate type.
-
-
Delegates and Generics
- A can define its own type parameters.
- Example Four
-
When to use delegates
-
When to use delegates instead of interfaces.
-
Both allow a class designer to separate type declarations and implementation. A given interface can be inherited and implemented by any class, a delegate can be created method on any class as long as the signatures fit. An interface reference or a delegate can be used by an object with no knowledge of the class the implements the interface or delegate method. They seem pretty similar when should.
- Use a delegate when an eventing pattern is used.
- You want to encapsulate a static method.
- You don't need to access other properties, methods or interfaces.
- A class may need more than one implementation of the method.
- http://msdn2.microsoft.com/en-us/library/ms173173(VS.80).aspx
-
-
-
-
Iterators and the Yield Statement
- In 1.1 you can iterate over data structures such as arrays and collections using a foreach loop.
- You can use any custom data collection in the foreach as long as it implements a GetEnumerator method that returns a IEnumerator interface.
-
ExampleOne
- Why does this suck?
- Boxing and unboxing happen, so performance is bad.
- Use the generic implementation instead.
-
How does an iterator work?
- Using iterators you can have the c# compiler generate the implementation of IEnumerator for you. The C# compiler can automatically generate a nested class to maintain the iteration state. All you need to do tell the compiler what to yield in each iteration.
- Example Two
- The compiler generated nested class maintains its iteration state. When the foreach loop is first called the compiler generated code GetEnumerator creates a new iterator object. Every time the foreach object loops and calls the iterators MoveNext method it begins execution where the previous yield return statement left off. As long as the foreach loop executes the iterator maintains its state.
- Example Three
- The nested iterators is implemented behind the scenes as a simple state machine. The simple state machine will resume execution after the previous yield statement.
-
What is coming up in 3.0
- Ling
- Object Initializers
- Collection Initializers
- Anomymous Types
- Local variable type inference
- Implicitly typed arrays
- Lambda Arrays
- Automatic Properties
- Extension Methods
- Partial Methods
-
Discussion
Jul/070
Model View Presenter made easy using the Web Client Software Factory
The Web Client Software Factory was recently released.
In past couple of weeks I have been tinkering around with Ruby on Rails and have become convinced that MVC, MVP, Supervising Controller, or Passive View is the way to go.
It is a giant step in the right direction for testability and it really makes code a lot easier to read.
I have always had a hard time implementing these patterns in asp.net. Not necessarily because it is hard, but because it is such a manual process.
I tried monorail and it made me feel a little better, but it still felt a little like a hack.
Recently I downloaded Microsoft's Web Client Software Factory.
I am very impressed. It is ginormous step in the right direction.(Yep it is officially a word so I had to use it)
Microsoft has really put MVP in the hands of the everyday developer.
Just open a project of type Web Client Factory and the whole project will be generated.
The Web Client Software Factory provides wizards for adding:
Views -- Creates a page, interface and corresponding class
Business Modules -- Module that contains web pages, page flows, business logic, etc.
Foundational Modules -- Module that does not contain web pages.
Test projects can be automatically generated for the Business Modules and Foundational Modules.
The test project contains mocked tests for the view, controller, and a mock for the underlying data.
Summary of encapsulated functionality
The timing is perfect.
I still have a few days to get to Barnes and Noble and return my Rails books:)
Jun/070
On the rails bandwagon part 2 (Editors)
The first part of any good programming experience starts with the ide.
I read a lot of reviews and decided to start out with Jedit.
It was cool at first, and pretty fast for a java app. The first issue I encountered was installing plugins. I couldn't connect to the plugin repository for some of the plugins, so I had to install them manually:(
So after 2 minutes of research I found I could just copy the plugins to jar folder in /home/jon/.jedit/jar/ and voila they worked.
So I was already to import my first rails project, I opened projectviewer and added it. Infinite Loop. Yep seemed like there was a symlink in the folder structure and jEdit would just try and import the project forever. I am tired of dealing with it, maybe I will try the next version.
Next I tried Radrails. This is basically a trimmed down eclipse with some specific rails functions. Overall it is pretty nice, but I do wish I could use the command line to generate my scaffolds and my project would automatically update. I did have some problems with their new version, so I just went with Radrails which is there Java 1.4 version.
So for now I am sticking with radrails, maybe when I am more motivated I will try Cream, since I am familar with Vim
