File Management WTF



  • Here's a WTF that I had to create on purpose (which reduces the WTF level by a notch or two though).

        I currently work on coding a .Net webservice interface for a Win32 client-server app . The client-server app is a WTF unto itself. But that is not the subject of this story.

        Instead I shall talk about the library provided to us by the original developers. Personally, I've seen poorly written libraries, but this one takes the cake.

        Why?

        Because it's got the mind of Descartes. It doubts itself. The interface it exposes to the outside world, conveys a sense of insecurity in it abilities. err... how shall I start?

     

        Ok, it's a file management system, so you should be able to add files. Good that this feature works, but with a twist. If you want to add a file, you call a function named on the lines of ImportFile(...). Now, if the Server has been held together by enough chewing gum, it will gracefully accept the file and return a file ID. If it hasnt had enough gum, I mean, if it has failed, well it again returns a file ID. Now there is nothing to let you know if the ID that was returned was valid or not.

    What to do?

    Idea 

    Download it from the system and see if you get a file!! So that should be a valid file ID (for the ImportDoc function that is).

     

    The next thing that you would think about is , DownloadDoc(...). This one's better, marginally.

    If you want to download a file, supply the ID and the destination directory; the server will then, automagically place the file in the destination directory. Now what if the ID that you provided was incorrect ? You might think that there is a return value, but no, there are no crutches in this part of the world. Instead, you need to 'monitor' the destination directory. Which would mean, creating an empty destination directory and monitoring it, or something on that lines.

    More fun...

    Want to delete a file? Supply the file ID and wave your hands in darkness, for the library does not know whether it has deleted the file or not. So the implementation goes something like this -

    first download the file to see if the file actually exists,

    if it exists, delete the file that was downloaded as well as the file on server by issuing the self doubting command - DeleteDoc

    Hope that the file is deleted, or better try downloading the file again to check for its existence.  Else retry a bazillion times (the judges have confirmed that bazillion + 1 times is a bad programming idea, so you should try exactly a bazillion times).

    Finally, spew out something intelligible (based on the diagnosis performed on the system operation) to the clueless user.

    <rant type="pointless">All this for something that could easily be done in Plone</rant>


Log in to reply
 

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