Good, Bad, I'm the One With The Idea...

  • Post ideas which you can't make up your minds about whether they are brilliant or Brillant. Expect vigorous debate.

    Let's start with this gem of a .NET library:

    The idea here, basically, seems to be to encapsulate stringly-typed value conversions, so that they get forced back into some semblance of strong typing as fast as possible. It seems mainly aimed at things like deserialization libraries (it specifically mentions JSON), and would, in they author's eyes, help reduce the ad-hackery involved in such things. I am pretty sure that there are better existing tools for that, though, but so far, it seems like an OK idea.

    I also get the idea that the author thinks this will help in refactoring code that was stringly typed for other reasons, but this is where the logic breaks down IMAO.

    First off, stringly typing for almost anything other than de-serialization is an anti-pattern, and while the author seems to recognize this fact, he doesn't seem to really get why it happens, or why it is unlikely that the coders who apply it aren't likely to grab a library to do it.

    Stringly-typing is, more often than not, due to a combination of ignorance of the language (as much as I dislike C#, I have to say that they did bend over backwards to make this sort of thing unnecessary) and Not Invented Here syndrome. The original coders probably did it because they thought it was the right way to do it, so they probably wouldn't have thought to look for a way to make it easier.

    Second, stringly-typing is a very strong code smell for bad practices in general; if the original coder used it, they probably did a lot of even worse things in the code as well.

    Something like this might have some value in meatball patching, the sort of fix you apply to buy time for a more extensive refactoring job later, but even then I doubt it would be worth it - it would take a long time to root out all the code that would need to be fixed, at which point you might as well do the actual refactoring. I'm not convinced that it wouldn't make things worse, but the intent is at least a good one.

    But the worst part, IMO, is that a form of Jevons Paradox might apply - anyone who is inclined to use stringly-typed variables who does go looking for a library like this, and find this one, is likely to take that as a green light for their approach. It has a lot of potential to make the problem it means to solve worse, by enabling this kind of shitty programming.

  • Impossible Mission Players - A

    @scholrlea said in Good, Bad, I'm the One With The Idea...:

    Expect vigorous debate.


  • In .net? I guess shit coming out of the querystring our a textbox. But:

    If Not integer.trycast(request.querystring("itemno"), itemno) then
       Itemno = -1
    End if

    You may need to cast from object, such as from view state or session. But I almost always use a strongly typed assessor.

    Public property CurrentUserId as integer
       If Session("userid") is nothing then
          Session("userid") = 0
       End if
       Return ctype(Session("userid"), integer)
    End get
    Set (value as integer)
       Session("userid") = value
    End if

    Occasionally I'll just write a throwaway function like:

    Function TryGetValue(ByVal val as String, ByRef output as Integer, ByVal defaultval as Integer) as Boolean

    Then over load the function with different types for output and defaultval.

  • Notification Spam Recipient

    @Lorne-Kates why is there nearly no casing consistency in this code

  • @pie_flavor said in Good, Bad, I'm the One With The Idea...:

    @Lorne-Kates why is there nearly no casing consistency in this code

    To annoy you.

  • @lorne-kates said in Good, Bad, I'm the One With The Idea...:

    To annoy you.

    You had me at VB.

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