views:

56

answers:

2

Let's say I have this sub in vb.net:

    ''' <summary>
    ''' Validates that <paramref name="value"/> is not <c>null</c>.
    ''' </summary>
    '''
    ''' <param name="value">The object to validate.</param>
    '''
    ''' <param name="name">The variable name of the object.</param>
    '''
    ''' <exception cref="ArgumentNullException">If <paramref name="value"/> is <c>null</c>.</exception>
    Sub ValidateNotNull(ByVal value As Object, ByVal name As String)
        If value Is Nothing Then
            Throw New ArgumentNullException(name, String.Format("{0} cannot be null.", name))
        End If
    End Sub

My question is, is it proper to call this ValidateNotNull (which is what I would call it in C#) or should I stick with VB terminology and call it ValidateNotNothing instead? Also, in my exception, is it proper to say "cannot be null", or would it be better to say "cannot be Nothing"?

I sort of like the way I have it, but since this is VB, maybe I should use Nothing. But since the exception itself is called ArgumentNullException, it feels weird to make the message say "cannot be Nothing".

Anyway, I guess it's pretty nitkpicky, just wondered what you folks thought.

+4  A: 

I think you're fine sticking with Null. It's not without precedent. For example, the .NET framework developers didn't create String.IsNothingOrEmpty for the VB community. And it also isn't like Null is some vague concept, anyone who has programmed or worked with a database for longer than a week has seen it.

With that in mind, it's OK to consider your audience. If your code is going into a class library that can be used by other developers, those developers may be accustomed to seeing null as null. On the other hand, if this is strictly part of some codebase that will only be maintained, then the VB folks looking at it may expect to see "Nothing." Conform to standards as best you can, but know that the standards of your language may not necessarily be the standards of your consumers.

But as said earlier, Null should be fine.

Anthony Pegram
A: 

Also, in my exception, is it proper to say "cannot be null", or would it be better to say "cannot be Nothing"?

Several tools (including our VSdocman) accept <see langword="null"/>. This will produce exactly the same text as MSDN: "null reference (Nothing in Visual Basic)". You can use it also for other keywords such as true, false, abstract, etc. See <see> tag syntax for more details.

Peter Macej
Ah, sorry. I misunderstood the question. I was referring to exception documentation where you use <c>null</c>. Now I found that you meant exception message.
Peter Macej