Who said VB coders are careless?



  • The following code is indicative of the overall attitude taken by a former dev on this project:

    Private _someThing As String
    

    Public Property SomeThing() As String
    Get
    Try 'begin error handling
    'get the value and cast it to the proper type
    'and return it to the caller
    Return CType(_someThing, String)
    Catch ex As Exception 'catch error
    Throw ex
    Finally 'always runs
    End Try
    End Get

    Set(ByVal Value As String)
    Try 'begin error handling
    'save the value to the instance variable
    _someThing = Value
    Catch ex As Exception 'catch error
    Throw ex
    Finally 'always runs
    End Try
    End Set
    End Property

    Remember, folks, simplicity is a force that must be constantly applied... 



  • I like the explanation of the "finally" block. Always runs... nothing...



  • Why to complain, at least the errors are handled!



  • I guess they copied a template from somewhere.



  • that's the point, the errors aren't handled, because in the catch block he's throwing the exception again. Except that you loose some information about the stack trace, that is, which line of code threw the Exception. No, wait, there's really just 1 line of code anyway.

    it could have been written as :

     private _something as string

    public string Something {

        get { return _something; }

        set { _something = value; }

    }

     

    and you would loose absolutely no functionality. 



  • Return CType(_someThing, String)??

    Why not Return _someThing.ToString()

    Of course, with someone so clueless, I wouldn't expect them to know proper error handling either.

     

    ...TRWTF 



  • @MasterPlanSoftware said:

    Return CType(_someThing, String)??

    Why not Return _someThing.ToString()

    Of course, with someone so clueless, I wouldn't expect them to know proper error handling either.

     

    ...TRWTF 

    _someThing is ALREADY a String, so no point in doing toString *or* CType.

    Also, the code doesn't technically say anything about VB coders, as it's clearly VB.NET. ^-)



  • @ruijoel said:

    that's the point, the errors aren't handled, because in the catch block he's throwing the exception again. Except that you loose some information about the stack trace, that is, which line of code threw the Exception. No, wait, there's really just 1 line of code anyway.

    it could have been written as :

     private _something as string

    public string Something {

        get { return _something; }

        set { _something = value; }

    }

     

    and you would loose absolutely no functionality. 

    With C# 3.0 this really becomes one line :D public string Something { get; set; } 



  • Guy seems to really hate his ex...



  • @Pidgeot said:

    Also, the code doesn't technically say anything about VB coders, as it's clearly VB.NET. ^-)


    Which is again officially called VB since 2005. v-)



  • @Pidgeot said:

    @MasterPlanSoftware said:

    Return CType(_someThing, String)??

    Why not Return _someThing.ToString()

    Of course, with someone so clueless, I wouldn't expect them to know proper error handling either.

     

    ...TRWTF 

    _someThing is ALREADY a String, so no point in doing toString or CType.

    Also, the code doesn't technically say anything about VB coders, as it's clearly VB.NET. ^-)

     

    Good point, I just got so wrapped up in how ridiculous this was:

    Return CType(_someThing, String)??

    Now it just seems so much worse...

     



  • I've been using CodeRush for so long, I can barely write a property from scratch anymore.  I didn't now people still did that stuff.


Log in to reply