Monday, December 21, 2009

Looking back, moving forward (New years post)

In this post I'm going to reflect on the year that's almost finished and the year to come.

I came up with a few topics that are worth discussing in this post.

My career

I don't think I ever mentioned where I work. The first of January I will be working 18 months for Ferranti. The only company I've worked for since I graduated.

The first project I've ever worked on was a rather big one. Firestation Antwerp. Last year we heard that sales scored another firestation for us (Firestation Ghent). So I've been working on these two projects since I started.

Do these projects get boring? Well, not boring, exhausting maybe. These projects are very complex (Dispatching, telecommunication, websites, GIS, ..) and the requirements are very high. Although these projects are exhausting from time to time, I don't think there are other projects where I would've learned as much in such a small period of time. As a developer I have touched and worked on lots of stuff: ASP.NET, WindowsServices, WCF, WebServices, GIS, API's, Telecommunication.. You name it.

Because I've had the chance to play with so many things I'm pretty sure that web development fits me best. So next year I will try to mainly focus on web developement.

Blog

I think I've been blogging since October 2008. When I just started out the quality of the content was rather poor. Although I'm not totally satisfied with the content I produced this year, I hope the quality has improved noticeable. I saw the traffic increase significantly this year, so I hope that's a good sign.

There are a few posts that scored pretty good out there. You can find them here. I'd like to thank Arjan Zuidhof, Lee Dumond, Alvin Ashcraft, .. for helping me getting my blog out there.

By blogging I've made lots of new friends. I enjoy reading through all of your Tweets. Bart De Smet in particular has been a very good mentor.

Community

I managed to go to two events this year:
- TechDays Belgium
- Scott Guthrie in Belgium

I hope I will get the opportunity to go to some big event next year. I also plan on going to more VISUG sessions.

I've been neglecting the ASP.NET forums lately. In general I think the quality of the questions is rather poor and there are plenty of good answerers. I've been a long time StackOverflow lurker. Next year I'll try to contribute to that community.

Travelling

I managed to travel four times this year:

In 2010 I'll try to go abroad at least three times.

Wrap up

In general, my year was pretty fun. I hope 2010 will be at least as good. Excited about hearing how you did this year and what you hope to achieve in 2010!

Sunday, December 13, 2009

The problem that ViewStateMode solves

A new feature of ASP.NET 4.0 is the ViewStateMode property on a Control.

You can use the ViewStateMode property to enable view state for an individual control even if view state is disabled for the page.
Source:Msdn

In this post I'll try to give this new feature a chance to shine and show it's use.

Problem to solve: Disable ViewState on the Page and enable it on an individual Control.

Let's try to solve this without the ViewStateMode property. Simply disable the ViewState on the page and enable it on lblViewstate1.

   1:  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewState_3_5.aspx.cs" Inherits="Demo_2___ViewState.ViewState_3_5" 
   2:      EnableViewState="False"%>
   3:   
   4:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   5:   
   6:  <html xmlns="http://www.w3.org/1999/xhtml">
   7:  <head runat="server">
   8:      <title></title>
   9:  </head>
  10:  <body>
  11:      <form id="form1" runat="server">
  12:      <div>
  13:          <asp:Panel runat="server" ID="pnViewState">
  14:              <asp:Label runat="server" Text="[Static value]" ID="lblViewState1" EnableViewState="True"/>
  15:              <asp:Label runat="server" Text="[Static value]" ID="lblViewState2"/>        
  16:              <asp:Button runat="server" Text="Do PostBack" ID="btnDoPostBack" onclick="btnDoPostBack_Click" />
  17:          </asp:Panel>
  18:      </div>
  19:      </form>
  20:  </body>
  21:  </html>

   1:  protected void Page_Load(object sender, EventArgs e)
   2:  {
   3:       if (!Page.IsPostBack)
   4:       {
   5:           this.lblViewState1.Text = "[Dynamic value]";
   6:           this.lblViewState2.Text = "[Dynamic value]";
   7:       }
   8:  }
   9:   
  10:  protected void btnDoPostBack_Click(object sender, EventArgs e)
  11:  {
  12:      //Do Postback
  13:  }

Hmmm this doesn't work. When I click the button and do a PostBack the Label lblViewState1 didn't maintain it's state. It displays [Static value] instead of [Dynamic value].

You could solve this problem by enabling the ViewState on the Page and disable the ViewState on all Controls that don't need to maintain their state. But that's pretty silly right?

This is where the ViewStateMode property comes into play. Check out the example below. I disable the ViewStateMode on the Page and I enable the ViewStateMode on lblViewState1.

   1:  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewState_3_5.aspx.cs" Inherits="Demo_2___ViewState.ViewState_3_5" 
   2:      EnableViewState="True" ViewStateMode="Disabled"%>
   3:   
   4:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   5:   
   6:  <html xmlns="http://www.w3.org/1999/xhtml">
   7:  <head runat="server">
   8:      <title></title>
   9:  </head>
  10:  <body>
  11:      <form id="form1" runat="server">
  12:      <div>
  13:          <asp:Panel runat="server" ID="pnViewState">
  14:              <asp:Label runat="server" Text="[Static value]" ID="lblViewState1" ViewStateMode="Enabled"/>
  15:              <asp:Label runat="server" Text="[Static value]" ID="lblViewState2"/>        
  16:              <asp:Button runat="server" Text="Do PostBack" ID="btnDoPostBack" onclick="btnDoPostBack_Click" />
  17:          </asp:Panel>
  18:      </div>
  19:      </form>
  20:  </body>
  21:  </html>

After doing a PostBack lblViewState1 still shows [Dynamic value] and lblViewState2 shows [Static value]. lblViewState1 maintained it's state!

This feature gives us another reason to stop being lazy and use ViewState where it's designed for.

Hope this helps.

Monday, December 7, 2009

Add leading zeros to a number

Todays post is a very small tip.

I saw the question "How to add leading zeros to a number" on the ASP.NET forums countless times before. And often the answers provide solutions that work, but are overkill as well.

