Completely missing the point...



  • I'm working on bug patrol for a generic data-entry app. It has a grid view that lets users input data. It also has a set of other views in addition to the grid, such as a regular winform-like deal. One of the things the app has is a trigger-like system, in which classes of a certain interface are called at certain points in the life of a record. So if a record is deleted from any view, data about this deletion is passed to an object invoked via reflection. The idea being the 'trigger' doesn't have to care about what view the user is using, just the data.

    Anyway, onto the anonymized code. This is the "BeforeDelete" function, which lets the action decide whether or not the delete action should be permitted. If it returns true, the delete can continue. If it returns false, it must stop.

    Public Function BeforeDelete(ByVal controller As Object, ByVal GUIDs() As String) As Boolean Implements BeforeDelete
        Dim RecordFound As Boolean
        If TypeOf controller Is SpecificController Then
            Dim SpecController As SpecificController = CType(controller, SpecificController)
            Dim RowIndex As Integer = SpecController.View.Grid.ActiveRowIndex
            SpecController.View.Grid.ActiveRowIndex = RowIndex
            Dim ItemGuid As String = CStr(SpecController.View.Grid.Cell(RowIndex, 3).Value)
    
        RecordFound = DataFacade.GetRecordCount(ItemGuid)
    
        If RecordFound = False Then
            Throw Exception(...)
        Else
            Return True
        End If
    End If
    

    End Function

    </p?

    WTFs:
    1 - Throwing an exception instead of returning false, which is what it should be doing.
    2 - DataFacade.GetRecordCount returns a boolean. I have no idea why this is. I don't think I want to know.
    3 - Getting the active row and then immediately setting the active row to that row. WTF?
    4 - The biggest WTF of all, is that this function goes to look up the value of a GUID in the grid, and specifically the grid, so that this event can be bypassed in the other view types. Guess what ItemGuid contains once it gets to the GetRecordCount call? Yeah. It contains GUIDs(0). Even better: you can delete multiple records from the grid, and this function ignores that and only tries to delete the active one.

    ARGGGGGHHH



  • @Welbog said:

    The idea being the 'trigger' doesn't have to care about what view the user is using, just the data.
    @Welbog said:
    If TypeOf controller Is SpecificController Then

    Why does the programmer hate ideas?


  • Considered Harmful

    Well it would be nice if the controllers exposed a common interface, rather than just being generic objects. That wouldn't make any difference here though, as it's hard-coded to a specific user interface. WTF.

    Edit: Wait, what's the return value if it's NOT SpecificController?



  • @joe.edwards said:

    Edit: Wait, what's the return value if it's NOT SpecificController?
    -banana



  • @joe.edwards said:

    Edit: Wait, what's the return value if it's NOT SpecificController?

    That's a good question. VB (the real WTF) has a default return value for code paths that end without returning. I think it's False, but I'm not sure. I just checked, and it is indeed false. Which means that this function isn't bypassed by other views, but rather it just doesn't work from any other view.



  • @Welbog said:

    That's a good question. VB (the real WTF) has a default return value for code paths that end without returning. I think it's False, but I'm not sure. I just checked, and it is indeed false.

    Is your backspace key broken?



  • @bstorer said:

    Is your backspace key broken?

    Works fine, I'm just too lazy to press it.


Log in to reply