ThreadSleep webservice



  • I think the code speaks for itself. The sheer wtfness of this simple method is mind-blowing. The useless comments. The fact that a webservice exists to to a Thread.Sleep. The fact that it returns a boolean (for what?). The catching of exception, in case a Thread.Sleep has crashed I guess. The empty Finally block. The fact that it's VB. Everything.

        ''' <summary>
        ''' Application service get delay of particular time based on the configuration settings "SleepTimeOut".
        ''' </summary>
        ''' <param name="userId">The user id.</param>
        ''' <param name="mandantId">The mandant id.</param>
        ''' <param name="userType">Type of the user.</param>
        ''' <returns><c>true</c> if success, <c>false</c> otherwise</returns>
        <WebMethod()> _
        Public Function ThreadSleep(ByVal userId As String, ByVal mandantId As String, ByVal userType As String) As Boolean
            Me.WriteLog("Control entered in ThreadSleep()", "userId", userId, "mandantId", mandantId, "userType", userType)
            Try
                Dim sleepTimeOut As Integer
                sleepTimeOut = IIf(Integer.TryParse(ConfigurationManager.AppSettings("SleepTimeOut"), sleepTimeOut), sleepTimeOut, 10000)
                Thread.Sleep(sleepTimeOut)
                Return True
            Catch ex As Exception
                Me.WriteLog(ex.ToString())
                Return False
            Finally
    
            End Try
        End Function

  • SockDev

    The comments you can't have; those would be processed by a documentation generator.

    The rest are deffo undefineds though 😉



  • Is Mandant a DC Comics supervillain?



  • Mandant is an SAP term....



  • The comments: I mean, "userId : the user id"... yeah.

    And do you understand the summary ? I mean, if you didn't know the method name and body, would you guess what the method does?



  • @blakeyrat said:

    Is Mandant a DC Comics supervillain?

    That'd be awesome. I'll start naming my variables after superheroes and villains right away.


  • SockDev

    Hmm… OK, you can have the comments too 😉



  • @cosmo0 said:

    Integer.TryParse(ConfigurationManager.AppSettings("SleepTimeOut")

    Integer.TryParse(ConfigurationManager.AppSettings("SleepTimeOut")
    

    I guess this changes so much you want to retrieve it each time?



  • Wait, why would you be using TryParse on an AppSetting? YOU KNOW THE TYPE!


  • SockDev

    @blakeyrat said:

    Wait, why would you be using TryParse on an AppSetting? YOU KNOW THE TYPE!

    What if someone mistypes the value, and it no longer parses? True, the undefined factor of typing seventeen instead of 17 is extraordinary, but stupider things have happened…



  • @RaceProUK said:

    What if someone mistypes the value, and it no longer parses?

    Well if they're fucking sane Visual Studio will catch the error long before they even attempt to build it.


  • SockDev

    I guess they could run a pre-build step that validates the App.config



  • Or they could do their development inside Visual Studio. I know, crazy crazy idea, I'm sorry.


  • SockDev

    I'm assuming they are in VS; I've just never seen it type-check an App.config before, s'all.



  • So they're doing a sleep...and to do that they log the user, mandant, and user type. Which leads one to wonder why they did not also log the sleepTimeOut. Maybe that's a trade secret, hmmm?

    Or maybe, just maybe, it was idiotic to log this undefined event in the first place?



  • Defensive programming. More failsafes is always* good.

    *pedantic clarification: not actually always, but most of the time.



  • @cosmo0 said:

    Thread.Sleep(sleepTimeOut)
    Return True

    I may be being dumb as I don't muck with threading if I can avoid it but doesn't Thread.Sleep act on the currently active thread so that the webservice won't return till the sleep is over?


  • SockDev

    @blakeyrat said:

    Wait, why would you be using TryParse on an AppSetting? YOU KNOW THE TYPE!

    wait. app.config appsettings can be annotated as different types?

    that's news to me and i'd love to see the documentation on how to use that, because i have to do tryparse all over the flipping place when reading from app.config (or web.config for webapps)



  • Crap. This looks like someone saw my OMGWTF2 submission on Github, ported my thread sleep "function" to VB, and used it.



  • @locallunatic said:

    I may be being dumb as I don't muck with threading if I can avoid it but doesn't Thread.Sleep act on the currently active thread so that the webservice won't return till the sleep is over?

    Speedup loop function!


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.