The two cleanest methods I know are String.Format and PadLeft.

   1:  Console.WriteLine("Using .ToString()");
   2:  Console.WriteLine(String.Format("{0:0000}", 16));
   3:   
   4:  Console.WriteLine("-------------------");
   5:   
   6:  Console.WriteLine("Using .PadLeft()");
   7:  Console.WriteLine(Convert.ToString(16).PadLeft(4, '0'));

You can see the result here.

//Using .ToString()
//0016
//-------------------
//Using .PadLeft()
//0016

Saturday, December 5, 2009

Response.RedirectPermanent in .NET 3.5 and older

One of the new features in ASP.NET 4.0 is permanently redirecting to a page using Response.RedirectPermanent.
It is common practice in Web applications to move pages and other content around over time, which can lead to an accumulation of stale links in search engines. In ASP.NET, developers have traditionally handled requests to old URLs by using by using the Response.Redirect method to forward a request to the new URL. However, the Redirect method issues an HTTP 302 Found (temporary redirect) response, which results in an extra HTTP round trip when users attempt to access the old URLs.
Source
You can achieve this functionality in ASP.NET 3.5 and older by writing a 301 Moved Permanently Status and a Location Header to the Response stream. This can be found in the HTTP specifications.

Here is an example.

   1:  Response.Clear();
   2:  Response.Status = "301 Moved Permanently";
   3:  Response.AddHeader("Location", "PageOne.aspx");
   4:  Response.End();

You can verify this by using Fiddler.

Tuesday, November 17, 2009

Book review: Professional Refactoring in C# & ASP.NET

Three months ago I was looking up to refactoring a legacy ASP.NET Webforms application. Although I was familiar with refactoring, I ordered "Professional Refactoring in C# & ASP.NET" by Daniejel Arsenovski to get deeper into refactoring.

The title

Although the title states "Professional", I think this book should find it's main audience in coding novices. Another problem with the title is the word ASP.NET in it. The book has one chapter covering ASP.NET, with only 35 poor-quality pages in it.

Now the title has some issues, but how was the content?

The content

Danijel identifies codesmells and shows refactoring techniques to solve them. Too bad some of these examples are spreaded over multiple pages, which makes them a tad sloppy and hard to read. Danijel stresses how important Object Oriented design is. He proves this by transforming procedural code into Object Oriented code, greatly improving the readability. This book should help developers who are new to or come from a non-OO background to apply the basic Object Oriented concepts. Next to refactoring techniques, he also touches refactoring tools, unit testing and design patterns.

I think the beginning .NET developer might be able to significally start improving his codebase by reading this book. For more experienced .NET developers most of the topics handled in the book should be part of their day-to-day skillset.

Conclusion

All by all I was a bit dissapointed by the book, it was an easy read, had a few interesting tricks, but I expected it would go more into depth.

Something valuable I realised though.. is that refactoring isn't something you learn by reading a book, but you learn it by obeying the constant hunger for improving your code.

If you feel confident that you dig the basic concepts of writing quality code, I would instead of buying this book, invest in a good book on Object Oriented concepts or design patterns.






Monday, November 9, 2009

My trip to Madrid in ten pictures

Last week I went to Madrid with my family-in-law to visit my girlfriend's brother and cousin.

Although our stay there was rather short (only four days), we visited some of the most impressive places in Madrid:
- Stadium Real Madrid
- The Royal Palace
- Prado Museum
- Queen Sofia Museum
- Buen Retiro Park
- Plaza Mayor
- ...


As always my girlfriend took lots of pictures, you can find my favorites below. Enjoy :)

Stadium Real Madrid



Pay attention to the stitching "Jesus in first place"


Royal Palace





Ruïnes of an Egyptian temple



Buen Retiro Park




Older lady feeding the birds. I wonder what her trick is.. Four of us tried letting them eat out of our hands, but we all failed.


Sunday, October 18, 2009

Building a simple Twitter widget using TweetSharp and ASP.NET

Widgets are a great way to spread your content. Users can just copy and paste some simple HTML or JavaScript, and off they are. By embedding this HTML or JavaScript, content is loaded from another server. Perfect examples are Google ads and Amazon ads.

I wondered how hard it could be. That's why I wrote a small Twitter widget using ASP.NET and TweetSharp. This widget simply shows your Tweets. To keep things simple it's HTML hosted in an iFrame. This solution might be a scalability nightmare tho, because it's executing the code every time the page loads.

When finished the widget looked something like this.



Let's take a look how you can build your own.

Get tweets by username

I used the very Elegant TweetSharp API for this.



   1:  private IEnumerable<TwitterSearchStatus> GetStatuses(string screenName) {
   2:       var twitter = FluentTwitter.CreateRequest().
   3:                                  Search().Query().FromUser(screenName);

   4:       return twitter.Request().AsSearchResult().Statuses;
   5:  }      



Build the widget

This method builds the HTML. I used the HtmlTextWriter class for this. A safe way to build HTML.


   1:   private String BuildWidget(string username, IEnumerable<TwitterSearchStatus> statuses) {
   2:              StringWriter stringWriter = new StringWriter();
   3:              
   4:              using (HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter)) {
   5:                  htmlWriter.RenderBeginTag(HtmlTextWriterTag.B);
   6:                  htmlWriter.Write("My tweets");

   7:                  htmlWriter.RenderEndTag();
   8:   

   9:                  htmlWriter.RenderBeginTag(HtmlTextWriterTag.Div);
  10:                  htmlWriter.RenderBeginTag(HtmlTextWriterTag.Ul);
  11:   
  12:                  foreach (var status in statuses) {
  13:                      htmlWriter.RenderBeginTag(HtmlTextWriterTag.Li);
  14:   
  15:                      htmlWriter.Write(String.Format("({0})", status.CreatedDate.ToString("hh:mm")));
  16:                      htmlWriter.Write(" ");
  17:                      htmlWriter.Write(status.Text);
  18:                      
  19:                      htmlWriter.RenderEndTag();
  20:                  }           
  21:   
  22:                  htmlWriter.RenderEndTag();
  23:   
  24:                  htmlWriter.AddAttribute(HtmlTextWriterAttribute.Href, "http://twitter.com/" + username);                
  25:                  htmlWriter.RenderBeginTag(HtmlTextWriterTag.A);
  26:                  htmlWriter.Write("Follow me");
  27:                  htmlWriter.RenderEndTag();
  28:   
  29:                  htmlWriter.RenderEndTag();
  30:              }
  31:   
  32:              return stringWriter.ToString();             
  33:          }



