RSS
Facebook
Twitter

Tuesday, April 28, 2009

What should I use MVC or WebForms

I have been outside of the whole website creation in .NET scene for too long.

Although I never stopped learning about web related technologies in the last year I focused mainly on desktop applications at my work and at home. The latest developments of the .NET world made me decide that perhaps it is the time to take action and have some hands-on experience in creating websites.

What I usually do when I want to understand/learn a technology is decide on a project and use the new technology to code it.

The only problem remaining was what should I choose to write my learning project with - WebForms or MVC?

Then I read To MVC or to WebForms? 

I’ve followed the links from the post through the whole argument whether or not to use MVC and looked at the pro and cons of each (by Gil Fink).

And I’ve decided – I’m going to learn MVC!

 

Any comments?

Friday, April 24, 2009

7 free tools for the Hobbyist .NET developer

I do some software development at home where I do not have the benefit of commercial software (i.e. Visual Studio Pro). Over the years I collected several open source/free tools that help me develop my pet projects.

image

[Tools required, part 1/mariusm]

 

The following is a short list of the tools I use all are free and most are open source:

  1. #Develop– This free open source IDE never cease to amaze me, weighing only 18MB it can pull his weight and has most the functionality that the commercial alternative (Visual Studio) has. It can even do some things that even Visual Studio doesn’t do for example it has code conversion (C#/VB)  and full NUnit integration. You can read more about #Develop here.
  2. Visual Studio Express – The other IDE I use when I’m not at work. When I’ve started writing code at home I had some difficulties getting used to a new IDE, like most .NET developers I’ve used Visual Studio at work and found the express editions a suitable solution for my home development. Although I find its many restrictions a bother I still use it because it has the same shortcuts and editing abilities I’m so used to from my day job.
  3. NUnit  – My unit testing framework of choice. I’ve used several unit testing frameworks over the years but I keep coming back to NUnit. It’s easy to use and has full integration with my IDE (see 1).
  4. TortoiseSVN for source control – Right now I use SubVersion for my source control needs. The free code hosting sites I’m using (CodePlex & Assembla) have subversion integration that I manage using this excellent client - It is as simple as pressing the left mouse button.
  5. .NET Reflector – The tool I didn’t know I needed until I’ve started using it. I use Reflector to investigate 3rd party .NET assemblies and check how certain feature of the .NET CLR are implemented at compiler level. If you do not know what it is try it!
  6. TestDriven.NET – If you have Visual Studio (not Express) installed you must check this Add-on. It adds integration with NUnit, NCover and several other tools. Needless to say this tool is free for personal use.
  7. Log4Net – Part of the Apache logging solution. I’ve used it at several companies I’ve worked at. It’s free and easy to use. If you need a logging solution for a .NET project you can’t go wrong using log4net.

Of course this is not a complete list. There are many other free .NET tools out there and I’m sure I missed most of them, if you have a free tool you’re using and you want other developer know about it - Write a comment telling how it helps you write better code.

Sunday, April 19, 2009

How does Stopwatch work

I’ve been using Stopwatch (and blogged about it) for some time and it never occurred to me to check how it really works. When using it as a benchmarking tool the fact that perhaps it wasn’t as accurate as can possible be didn’t bother me at all.

The question of the accuracy of Stopwatch become relevant in one of my pet projects, I needed a high precision timer and I wanted to know if it was up to the task.

Investigating Stopwatch proved to be very easy – using Reflector and I’ve opened System.Diagnostics.Stopwatch:

image

After a little pocking around I found that the actual “time keeping” is done in the GetTimeStamp() method that is used to get the current time for calculating the amount of time that passed. Diving into that method showed the following code:

image

It seems the method uses QueryPerformanceCounter (from Kernel32.dll) if it supported and uses .NET DateTime and a fall through if not.

QueryPerformanceCounter is a Windows API used to get the current value of the high-resolution performance counter directly from the processor. In fact in the past I used to use QueryPerformanceCounter for the purpose of high precision time related calculation.

Stopwatch handles all of the voodoo of initializing the related information (timer tick frequency) in its static constructor (cctor).

 

After this little research I know that I will no longer need to implicitly use PInvoke when I’m in need of high resolution timers.

Sunday, April 12, 2009

Virtual Tech-Days recordings available

Microsoft Tech-Days recordings are available for viewing and download on the Tech-Days site.

image

So if you’ve missed the my session on TDD & Mock objects it is available for download (or Online viewing).

 

I would appreciate any feedback – please feel free to leave comments or send an Email

Wednesday, April 08, 2009

Fix - Visual Studio crash when running MSTest

Today during work I had a very annoying issue - whenever I've run the project unit test suite (using MSTest) Visual Studio disappeared. This is the first time I saw it crash like this without any error message or even an exception it just vanished.

I've gone through the regular routine of restarting windows and re started visual studio but it didn't help, my helpful co-worker even suggested that I re-install visual studio 2008.

Due to the fact that installing VS2008 would have cost me a few hours of my time I've decided to investigate this issue.

A bit of searching showed the following error (using Event Viewer):

 image

