August 2003 - Posts

Update: The original url's work again! Due to an unexpected move of the server hosting the TypeFinder macro and the BuildFileBuilder site, the original url's do not work at this moment. But you can reach them by using the new url's:

I'm sorry for the inconvenience and I'll do my best to get the original url's back online asap. Thank god, there is DynDNS :-) !

<quote>
Well rather then complain about the lack of a main feed for http://blogs.gotdotnet.com/ I decided to code up a little app to create a feed.  The current feed only includes the blogs running BlogX so guys like Don Box are currently not included.  I'll write more about how I created the main feed as well as release the source for the feed creator in a later post.  For the time being point your aggregators over to http://www.emxtechnologies.com/gotdotnet-blogs/mainfeed.xml and let me know what you think!
</quote>

Thanks a lot Steve!

The people that probably know the most are also the ones trying hardest to learn.

Think about this sentence by posted by Darell Norton. I was amazed nobody ever said this before. It's like searching for your glasses while you're having them on your nose! I'm not pretending that I know a lot, but I do try to learn a lot. In my opinion learning is not only about reading very complex articles written by very intelligent people (although you can and will learn a lot of them), but also to be open to opinions, thoughts, reasoning, ... of maybe less experienced people. You can even learn of other people's mistakes. I answered quite a lot posts on forums, very simple questions and some rather complex ones, they all taught me how other people think. You can use that knowledge when writing articles, giving presentations, ... to warn people which mistakes are made and how to avoid them. Anyway, learning 24/7 about .NET, trying to know a lot, is great!

Fact: Users provide wrong data as input.

So we have to check this data before processing it. Btw, not only users can enter wrong data, even data provided by other systems can be wrong and should be validated. Suppose our application has the n-tier architecture as proposed by Microsoft (Application Architecture for .NET: Designing Applications and Services), using custom entity business classes and a webservice layer to provide services to a client. There are several places where you can do validation, but which one to choose?

User interface layer: validation by the client application
The first place where validation can be done, is at the client side, as close to the user as you can get. This validation is pretty easy to implement. You can choose several approaches: for example: check the input each time a TextBox (or other control) loses focus. Or the validation is done before pressing the Ok/Save button, closing the form, ...
In my opinion the second approach is better for several reasons. First of all, by using the first approach the input is only validated when the control loses focus, so you can't be sure of the input, without checking all of the controls again. When using the second approach, be sure to provide one message containing all of the controls that have data that is not correct, instead of displaying a messagebox for each control.

Building validation in the user interface layer seems to way to go. But in the new world of Service Oriented Applications (SOA), there can be multiple client applications using your services. So it's obvious each client application would have to implement validation, which is not so good (always trying to avoid code repetition!). You can argue about the code repetition thing, but since we are living in the SOA world, it's possible we don't write the client application, or our services are accessed directly by other companies. So only client side validation is not enough.

Services interfaces: validation by the webservices and business components
The next place to think about is the Services Interfaces. Since every possible client application uses one ore more of the services interfaces, implementing validation at this level seems to be a good idea. The validation logic is centralized in one place and cannot be surpassed so all data provided by any client application will be validated.

But what could be a problem is passing information about the validation back to the client. Using this approach, data can only be validated by sending it to the server and waiting for a response. So even if the client application only wants to check if the data is entered correctly, a roundtrip to the server is needed.

Next question: how to do the validation? Again, there is no answer that would suit for every situation. You could validate every property in the property set member. This is an easy solution that prevents wrong data to be stored in an object. The drawback of this approach is that you validate one property a time. So suppose your users has entered 2 values for 2 properties, they get validated after each other. This would result in a scenario like this: the users enters it's data and presses the submit button, a message is shown that valueA is wrong, the user corrects it's data and submits again, another message is shown: valueB is wrong. I guess your users would not be happy. Another solution is to build a Validate function. This function would be called after all properties are set, and would do the validation checks. This gives you the advantage that this function can create an error message that informs the user of all properties that are wrong.

Conclusion?
I think there has to be some minimal trivial validation at the client side, so no round trips are needed for example to check if the date is in the correct format. The main part of the validation should be behdind the webservices (Services Interfaces layer). When performance, is one of your main issues, you should use as much client side validation as possible, due to the roundtrips. But as always, performance is not the only issue, so there should be a balance between client side and server side validation. Clients should at least contain some basic validation rules, if your performance constraints allow you, you could consider moving some validation to the server side. But be aware that even when you use very extensive client side validation, server side validation is needed to! Any thoughts would be appriciated!

Namespaces in .NET are great! But how many times do you find yourself typing Private r As xmlreader, and then noticing that there is no Imports/using statement for the System.Xml Namespace? Then you would have to scroll to the top of your document and add the Imports/using statement by hand. Alternatively you could choose to add the namespace to your declaration: Private r As System.Xml.XmlReader. Since we are all developers, why not develop something to help developers with this tedious task of namespace lookups?

The first version of this macro was published some time ago. Thanks to Yves Hanoulle, Thomas Freudenberg and Guillaume Roberge, a new version is available. Changes:

  • Check if the “Imports/using NamespaceX“ statement is already present in the code.
  • Code cleanup and improvements.

The new version (with installation instructions) can be found on this page: http://dotnet.leadit.be/typefinder (temporary down, alternative: http://typefinder.mine.nu). A compiled Macro Project and the source code in plain text can be downloaded.

<quote>
Ever found yourself in need of a quick color scheme ? But no inspiration at all ...
</quote>

Then the quickcolor utility can be used! This online tool lets you search for color combinations that match. So if you don't want to hire those way-to-expensive designers, but still want to have a nice color scheme: this little tool is for you. Here is a link to an article about color theory.

Today I was searching for a code snippet that I had used some time ago. But I couldn't find it! I knew I had used it before in a project, but ofcourse I hadn't the source code with me. I work on different locations (customer's office, office, home) on different machines (customer's pc, laptop, desktop) and I don't copy all my projects to each pc. My next thought was: “No problem, just use Google!”. But when you really want to find something, the chances are high that you can't remember the exact title of the article or website you've read (Murphy's law). So no luck with Google today. Finally I went home and looked up the snippet in my old project...

This experience has happened quite some times to me (am I the only one?). So I started wondering if there is a solution for this problem. Here are some requirements:

  • Code snippets must be stored together with a description and title.
  • A nice UI has to provide functionality to store and search code snippets.
  • The data needs to be stored somewhere on the web so it can be accessed from different locations.
  • Optional: Code snippets are shared between different people.

Does anyone has an idea if such an application exists? Or do I have to make one myself? ;-)

Btw, here is the code snippet I was looking for. It adds a global error handler, that catches all unhandled exceptions


Public Sub New()

MyBase.New()
InitializeComponent()

AddHandler System.Windows.Forms.Application.ThreadException, AddressOf Me.GlobalErrorHandler
End Sub

Public Sub GlobalErrorHandler(ByVal Sender As Object, ByVal t As System.Threading.ThreadExceptionEventArgs)
MsgBox(t.Exception.ToString)
End Sub


I'm back from my honeymoon to Thailand. It was an incredible holiday, we saw so many beautiful things and the people were so kind: I can recommend it to everyone!

So the next days I will be enjoying the Belgian weather: we're having extremely hot weather (around 36C). Thanks to all of you who send congratulations and greetings and cu soon!

More Posts