Writing the widget to the page

On the Page_Load event of the Page I get the username from the QueryString, get the statuses for this username, pass them to the BuildWidget method and write that result to the Reponse Stream.


   1:  protected void Page_Load(object sender, EventArgs e) {
   2:              string username = Request.QueryString["username"];;
   3:              if (!String.IsNullOrEmpty(username)) {
   4:                  Response.Write(BuildWidget(username, GetStatuses(username)));
   5:              }
   6:          }



Embedding the widget in a page

I hosted the widget in an iFrame. Set the src attribute of the iFrame to the url of your widget.


   1:  <div style="width:30%;height:100%;float:right"> 
   2:              <iframe scrolling="yes" 
   3:                  style="" 
   4:                  frameborder="1" 
   5:                  src="http://localhost:1524/TwitterWidget.aspx?username=JefClaes" 
   6:                  marginheight="0" 
   7:                  marginwidth="0">
   8:              </iframe> 
   9:          </div> 



That was pretty easy right?

Friday, October 2, 2009

RSS in .NET

A few days ago, I was playing with some RSSFeeds.

As far as I knew, I had to build an HttpWebRequest, get the HttpWebReponse and parse the response. While searching for the RSS defenition, I realised that this must have been done 1000 times before.

I googled RSS .NET and found one relevant link to a dead/failed open source project. Looking further I came across some articles which used an XmlReader and LinqToXml, but this wasn't what I was looking for. I asked whether there is any good RSS library in .NET at StackOverflow, and one smart guy pointed me to the System.ServiceModel.Syndication namespace. This is new in .NET 3.5 and after looking around some more I found out that it's a pretty unknown namespace.

After playing with it for 15 minutes I was pretty sure this was exactly what I was looking for.

Reading and creating RSS has never been this easy/safe.
You can find how to read an RSS Feed an how to create a new RSS Feed below.

Reading an RSS Feed




Create an RSS Feed




Pretty simple right?

Saturday, September 12, 2009

Why the javascript beforeunload event is incomplete

The onbeforeunload event fires when a page is being unloaded.

In the intranet webapplications world customers pretty often ask to show a warning when a user leaves a page (by closing the browser, closing a tab, clicking a link,..). This feature is specifically very interesting for data-input-driven webforms where one wrong click can make ten minutes of work undone.

Last week I had to implement this feature in a huge webform which is causing lots of postbacks (firing the onbeforeunload event). Actually I only had to warn the user when they closed the browser or clicked a link in the masterpage. I figured out that the beforeunload event must have some convenient properties, but as you can see below, it had no properties which I could use.



Of course there are workarounds for this problem, like there are workarounds for almost all technology problems. But these workarounds often make tasks harder and less "clean".

In my opinion the browsers could and should do something about this. Adding a few properties like unloadedbysrc, unloadedbytag, unloadedbyid would make our life a tad easier.

What do you think?

Wednesday, September 9, 2009

Debugging "SubReport could not be shown."

I've been upgrading a local report which contains multiple subreports, and yes I got that "SubReport could not be shown." error more than once.

Debugging this error is a pain in the a.. All you get is "SubReport could not be shown.", making me want to punch my screen and scream "BUT WHY?"

Just before breaking my screen and going on full tilt, I decided to take a step back and run through my checklist.

Here it goes..

Can the reportviewer find the subreports?

If the subreports are in another location (other folder, other assembly..), the reportviewer will not find them.

The solution for this problem is using the LoadReportDefinition method and passing the report definition as a stream. An example can be found in this post.

Are you passing all parameters?

Doublecheck your report parameters.

Are you passing all the required/correct data to the report?

Are you handling the SubReportProcessing event, to pass the data to the subreports, not the main report?

Did the database definition change? Did a query break? Is the structure of the query still the same as defined in your report definition?

Are there other things to add to this list?

Tuesday, September 8, 2009

Three common mistakes you should avoid when starting with Web Page Resources in ASP.NET

This is a list of of three common mistakes made by developers who start using Web Page Resources in ASP.NET.

1. Not using the right format for the name of a local resources file

The format of the name of a local resources file should be: PageName.PageExtension.resx.

If you don't add the page extension (Aspx, Ascx), you will get the Exception "The resource object with key 'PageTitle' was not found.".

2. Not adding an App_LocalResources folder to each subfolder

Each subfolder must have it's own App_LocalResources folder, else ASP.NET will not be able the find the resource, leading to the "The resource object with key 'PageTitle' was not found." Exception again.

3. Not understanding the difference between GlobalResources and LocalResources

In general global resources should be used when you need a resourcekey in multiple pages through your site. Local resources are page-specific.

This article on MSDN contains a great summary.

You can use any combination of global and local resource files in the Web application. Generally, you add resources to a global resource file when you want to share the resources between pages. Resources in global resource files are also strongly typed for when you want to access the files programmatically.

However, global resource files can become large, if you store all localized resources in them. Global resource files can also be more difficult to manage, if more than one developer is working on different pages but in a single resource file.

Local resource files make it easier to manage resources for a single ASP.NET Web page. But you cannot share resources between pages. Additionally, you might create lots of local resource files, if you have many pages that must be localized into many languages. If sites are large with many folders and languages, local resources can quickly expand the number of assemblies in the application domain.

When you make a change to a default resource file, either local or global, ASP.NET recompiles the resources and restarts the ASP.NET application. This can affect the overall performance of your site. If you add satellite resource files, it does not cause a recompilation of resources, but the ASP.NET application will restart.

Sunday, August 23, 2009

Why code reviews should be a teamthing

Often code reviews are done by one person, the technical lead of your team.

In my opinion it's better to make each developer of your team do code reviews.

