dimanche 10 mai 2015

Proper programming - should a function return a value on all code paths?

My VB.Net class's constructor is passed a value for an Enum property. If I create a method in this class that uses Select Case statements, is it proper programming to include a Case Else line (that would never be executed)? I understand it, just want to know what is "proper" programming. Thanks! Pseudo-code if I'm not clear:

Public Enum eList
    one = 1
    two = 2
    three = 3
End Enum

Public Class Class1
    Private _eValue As eList

    Public Sub New(ByVal ePassed As eList)
        _eValue = ePassed
    End Sub

    Public Function SomeMethod()
        Select Case _eValue
            '(all eList items accounted for below)
            Case eList.one
                'do something
            Case eList.two
                'do something else
            Case eList.three
                'do another thing
            Case Else
                '  should I put a Return <value> line here?
        End Select
        '  and should I also put a Return <value> line here?
    End Function

End Class

Thanks for helping me learn!

Aucun commentaire:

Enregistrer un commentaire