Now I had something I can search for at the Internet. Simple search showed me that the issue also occours when using Azure & ASP.NET MVC and seemed to originate from a bug in visual studio when on of its add-ons uses .NET 3.5.

It looked like I needed to patch the .NET framework to fix the problem. Although it seemed a bit excessive (not to mention risky) I've downloaded the hotfix and installed it.

After (yet another) windows restart I opened visual studio and run the test suite and it worked!

Monday, April 06, 2009

Performance optimization tip – understand your memory layout

.NET take care of all memory allocation and de-allocation and after a while it seems that programmers no longer need to understand exactly how data is stored in the memory. The idea of not needing to know how data is stored could not be farther from the truth, in fact memory layout have great impact on code performance.

Test Case – For Loops

Every program I ever wrote has at least one loop and often than not I use a For loop for iterating my collections.

The following code accesses two dimensional array of integers:

for (int i = 0 ; i < width; i++) 
{
for (int j = 0; j < height ; j++)
{
testArray[i,j]
= i * j;
}
}


And it seems that there is no reason not to write the code this way:



for (int j = 0; j < height ; ++j)
{
for (int i = 0 ; i < width; ++i)
{
testArray[i,j]
= i * j;
}
}


Both code snippets do the same thing – store a multiplication of indexes in each cell of the array.



 



When run both snippets (using Stopwatch) I discovered an interesting thing – running the 1st code snippet took less then half the time it took running the 2nd snippet. More accurately when using array of 1000x1000 the 1st took 18 seconds while the 2nd took 44 seconds!



The reason for the time differences is in how the array is stored in the memory.



How arrays are stored in the memory



Allocated arrays are stored in the heap memory as a continues chunk of memory. Two dimensional arrays (same as in the example above) are stored similarly – each line of the array (index x,0 – x,n) stored together and so to reach the x,y cell we have to go to the j + (i * width) place.



image image



[Taken from C++ Notes - 2-D Array Memory Layout]



 



What it means is that when we travel the array line by line we run on the array from start to finish and when running by columns (2nd example) we jump on each iteration a number of cells of the size of the array “width”.



 



When we read/write to the array it is copied to the cache memory (which is a limited size fast memory). When traveling sequentially we make it easier for the cache to help us by bringing additional cells from the array. Obviously the cache memory have no knowledge of our array or its width and so when we jump on the memory in width size steps we do not use the cache properly and the write time takes much longer.



Conclusion



Although using .NET free software developers from the need to micro manage the memory usage of our code knowing how the data is stored and accessed can make a noticable difference.













image

Friday, April 03, 2009

How to start SCRUM/Unit testing in your organization

I just cam back from the ALT.NET meet-up (It was great!). I met with very interesting people and learned a few new things, right now I’m going over my notes from the session to try and sort the information in my head.

One of the sessions I participated in was about how to convince a company to start TDD/Unit testing or SCRUM.

Convincing my previous co-workers and friends that their team should use unit testing/TDD has been bugging me for quite some time and it was great discovering that I’m not the only one that had thoughts on the subject.

The following is a brief summery of the ideas I heard on the sessions along with my thoughts on the subject:

 

Convincing the Developers

It seemed that most of the participants of that session had some thoughts on how to convince a fellow developer to use unit testing/TDD:

1. Better Tools

  • Better tools makes it easier for a beginner to benefit from unit tests from the start (think Resharper).
  • Tools can generate high quality and easy to understand code the developer will be able to use it from “day one” easily integrating the new technology in his daily work and by working with the new technology will help asses its merits.
  • Good tools help reduce the initial (an so painful) learning curve that every dev encounter when starting to use a new technology.
    The other big advantage of a good tool is that the knowledge becomes available when a certain need raise.

2. Knowledge base

Obviously it is easier to learn a subject that has a lot of entry level information that can ease the transition.

  • Tutorials
  • Documentation
  • Blogs and forums

3. Show them how their current works becomes simpler/better

By taking an existing part of that developer/team code and using the new technology on it we can show its benefit.

In our case by showing how to implement a new feature using TDD we can convince other programmers of the benefits of using unit tests.

 

All of those will help convince a fellow developer (and perhaps a team/dev lead) to embrace the new technology – but what can we do to convince a manager (even our own manager) to use a new technology as part of the development process?

Convincing you manager

Although convincing a developer to use a new technology is important, in most organizations there is a need to convince a manager to allocate the needed resources.

On that point it seemed that the session participants had more problems then solutions…

Talk their talk

To convince someone you need to know what is important to him. So in order to convince a manager you first need to know what is important to them in the project he is managing.

If the manager cares about quality, development speed or happy employees then you need to be able to show how the new technology can do that.

Research on the subject that shows how the new technology impacts the development process will help you to validate your claims in the eyes of you manager.

Proof Of Concept or Demo

Doing a POC is good way to show your manager how the new technology can be used in the current project.

Perhaps you might be allowed to perform a such a demonstration or try to use the new technology for a while to asses it.

This is a great way to teach fellow developers on the new technology so they could also join your cause.

 

There are many ways to convince your own (or someone else) company to use a new technology I think that it is important to be positive and try to be persuasive.

Related Posts Plugin for WordPress, Blogger...