My arguments
  1. Having all developers doing code reviews enforces well-documented coding standards..
  2. Which also leads to discussions about what these codings tandards should be.
  3. Each developer is forced to understand the workflow of an application which isn't his, which expands his domain knowledge.
  4. Each developer learns from others and is given an opportunity to teach and discuss why someone chose a certain path.. There is always something new to learn, even for seasoned developers. You might just pick up that latest trick doing whizbang Silverlight 3 stuff from that freshman that just started working this year.
  5. Multiple perspectives on a problem can only benefit the solution.


What are your thoughts?

Thursday, August 20, 2009

My holiday in France in five pictures

Last week I went on a holiday to France with my girlfriend and her family.

Because pictures say more than words..

One: The location - Laguepie, Albi



Two: The house and "la piscine"



Three: Me enjoying the sun



Four: Only in France you find a 1955 Peugeot 403 with numberplates just standing there next to the road



Five: Random picture of one of the towns next to Laguepie



Looking forward to the next holiday :)

Saturday, August 1, 2009

Managing UserControls using Interfaces

It's a pretty common situation where you have multiple UserControls in a page which all expose the same functionalities.

In the project I'm working on right now, we have a big TabContainer. And each Tab is a UserControl. One button should make all the Tabs save their data, but not every Tab is always loaded into the TabContainer. As you can guess, we needed something generic.

That's why I introduced the ITab interface. Every UserControl implements this interface.

When I hit that save-button, a method iterates trough the ControlCollection and looks for every type that implements the ITab interface.

Take a look at this codesnippet.



The public method Iterates through the ControlCollection and checks if the Type is a Tab using the private IsTab() method. This private method uses Type.GetInterfaces() to iterate through all the Interfaces for that Type. If the control is a Tab, I cast it to an ITab and call a public method depending on the ReportMode.

Thursday, July 9, 2009

Active Directory in .NET: Recursively find all groups for a user

I had to write a function which returns all the groups (even if they are nested) for a user.
A good thing I discovered the System.DirectoryServices.AccountManagement namespace.

Take a look at the code snippet. I think it's pretty readable.. What do you think?



The GetListOfGroupsRecursively() function tries to find a Principal object by the Username of the ADUser parameter. If the Principal object is found, we call the GetGroups() function and store it's return value in a PrincipalSearchResult. If there are searchresults, we try to get the members for each group by calling the GetMembersForGroup() method. This method recursively searches through all the members of the group looking for Principal objects where the StructuralObjectClass equals "group".

Tuesday, July 7, 2009

Active Directory in .NET: Getting started (A better version - Using the AccountManagement namespace)

A few days ago I blogged on Active Directory in .NET: Getting Started.

In that post I stated that everything you need to query the Active Directory in .NET lives in the System.DirectoryServices, well that was a lie. .NET Framework 3.5 introduced the System.DirectoryServices.AccountManagement namespace.

I learned about this namespace today, and wow, it really is much better. I have rewritten our own Active Directory wrapper in less then a few hours.

All you need to know in general is that everything you do using the AccountManagement namespace needs to run under a PrincipalContext.



Let me show you two basic methods..

I commented out the original method which uses the DirectoryServices namespace. Can you see the difference?

Authenticate a user



Get the DisplayName of a user



The code hardly needs any explanation. Hope it helps!

Sunday, July 5, 2009

Active Directory in .NET: Getting started

Note: If you are using .NET Framework 3.5 or better, check out this post for querying the Active Directory!

Working with the Active Directory is one of the things that every .NET or ASP.NET will face in his career. Most of the time you need information from the Active Directory. Editing, inserting or removing objects from a .NET (web)application is very rare, mostly because a System Administrator is managing the Active Directory.

Let me show you how to get started on getting information out of the Active Directory.

The basics

Everything you need to work with the Active Directory lives in the System.DirectoryServices namespace.

The most important classes you will need are:
Directory Searcher
Directory Entry
Search Result

So I advice you reading through the documentation of these classes.

Getting familiar with LDAP queries

I strongly advice you to try LDP.EXE

Ldp.exe is a Windows 2000 Support Tools utility you can use to perform Lightweight Directory Access Protocol (LDAP) searches against the Active Directory for specific information given search criteria. This also allows administrators to query data that would otherwise not be visible through the Administrative tools included in the product. All data that is returned in LDP queries, however, is subject to security permissions.




This tool will help you understand LDAP queries. Go through this article in the Microsoft Knowledge Base to get started.

Thursday, May 28, 2009

Programmatically/Dynamically building an RDLC

I was designing a Local Report when I stumbled upon a shortcoming of the Report Rendering Engine. A Rectangle has a Hidden property. When you set the Hidden property to True, the content of the Rectangle doesn't render, but the space of the content is preserved. In my case, this caused some white pages. So I looked for a way to build a RDLC programmatically. An RDLC is just an XML, so how hard could it be :).

I first searched for an example on MSDN, but I didn't like the way described there. In this article on MSDN they use a XmlTextWriter, which makes the code hard to read and not very maintainable in my opinion. You can find that MSDN article here.

After some further investigation I found the RDLC XSD on MSDN. You can find the XSD here.

I used the xsd.exe Tool to generate a Class based on the XSD. This way you can create an RDLC in a more Object Oriented way, which leads to more maintanable code.



It would be awesome if someone had the courage to add comments, so Intellisense would be able to help creating RDLCs programmatically.

After adding the Report.cs to your solution, you can start making your own RDLCs programmatically. Note that the ReportViewer needs a Stream to read the RDLC.

I chose not to show my whole implementation of my own ReportGenerator, because it's not really a good example. These steps might get you started though.

