A place-holder?



  • I don't know whether or not this C# code has a problem, but certainly puzzled me:

    private void Dispose(bool disposing)
    {
        // disposed yet?
        if (this.disposed == false)
        {
            // managed resources
            if (disposing)
            {
            }
    
    followed by other stuff, but the nine lines shown are exactly as in the original source.


  • Without context, I could be mistaken, but that pattern is usually used to discern if the underlying system is disposing of the object (eg: delete x -> heap manager thread), or you (the programmer) are disposing of it (at least in Java).



  • @rstinejr said:

    I don't know whether or not this C# code has a problem, but certainly puzzled me:

    private void Dispose(bool disposing)
    {
        // disposed yet?
        if (this.disposed == false)
        {
            // managed resources
            if (disposing)
            {
            }
    
    followed by other stuff, but the nine lines shown are exactly as in the original source.

    This look like right-click programming: somebody copied stuff from a MSDN sample, changed a few bits and removed the skeleton content. Basically if the class was using any kind of resource (like a file), it usually would be disposed in the "if disposing" section.



  • == false and the empty block are both bad style, but the basic structure with the two conditions is standard boilerplate.



  • That is indeed the correct pattern... it is (to me at least) an interesting stylistic question of keeping the structure even when the various parts are empty. I can see both sides of the argument, and am happy as long as people are consistent!



  •  Yeah that's the standard dispose method, if you implent IDisposable VS automatically adds that to your class



  • @BaRRaKID said:

     Yeah that's the standard dispose method, if you implent IDisposable VS automatically adds that to your class

    What version of Visual Studio? On VSTS2010 the only thing that appears is the Dispose() method, nothing inside it. Did you get snippets somewhere?



  • @pjt33 said:

    == false and the empty block are both bad style, but the basic structure with the two conditions is standard boilerplate.

    Did not realize this was the standard boiler plate. I was reviewing a class to make sure that the non-managed stuff was correctly released when I discovered the empty if-block. The body of code was only partially completed and had several bugs when I started work on it, so my concern was that something had fallen thru the cracks.

    Other classes in this code have Dispose methods that clear managed lists and then return. The app is a smallish tool that has no worries about busting the heap before GC can do its thing. I mentioned the extraneous use of IDisposible and was told that the use of Dispose is a common pattern in C#. At my shop, that appears to be true even when it serves no purpose.

    BTW, as I've noted before, I really hate the if (foo == false) idiom.



  • @rstinejr said:

    BTW, as I've noted before, I really hate the if (foo == false) idiom.

    Agreed. "false" has a negative aura, so I never use it. Instead do: if (!foo == true)



  • @morbiuswilters said:

    @rstinejr said:
    BTW, as I've noted before, I really hate the if (foo == false) idiom.

    Agreed. "false" has a negative aura, so I never use it. Instead do: if (!foo == true)

    To make things even less negative, more joyful I prefer this: if (!!!foo == true)



  • @Speakerphone Dude said:

    @morbiuswilters said:
    @rstinejr said:
    BTW, as I've noted before, I really hate the if (foo == false) idiom.

    Agreed. "false" has a negative aura, so I never use it. Instead do: if (!foo == true)

    To make things even less negative, more joyful I prefer this: if (!!!foo == true)

    For a taste of old Mexico, add a pinch of: if (¡¡¡foo == true)

    It's a good thing.



  • @morbiuswilters said:

    @rstinejr said:
    BTW, as I've noted before, I really hate the if (foo == false) idiom.

    Agreed. "false" has a negative aura, so I never use it. Instead do: if (!foo == true)

    +1

    == false will get you canned during the next RIF at my shop



  • @rstinejr said:

    I don't know whether or not this C# code has a problem, but certainly puzzled me:

    private void Dispose(bool disposing)
    {
        // disposed yet?
        if (this.disposed == false)
        {
            // managed resources
            if (disposing)
            {
            }
    
    followed by other stuff, but the nine lines shown are exactly as in the original source.


    Usually when bool is an arg in Dispose it is to diferentiate whether the call is coming from an explicit call to Dispose, or coming from the destructor.

  • ♿ (Parody)

    @this_code_sucks said:

    == false will get you canned during the next RIF at my shop

    Why does your shop suck so much?



  • @this_code_sucks said:

    == false will get you canned during the next RIF at my shop

    Even better if it got you caned at sundown, then canned.



  • @morbiuswilters said:

    @Speakerphone Dude said:
    @morbiuswilters said:
    Agreed. "false" has a negative aura, so I never use it. Instead do: if (!foo == true)

    To make things even less negative, more joyful I prefer this: if (!!!foo == true)

    For a taste of old Mexico, add a pinch of: if (¡¡¡foo == true)


    But that will give you a syntax error unless you close the exclamation marks!!!



  • @pjt33 said:

    @morbiuswilters said:
    @Speakerphone Dude said:
    @morbiuswilters said:
    Agreed. "false" has a negative aura, so I never use it. Instead do: if (!foo == true)

    To make things even less negative, more joyful I prefer this: if (!!!foo == true)

    For a taste of old Mexico, add a pinch of: if (¡¡¡foo == true)


    But that will give you a syntax error unless you close the exclamation marks!!!

    <font color="#000000" face="courier new,courier"> if (¡¡¡foo!!! == true)</font>

    <font color="#000000"><font face="Courier New"><font face="Arial"> </font></font><font face="arial,helvetica,sans-serif">¡Yes!</font></font>



  • @boomzilla said:

    @this_code_sucks said:
    == false will get you canned during the next RIF at my shop

    Why does your shop suck so much?

    Because rstinejr used to be the senior developer there. During his tenure he implemented a draconian code style standard. Adding to the suckiness, because so much emphasise was put on code style, things like archetecture and functional standards went out the window; we even have post increment in most of the cases where a pre increment was appropriate. Though he has moved on, this backwards culture still prevails.  



  • @this_code_sucks said:

    we even have post increment in most of the cases where a pre increment was appropriate.

    NOOOOOO!!!!



  • @this_code_sucks said:

    @boomzilla said:

    @this_code_sucks said:
    == false will get you canned during the next RIF at my shop

    Why does your shop suck so much?

    Because rstinejr used to be the senior developer there. During his tenure he implemented a draconian code style standard.

    I was just joking about caning. I might think it's a good idea, but the HR people would pitch a fit.


Log in to reply