Return True? That's It? WTF?
I posted some code the other day at TheDailyWTF.com that used some pretty intense error handling for a function that simply returned "True". Of course, the way to do it would have been:
Private Function CheckOperation() As Boolean
Return True
End Function
I noticed in the comments that a few people thought it odd that there existed a function (in production code, no less) that did nothing but return a static value. But there's nothing out of the ordinary there. I've developed numerous classes with methods that do just that: return a static value. And no, they're not stubs.
Here's an example from something I recently developed. The system allowed importing through various data sources. To accomodate this, I built an interface:
Public Interface IImportable
ReadOnly Property SupportsAsynchronousTransfer() As Boolean
ReadOnly Property ReadyState() As ImportReadyState
Sub Import(ByVal conduit As DataConduit)
End Interface
As you can see, some data sources can support asynch transfer, others cannot. And now for the class that implements this:
Public Class CsvDataSource
Inherits DataSource
Implements IImportable
'Snipped non-IImportable code
Public Sub Import(ByVal conduit As DataConduit) _
Implements IImportable.Import
'Snipped code for method
End Sub
Public ReadOnly Property ReadyState() As ImportReadyState _
Implements IImportable.ReadyState
Get
Throw New NotSupportedException()
End Get
End Property
Public ReadOnly Property SupportsAsynchronousTransfer() As Boolean _
Implements IImportable.SupportsAsynchronousTransfer
Get
Return False
End Get
End Property
End Class
Sure, it's a property in this case, but I think you get the idea ...