1. Create a new Report object.
2. Do whatever you want with the object.. Add textboxes, rectangles..
3. Before reading the Report object into the ReportViewer you need to serialize the object to a Stream. I chose to use a MemoryStream. (Don't forget to set the position of the Stream to 0!)



4. Load the Local Report in the ReportViewer using the LoadReportDefinition method.



And that should be it!

Tuesday, May 12, 2009

The report definition for report 'path' has not been specified

The full errormessage is:
The report definition for report 'path' has not been specified. Could not find file 'path'.



If you use an installer to install your webapplication, this error might occur when you try to run a local report (rdlc).

The solution is to set the property "Build Action" of the rdlc to "Content". Now your installer will copy the physical rdlc.



Thanks to my colleague Kris S.

Friday, April 24, 2009

Interview with Arjan Zuidhof from Arjan's World

Like the title says, I had a little chat with Arjan Zuidhof from Arjan's World.

Arjan has a opinionated linkblog, on which he posts on a daily basis.

Here it goes..

Next to blogging, what do you do for a living?

I'm a thirty-something developer from the Netherlands working as an inhouse .NET developer in a big company, somewhere in the Randstad (western part of the country). I mainly work on projects related to customer data in the broadest sense. We pull all kinds of tricks to relate several pieces of data like names and addresses and do judgments on them based on complex business rules. Sounds dull, but it can be quite interesting. I'm looking to see if I can pick up some more ASP.NET work though, as web development is actually my secret love. So that's why in my spare time I pick up things like ASP.NET MVC.

Can you give an example of a project you are working on? What is the structure, which Microsoft technologies do you use?

Right now I'm working on a fairly large project that's in maintenance. It's a bunch of spaghetti code on which some new functionality must be added. Difficult work, but I use unit tests, refactoring, and basically the pragmatic principle of 'do not touch what does not absolutely need to change'. It's hard though to find enough time to do all this AND add additional features on customer request. But we all know that don't we? The project was originally written in .NET 2.0, using basic NET remoting to connect a Windows Forms client with a backend server. Unfortunately the project needs to be supported for a couple more years, and does not lend itself for improvement (WCF and WF come to mind here, but alas). The good thing is we work with the latest Visual Studio / TFS stack, so there's enough new stuff to explore.

It must be challenging to work on legacy code. Are there any good books you've read on working with legacy code? Are there some more tips you want to share?

I'm currently using the well known 'Working effectively with Legacy Code' by Michael Feathers. It's a biggie chock full of tips on how to get your teeth in spaghetti code and make something nice out of it. Refactoring, introducing patterns where appropriate, isolating parts of your code. It is all there. I would advice not to read it from beginning to end, but rather just dive in and read the topics that you currently need to know about. Think Michael advises this himself somewhere too.

What framework do you use for your unit tests?

Arjan: We're using the default one in Visual Studio (don't they call it Team Test?), but I'm investigating nUnit, which is way nicer and more powerful.

Our team is using Team Foundation as well. We are currently not making use of its full potential though. We mainly use it for Source Control. Which features of TFS do you use? Which ones do you like, which ones do you hate and which ones haven't you tried out yet but look very interesting.

We mainly use the developer related features, since (project) managers are a bit hesitant here to put the system into good use :) That means work item / feature / bug tracking, builtin version control (which sometimes needs to be screamed at to work correctly, by the way). We're using several build definitions that deploy automatically to drop zones. That's about it I guess. There's the nice reports and all, I know, but the developers don't really need them currently to get the job done.

Let's change the conversation a bit onto your blog. I think you are doing a great job, but how do you manage all that information?

A decent feedreader of course :) At first I used Bloglines, but some time ago it had a lot of glitches and outages. It was constantly 'forgetting' your status. Then I found everyone and their mother talking about Google Reader. Of course that's the most used feed reader nowadays. And with good reason!

To get an idea. Can you tell us how many blogs you follow? And how many posts you read on average each day?

I'm using the Reader to successfully track something slightly less than 600 feeds on a daily basis. Don't know how I manage, I just do :) Well, as a matter of fact, I do know: it's all about creating the right categories: most important feeds are always checked completely. But there's a lot of fluff, of just basic news out there which I only read when I have the time (not often), and categories that I just quickly skim for interesting topics.

How many posts a day: that's the nice thing about Google Reader, it tracks this for you in a 'Trends' section. Trends says I 'read' 5217 article in the past 30 days. Now, this doesn't mean that I completely read them all (mind you), just that they were in front of my eyes for a moment, to see if they were interesting enough to link to. I guess I make this decision in a split second, based on title of the post, and the name of the author.

Have you tried out non-webbased RSS Readers?

Not really. Tried FeedDemon and RSSBandit some time ago. But working on several machines requires keeping track of several software installs and use something like Dropbox to synchronise the data files. Could easily do that, but since I'm rather the lazy type - there's your real reason I prefer web based readers - haven't done that so far. And Google Reader's good responsiveness is keeping me from switching.

Do you feel like reading blogs helps you a lot in being a better developer? If so, in which ways?

Well, sure. For the obvious reasons: teaching me new and often better ways to do something (let's call this the 'tricks'). Then there's another slot of bloggers who focus more on the deeper insights behind programming (design pattern, methodology, agile development etc.). You don't always need to agree completely, but there is lots of good content out there that at least deserves some serious mulling over. And sometimes they show me how *not* to do things. Fortunately the first category is way bigger than the second (You probably all know The Daily WTF. If not, then you absolutely pay them a visit for an overwhelming number of examples of the latter category).

To wrap up this interview (A Top-10?). Which are your favorite blogs? 

A Top-10 you ask? Don't like top-x lists at all, but since unscientific evidence has shown that they have a great click-through rate, we have to deal with them :) Only thing: there is not one single blog that I would call upon being my no 1. Besides, it's hard as by definition this would exclude an overwhelming amount of top notch blogs. Still, away with the excuses,here's the unsorted list:

  1. The guys at Codebetter.com. Almost every day they contribute some food for thought related in one way or the other to methodology. Highly reccomended!
  2. Los Techies guys: same reason as above.
  3. Leon at the Secret Geek blog. Humorous and less humorous posts on a not so regular basis. He brought my little link blog fame by awarding me the ‘Next Mike Gunderloy’ award when Mike Gunderloy stopped linkblogging when 2007 came to an end.
  4. Simone Chiaretta a.k.a. the Code Climber. Enthusiastic Italian MVP who just released a book on ASP.NET MVC.
  5. Scott Hanselman. Though he lost a little bit of his touch since joining the ranks at Microsoft, he’s absolutely an avid blogger, podcaster and overall tool geek.
  6. The Lifehacker.com blog. For a couple years already lifehacks, GTD, and more recently the rise of social software attract me. There is truly a revolution taking place in this field. A lot of things we took for granted for a long time are suddenly obsolete without us realising it. Let this entry in the list be representative of my interest in this domain.
  7. Michael Lopp a.k.a. Rands (in repose). The guy who wrote “Managing Humans”, great book. New articles drip in on his blog; not too often, but when they do, you do yourself a disfavor not to read them
  8. Jeff Atwood. Though he gets a lot of flak, the guy does an awful lot of research for high high profile, high rotation blog (100K+ readers). There is not a subject he has no opinion on
  9. Rajiv Popat: .NET developer writing a lot about tools, technology and project management. Think I said it before but the guy is a hidden gem.
  10. All the other guys and gals that were not mentioned here but make great contributions to the blogosphere. Thanks for giving me enough stuff to link to!

And thank you for the talk!

Friday, April 10, 2009

ie6-upgrade-warning

This is one of the better initiatives in the campaign against IE6.



You can find the little script and some more information here.

I finally had the chance to do something for the opensource community.. I added the translation in Dutch ;)

