shawnz 2 months ago

Is that really achieving OP's goal though, if you're only raising it by creating a new intermediary level to contain the conditional? The conditional is still the same distance from the root of the code, so that seems like it's not in the spirit of what they are saying. Plus you're just introducing the possibility for confusion if people call the unwrapped function when they intended to call the wrapped function

  • Brian_K_White 2 months ago

    But the checking and the writing really are 2 different things. The "rule" that you always want to do this check before write is really never absolute. Wrapper is exactly correct. You could have the single function and add a param that says skip the check this time, but that is messier and even more dangerous than the seperate wrapper.

    Depends just how many things are checked by the check I guess. A single aspect, checking whether the resource is already claimed or is available, could be combined since it could be part of the very access mechanism itself where anything else is a race condition.

astrobe_ 2 months ago

It sounds like self-inflicted boilerplate to me.

  • bee_rider 2 months ago

    If you were going to write the tests anyway, the additional boilerplate for splitting it up and doing a wrapper isn’t so bad (in C at least, maybe it is worse for some language).

    • astrobe_ 2 months ago

      When you say "isn't so bad", is it just a manner of speech or is it actually a little bad (but it is a compromise?)?

      • bee_rider 2 months ago

        Well, I was working on a sort of green-field project that did this, and I liked it. It neatly solved the problem of needing the tests, but only wanting to call them on user-provided inputs. However, some caveats:

        * I wasn’t around long enough to see if there was a hidden maintenance cost

        * It was a very thoughtfully designed library in an already-well-understood domain so it wasn’t like we were going to need to change the arguments a ton

        * It was explicitly a library designed to be used as a library from the get-go, so there was a clear distinction of which functions should be user-visible.

        I think I would find it annoying if I was doing exploratory programming and expected to change the arguments often. But, in that case, maybe it is too early to start checking user inputs anyway.