To comment or not to comment

Introduction Anyone that has ever taken a programming class or read a beginners book on the subject know how important it is to write comments in your code. But is that really true? In this post I’m going to discuss/question the common practice of writing comments in your code. Bad comments A couple of weeks ago I was contacted by an old friend of mine that runs a construction company. They have an old custom system that they’ve had since the mid or late ’90s sometime. He wanted some slight modifications made to this system, but the consultant business that … Continue reading To comment or not to comment

Copy and Paste programming – A bad habit

Introduction I usually stay away from religious discussions when it comes to programming habits and technology choices simply because they don’t usually make any sense at all and are most often just based on emotions. Arguing if VB.Net is better or worse than C# is just nonsense in my book since the differences between them are minor. They both target the same platforms, and use the same framework, of course there are differences but none of them are so great that you would say that this is a much better language. I personally think that XML literals in VB are … Continue reading Copy and Paste programming – A bad habit

Develop for Windows 7

Have you any plans on starting to develop applications for Windows 7 yet? The Windows API Code Pack can be used to access some of the new features in Win7, but also some existing features in older version of the Windows OS. The team at Microsoft that are behind the code pack have just updated all the sample code so they now come in both VB as well as in C#, and they did a very good job with it too. So go have a look, it’s pretty neat. Have fun.

At your service (part II) – ASMX Web Service vs WCF

Introduction Last time I demonstrated how to develop a Windows Communication Foundation (WCF) service. This time we’re going to look at the differences between a ASP.Net WebService and a WCF service. The biggest difference between them is probably that a WebService only can be activated via HTTP and they are tightly coupled with ASP.Net HTTP pipeline. A WCF service on the other hand can be bound to a large variety of network protocols. It also doesn’t require that it is hosted on a web server, it can be hosted in a console application, in a Windows Forms app, or in … Continue reading At your service (part II) – ASMX Web Service vs WCF

At your service (part I) – WCF tutorial in VB

Introduction In this post I’m going to do a tutorial on Windows Communication Foundation, WCF. This tutorial is divided in 4 steps: Defining the WCF data and service contracts. Implementing the WCF service contract. Creating the service-host application. Create a client application that uses the service. So without further ado, let’s get busy. Here is where we are getting busy We’re going to implement our WCF server as a simple console application so start Visual Studio and create a new Console project. But for now we just leave the Sub Main() empty, since we implement the server in step 3. … Continue reading At your service (part I) – WCF tutorial in VB

Debugging a Windows Service

Introduction In my last article I showed a simple example of how to create a Windows Service using VB. This time we’re going to have a look at how to debug the service from Visual Studio. Since a service must run from the context of the Service Control Manager you can’t normally debug it in the same manner as you would any other project type. Normally you would need to build the project, install it using the InstallUtil.exe command line tool, and attach a debugger to the process while it’s running. Another approach is to create a separate project (console … Continue reading Debugging a Windows Service

Creating a Windows Service using VB.Net

Introduction Yesterday I got a call from my brother, or actually he sent me a message over MSN. He wanted to know if I could help him create a program with a very specific requirement. Where he works they have a system that creates a lock file when you enter a new journal into the system. However because of a bug (?) in that system, this file is not always deleted after the journal have been entered. If this file is not removed, no more journals can be entered and the system runs amok. So my brother wanted a program … Continue reading Creating a Windows Service using VB.Net

Event horizon – Understanding custom events

Introduction In this article I’m going to try to explain what custom events are and why you should use them in your code. As you will see the term custom event in this context is not just an event you have created for your own class, but also a custom way of storing the delegates for this event. Most of this article is intended for the VB developer, but with the exception of VB specific parts, especially found in the Background Info section, the information here also applies to C# (but with a slightly different syntax of course). Background info … Continue reading Event horizon – Understanding custom events

Run you later – Understanding deferred execution in LINQ

Introduction In this article I’m going to try to explain one of the most misunderstood features of LINQ – deferred execution – and the impact it might have on your code if you don’t fully understand what it means. What does deferred execution mean? According to the dictionary the word deferred means delayed or postponed. So deferred execution in LINQ means that the actual execution of a query is postponed to a later time. Let’s say that you’re using LINQ to SQL and want to use the following LINQ query: Dim cheapProducts = From p In db.Products _ Where p.ListPrice … Continue reading Run you later – Understanding deferred execution in LINQ

The Untouchables (part III) – Adding iterators to our immutable stack

Introduction In my last post I showed you a VB translation of Eric Lippert’s immutable stack class. There was however one thing that was lost in translation. In Eric’s original code he made the class enumerable (added support for a For Each loop). Because C# has support for iterators with its yield keyword, that was very easy to do… in C#. VB currently doesn’t have this feature so to add the same support we need to implement both the IEnumerable(Of T) and the IEnumerator(Of T), which in turn requires the implementation of the non-generic IEnumarable and IEnumerator and also the … Continue reading The Untouchables (part III) – Adding iterators to our immutable stack