Sunday, February 15, 2009

Stored Procedures: Make them or break them

I've been thinking about the use of stored procedures lately.

Some questions that popped up in my head: What are the advantages/disadvantages? When and how should they be used? Will they extinct with LINQ to SQL becoming more and more popular? Why should you store your queries in your database, instead of in your code..

I asked the opinion of a few ASP.NET/.NET professionals. Hope you find this interesting!

Kris Van Der Mast (Blog)


Since I'm a consultant I have to go with the specifications of my clients. Most still use stored procedures though I see a shift occurring. My current client allows us to use Linq To Sql for select statements (generated by L2S) but for update, delete and insert statements they require us to make sprocs since they put security on it on a database level. My former client allowed us to use NHibernate (winforms project) but for 3-4 special occasions we used sprocs.

SyntaxC4 (Profile)


I do use Stored Procedures on a regular basis. I develop mostly in DotNetNuke, which has an extensive use of stored procs. I have read blogs, and forum posts that suggest that stored procedures shouldn't be used as they can be a performance bottleneck, but I believe they are an excellent way of promoting SQL Abstraction. 
I do however try to preserve the number of stored procedures I write. I normally create one stored procedure to handle both insert and updates to the a particular table, one for deleting, and one to select (sometimes i do multiple select statements within one stored proc if it makes sense). 
To work away from bottlenecks, i try to use subqueries in my stored procedures instead of using a view to query against. unless of course a view is more efficient.

TATWORTH (Profile)


It is not much a case of would I use stored procedures as when would I not use them! Occasionally for searching, dynamic TSQL needs to be generated and for this I would use parameterized TSQL. Otherwise I use stored procedures all the time. I do have stored procedures for generating from the table definition stored procedures plus wrapper code. This allows very rapid development of the data layer.

The use of stored procedures (or the occasional parameterized TSQL) is in my opinion one of a series of essential steps to produce robust applications.

Tom Peeters (a co-worker)

I prefer to (read always) use stored procedures when I’m developing front end applications. 
The ones who find creating stored procedures is intolerable overhead, I want to give some advantages.. 
  1. They are modular, I’d prefer to troubleshoot a stored procedure than an embedded query buried within many lines of GUI code.
  2. They are tunable. Changes can be made to the stored procedures --in terms of join methods, differing tables, etc.-- that are transparent to the front-end interface.
  3. Stored procedures abstract or separate server-side functions from the client-side. It is much easier to code a GUI application to call a procedure than to build a query through the GUI code.
  4. Stored procedures are usually written by database developers/administrators. Persons holding these roles are usually more experienced in writing efficient queries and SQL statements. This frees the GUI application developers to utilize their skills on the functional and graphical presentation pieces of the application. If you have your people performing the tasks to which they are best suited, then you will ultimately produce a better overall application.
In short, queries are best handled via stored procedures. While the initial development overhead is greater, you will more than make up for the investment down the line.

Looks like a lot of people are still very fond of stored procedures. The arguments make a lot of sense!

What are your thoughts on stored procedures?

Tuesday, February 10, 2009

Being a developer in India

Nowadays all you here is: hey let's outsource our call center, our IT department, our developer team.. to India. I asked Mudassar Ahmed Khan a few questions about how it's like being a developer in India.



How is it like to be a developer in India?

Quite bad..
  1. You get into heavy competition from day one when you join a Computer Science course.
  2. Companies set percentage criteria for young graduates. If you are below those criteria you will have a hard time finding a job.
  3. If you get into the company, the company decides what you will work on.
  4. For Multinationals you need to pay security amount which is refunded when you complete a certain period in the company the period has a range 1-4 years depending on the company.
How do you make up for the lack of experience? Work harder, be more passionate, ...?

In Multinationals you can't be more passionate because you have a lot of restrictions. But you get a fair amount of money too. In Midsized and smaller companies, you'll get good work but at the cost of less money. But here too you can't be passionate since the Team Leaders and Project Managers mostly don't allow you to do so. So it's the company which decides much rather than the individual. It's very rare that you get into a company that allows you to use ideas like mine.

What is the general feeling about outsourcing? Is everyone just content that it is great for the economy, or do people have doubts?

It has increased the IT in India and many companies take up outsourced work from other countries. Recently the recession affected many companies and they have removed many employees. So it has both positive and negative effects.

Do you think India is a threat to Europe?

I have no idea in that perspective.

Monday, January 12, 2009

Interview with Curt Christianson (Part II)

This is part II of the interview with Curt Christianson. For Part I go here.

Part 2: Technology


