April 7, 2009

Dev Tool Dump

Basically a link dump for different aspects of development and popular tools associated with them. I won't pretend I've had time to really look into all of these (especially the ORMs), but it is sometimes good to know there are other solutions out there.

A few things I wouldn't have minded including and would also like to look at are, different Dependency Injection Frameworks (Ninject, Structure Map, Unity), logging frameworks (other than log4net) and some task tracking solutions (FogBugz, Trac).

I know I am going to be setting up Team City with Subversion at home this weekend.

Build Server

Cruise Control
CI Factory
Team City

Source Control

Subversion / Tortoise SVN
github

Build Tool

MS Build
NAnt

Test Coverage Tools

NCover
Part Cover
NCoverCop

Unit Testing Framework

MbUnit
NUnit
xUnit

Test Runner

Gallio


Mocking Framework

Rhino Mocks
Type Mock
moq

ORM Solutions (source)

ADO.NET Entity Framework
Base One Foundation Component Library
BCSEi ORM Code Generator
Business Logic Toolkit for .NET
Castle ActiveRecord
DataObjects.Net v4.0
DevForce
Developer Express
EntitySpaces
Euss
Habanero
iBATIS
Invist
LLBLGen
LightSpeed
Neo
NConstruct
NHibernate
Opf3
ObjectMapper .NET
OpenAccess
TierDeveloper
Persistor.NET
Quick Objects
Sooda
Subsonic
Orasis

April 5, 2009

Structs

This week, structs came up for the second time in less than 2 months. I assume it is best to set the record straight for myself and hopefully others. The most important difference between classes and stucts has a lot to do with the different types of memory programmers have indirect access to. I admit I don't know a great deal about the differences between stack and heap memory, so I spent so time looking into both.

Stack Memory functions as a LIFO ordered stack. Allocation is simple and faster than heap allocation. The memory is also automatically reclaimed once it is out of scope, which beats the pants out of waiting on the garbage collector.

stack_heap

One major issue with the stack memory is that if the amount of memory required is significant and overruns what is available, you will get a stackoverflow. Another issue is that because memory is deallocated as soon as it is out of scope, data must be copied everywhere it is used. For example, whenever a struct is passed into a function, a new struct is created with the values of the copy. This is slower than just handling a reference to the memory and working with the data structure (class) in that fashion.

struct StructContainer
{
    public int x;
}
 
class ClassContainer
{
    public int x;
}
 
static void ChangeStructValue(StructContainer sc)
{
    sc.x = 5;
}
 
static void ChangeClassValue(ClassContainer cc)
{
    cc.x = 5;
}
 
static void Main(string[] args)
{
    StructContainer sc = new StructContainer();
    sc.x = 1;
 
    ClassContainer cc = new ClassContainer();
    cc.x = 1;
 
    ChangeStructValue(sc);
    ChangeClassValue(cc);
 
    Console.WriteLine("Struct: {0} \r\nClass: {1}", sc.x, cc.x);
}

Heap memory, on the other hand, is allocated through a pool or free store. Memory is accessed indirectly or through references. Memory allocation and deallocation is hidden from the developer through abstraction and when dealing with classes, involves a garbage collector.

Now, the functional differences between structs and classes are actually quite small. Both structs and classes can contain functions, methods and implement an interface. Both can have constructors, but a struct can only contain an empty constructor. Only classes support inheritance. Effectively, if you are just creating a very simple data structure that may need a method or two; it can be done using a struct or a class.

Just a note, structs can not only be expensive when passing around, due to copying, but they can also be expensive in terms of memory usage as the stack does not have infinite space. Because of their tendency to take up more memory than expected, especially if the struct is more than 16 Bytes; it is probably best to avoid using them unless you are really certain that you know what you are doing and their scope will not grow.

If you are interested in reading more about the stack and heap, I would recommend this article. This one is a fantastic read, but deals more specifically with the heap.

Identify And Prevent Memory Leaks In Managed Code

C# struct/class Differences

April 4, 2009

ReSharper

Figured I would put a serious effort behind learning how to use more of the ReSharper features and gain a better familiarity with it. I am also using the latest 4.1 build and the first thing I noticed was recommendation to use implicitly typed local variables everywhere. I like having access to implicit variables and truely enjoy programming in python because of duck typing. However, I in no way condone switching any variable in an explicitly typed language over to implictly typed just because it has support for it. Use interfaces and proper structured code, don't cheat with passing var's or using var's just because you don't have to go back and rename a variable. That is what ReSharper is for.

Fortunately, this is quickly turned off by selection Resharper Options and under the Code Inspection section select Inspection Severity. Under Code Redundancies go down to the bottom where it says, Use 'var' keyword when initializer explicitly declares type and toggle it to off.

 
Copyright © CodeCuriosity | Theme by BloggerThemes & frostpress | Sponsored by BB Blogging