Let me ask you some general questions about building a web application. What is your advise on setting up the layers of a web application. In the web application I'm currently working on we chose a not so standard architecture I guess. We have multiple "modules", which are folders in practice. In the root of these modules we hold our aspx pages. For each module we have three folders: BLL, DAL and Controls. In our BLL we hold our objects, some logic, ... In our DAL we stock our typed datasets based on stored procedures. We divided our pages into Controls, because our pages are pretty big. We access all of our data methods in the controls, using ObjectDataSources based on the typed datasets. We try to make as much use as possible from the ObjectDataSources using the designer, some custom things are done in code-behind. But we found out that this architecture is a hassle. It doesn't give a much as control as we'd like and debugging/logging really is a pain in the ass. A problem is that we can't use the designer as much as we want, because we needed to add more functionality/business logic than the designer allows us. With the result that some of the logic is in the aspx page and some in the code behind. What is in your opinion a better architecture?

From the sound of it you are running into some of the same circumstances I did. I found that using the pre-build datasources were WAY too much limitation for me. I tend to toss them out right away and switch to a more manual approach. This does make more work (you have to do sorting and paging yourself) but other than that I found it a lot easier to work with.
I used to be a fairly strong believer in the 3 tier approach but have come to the conclusion that for 99% of work that's done you are best off with a simple 2 tier approach. There is no real need to seperate the Business and Data layers. Combining the object definitions with the calls to the database and mixing in the validation from the business perspective all at once seemed the best bet. I still break the pieces out into seperate methods but I've combined them all into one set of classes instead of 2 distinctive ones.
Now, as far as controls go... my rule is simple... if I use it more then once it's a control...if not, then it's coded into the page. I never make a code block into a control unless there is a reason to...otherwise it's extra work for yourself. That said... i was VERY guilty of the opposite. I used to take every Asp.Net control and make a custom control that inherited from the native one. Then I would only use the custom one...just in case some day I wanted to enhance it (I almost never did) so eventually I stopped that nonsense.

What is your opinion on using stored procedures? Some say using stored procedures is oldschool.

 I've really shifted away from it. In the past, with previous versions of MS SQL you really wanted to use them as much as you could for perf reasons, but now that's really not the case. What I've done is actually make all my SQL statements simply constants in my application. They are all in one class file so they are easily found and tweaked when needed. I do parameterize everything though...this is a MUST in my book.

About using the sql queries in your classes.. Are you simply returning datasets from your functions and binding these to your controls? Are you planning on using LinqToSql in your future projects for this? What is your opinion on Linq? I also wonder if you have any idea what Microsoft's is opinion on the issue of not being able to use the datasources for more complex things, because basically that's what they are designed for, to reduce development time. What is your opinion on this. Should Microsoft do something about it?

I used to use datasources a lot but since vs2005 I discovered Generic.List(of ). This has been my favorite thing. Everything now is bound to a List(Of myObject), hence the custom sorting and paging. I've used LinqToSql in the past to play around but the limitations were too great. My objects are often complex and it didn't really handle them well. The new Entity Framework stuff looks more promising though, and it looks like LinqToSql is already "obsoleted" in the framework anyways.
I don't think these datasources were really meant for anything other than small-midsized applications (complexity wise). They were always meant (in my opinion only of course) to be for those times when you need it fast and easy and you have a one-to-one relationship with your datamodel and application classes.

You also co-edited a book about AJAX? AJAX is an awesome technology. "Javascript that works". I really think I am not using AJAX to it's full potential though. What I am using is the UpdatePanel (which is the best control ever) and the AjaxControlToolKit. That's it. What am I missing here?

I wouldn't say edited.. but reviewed. It's different, but same basic concept. Personally, the UpdatePanel is THE heart of Ajax. Beyond that it's all secondary. So, with that I'd say you are actually right on track with what you need for Ajax.

The other book you reviewed was on WPF, right? What are your thoughts on WPF? Is it gonna take of soon? Is this the end for WinForms?

I've actually reviewed at least a dozen different books over the last few years.
The WPF one was a while ago but it's just coming out in published copy.
For me WPF is something that's interesting but not something that I will probably ever do much with. Is *it* the end of WinForms... absolutely not. Is it *part* of the beginning of the end... sure.

Now...if I was to take a stab at the prediction of development here's what I see. WinForms and WebForms will both really "die off" and what you'll see come out of the ashes will be a conglomeration of the two. More like a child of the two rather than one taking over the other. The differentiation between two negligible. The user will never really know, or care, where they are operating. It's not really "cloud" computing (that's just poor PR in my opinion) but rather a melding of the two. With things like Ajax, WPF, WCF and all the other acromyms, we are on the way. I think in the next 2 years you will see some real distinct breakthroughs, especially with hand-held platforms, that will be the hybrid we're after. Take those and extend them to the larger CPU capacity of the home PC and you get some idea of what could be done.

Are you thinking of more Surface like interactivity?

Not really... surface is cool, and definitely part of it. The multiple-input, touch-sensitive piece will definitely find it's place with the new scheme but I don't think we're really gotten at the core of the new stuff yet, it's still on the verge of being discovered (or tucked in a lab somewhere). Think of a meld between the PC, Laptop/Tablet and SmartPhone, but all as one device with all the best features of them all and integrated into a form factor yet to be determined (I have ideas but still to early to say).

I think that's a good line to end this interview! Thank a lot.

Thursday, January 8, 2009

Interview with Curt Christianson (Part I)

Curt Christianson is one of the administrators of forums.asp.net. Last month I stumbled across his blog, and felt like I had to do an interview with him. And here we are!

I have divided his interview in two parts:
  • His career and his life
  • Some techtalk on mainly ASP.NET webproject-architecture mixed with a bit of AJAX and WPF

Part 1: Career and life


Who are you? Where do you live? What do you do for a living?

The question of who I am is a toughie... I'm really at a transition point in my life. For years now (too many to count) I would have simply answered "geek" but with this last year coming to a close and the start of a new one I feel like I've also hit a changing point. I've refocused my energies on my life and family (just got engaged, just bought a new house) and shifted away from a lot of the day to day "geekdom" that ruled me (I closed up my consulting business). I live, and grew up, in Central Wisconsin. The weather is nice (excluding the heavy winter months), the cost of living is great and the education systems are really quite great (thinking about starting a family soon). I pay the bills with a good job as a high level programmer with Asp.Net at a good sized insurance company. It's not the glamorous lifestyle but it's definitely a solid position with a good future. For a number of years I supplemented my daily work with private applications development with my consulting business but eventually the time comes where you need to pick priorities and, as it should, family and friends won out.

How old are you? How long have you been into software development? Can you describe your experience as a junior developer?

I'm currently 36 and have been in the computer industry (professionally) for about 12 years but I've really been a geek since I got my first Atari 2600. My career is actually one that's a little different (I think) from most of the Sr. level developers out there. First off I actually went to school for something completely different. I was an English Lit. major in college (I attended the University of Wisconsin) but after 5 years I called it quits and left when I couldn't afford it anymore. When I returned from school I took a job at a software duplication company working the line. It was a 100% non-technical position and simply an assembly line type thing. While working there the equipment would break a lot... so I tended to take on the initiative of fixing the stuff myself. Eventually they hired me into their tech support area but that was pretty boring to me. I left there and went to work for an off-shoot of the state where I traveled around and worked at distance learning labs all around the State. I also was contracted out to help out a couple school districts in the area part of the time. My focus was all on the networking and server side of things. That lead me to another company that was an actual software focused business but my role was more of one of server setups and networking support again. After a few years I got pretty bored with it. Eventually I got a job as an Asp developer (not Asp.Net but the old stuff) for a construction company. I pumped out some great work while I was there and actually got noticed by Microsoft and was awarded the MVP award for the first time. That was October 2002 I believe. The company I was at was has a very small I.T. area and I started to get the itch to do more so I took the opportunity to go to an insurance company specializing in travel related products. I stayed there for about 3 years and really honed my .Net skills. Like most of us I got the itch again and moved on to a larger company. This time it was another insurance business but with a huge I.T. area and some incredible projects underway. That was about 3 years ago now and things are still going strong..

For me to describe my time as a Junior developer it would really only be one word...."short". When I started development the programming department at the company I was at consisted of ME..... There were a few others but for the stuff that I was doing there wasn't anyone but me really (and the newsgroups...they saved me). With this, I really had to immediately step up and take on a more controlling role. So in reality my first programming job was as a Sr. developer and from there I continued to take on new roles at new companies but always in a lead/Sr. type position. I think there are some developers out there that are destined to always be a Jr. developer. Some lack passion, others skill, but most of the ones out there that have at least one of those two things (or better yet, both) will quickly find themselves climbing the ranks. People who love what they do will get noticed and that will usually be the key to getting the next step up the ladder.

When did you start up your consulting business? What are your thoughts afterwards on having a consulting business together with a fulltime-job? Is it worth it?

As far as my consulting business goes it's really a two-parter. First off, back in the late 90's I had a computer business that I ran. Mostly I built custom PCs for people and would come out to their house to fix problems they had. This wasn't too bad but the profit margins (thanks to all the online retailers starting out) were tanking and there was little money left to be made. I closed up that business but took the pieces I learned and in 2000 started up df-Softare. I was writing custom apps (mostly web portals) for the small and mid-sized businesses out there. It was something I really enjoyed doing and managed to make a few bucks although it was never significant enough to let me quit my day job. I ran df-Software and had a pretty good time but eventually the time impact was a little too much and I decided to close shop. I still do the occasional site but these days it's mostly for fun. Was it all worth it? Sure... besides really learning a lot about way things can go wrong it also led me down a path where I had the MVP award for 6 years. The MVP title really was a huge perk when job hunting too. Besides those things it also let me see what it really takes to survive in the business world. It's a lot harder than it looks! Those things really helped me become a better person outside of work too I think. It's easier to see outside of your own "box" and look in from the other perspective now and then.

Amazing career! In your current job.. What is it exactly that you do? Are you developing 100% of the time? Or are you more of a team leader/systems architect who instructs the other developers, tells them what to do and how to do it?

Currently my role is as a Sr. Programmer. The company I'm at has it's own Architecture area as well as segregating the Middleware and Data teams out from the developers. Unofficially I'm a "goto guy" for anything .Net or even just general programming. With the projects I'm currently on I spend about 60% of my time coding and the remaining 40% doing coordination and assisting others. I've also acted as a liason with the University locally and worked as the lead for their Comp. Sci. 480 students who come to our company under that program. It's like an internship.

In general, what are the things you try to teach these students?

Mostly we aren't there to "teach" them so much as let them get a feel for a real-world project. What it's like to design, document, code and test an application. With only 1 semester it's tough to do but it's still a good experience for all.

Which part of the ASP.NET framework would you enjoy talking about?

I have the advantage of being with Asp.Net since it's pre-beta days. At an early MVP summit the Asp MVPs (there was no Asp.Net at the time) were taken in to a lab at Microsoft and allowed to play with the "bits" that later became Asp.Net 1.0. It blew us all away. Prebuilt controls, compiled code, object oriented programming and an intellisense development environment... WOW. It was like the computer Gods took a liking to us and blessed us with their favor. Most of us at the time were dealing with pure scripting and using tools like notepad for our development environment so there really didn't have to be a huge leap for us to feel like we really gained ground but this was really a lot more than we hoped for.
Now that I gave you my background in Asp.Net... you can see it would be hard to limit myself on what to talk about. I've really worked at it over the years, staying up to date as much as I can, but I have to be honest and say that a lot of the developments/enhancements that have come out in the last year have really passed right by me. LINQ, MVC, DynamicData just to name a few... these things I can't really talk on with any strong knowledge. I've messed around with them, and used them a little and can see how they could really help but I'm an old-school developer. Taking away too much control is something that's a little scary. Anyway... feel free to ask on anything you would like. If it's a topic I haven't gotten to know well then I'll say so.
Oh, and I'm not sure if I've mentioned but I've done a ton of manuscript reviews for publishers. I'm quoted on a few covers from Manning press (Asp.Net Ajax in Action and WPF In Action) as well as being listed in the acknowledgements sections of quite a few books related to programming.

To be continued..

The tech-talk will continue in part II of this interview which will be published next week Tuesday I think.